Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/cmd.py @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 3e26c9033306 |
| children | b9c9c4b2effe |
| rev | line source |
|---|---|
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
1 """distutils.cmd |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
2 |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
3 Provides the Command class, the base class for the command classes |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
4 in the distutils.command package. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
5 """ |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
6 |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
7 import sys, os, re |
|
51393
b4820fceda24
Merged revisions 69360 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
48575
diff
changeset
|
8 from distutils.errors import DistutilsOptionError |
|
13947
191f20e0473e
Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents:
13808
diff
changeset
|
9 from distutils import util, dir_util, file_util, archive_util, dep_util |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
10 from distutils import log |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
11 |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
12 class Command: |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
13 """Abstract base class for defining command classes, the "worker bees" |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
14 of the Distutils. A useful analogy for command classes is to think of |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
15 them as subroutines with local variables called "options". The options |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
16 are "declared" in 'initialize_options()' and "defined" (given their |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
17 final values, aka "finalized") in 'finalize_options()', both of which |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
18 must be defined by every command class. The distinction between the |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
19 two is necessary because option values might come from the outside |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
20 world (command line, config file, ...), and any options dependent on |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
21 other options must be computed *after* these outside influences have |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
22 been processed -- hence 'finalize_options()'. The "body" of the |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
23 subroutine, where it does all its work based on the values of its |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
24 options, is the 'run()' method, which must also be implemented by every |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
25 command class. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
26 """ |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
27 |
|
14626
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
28 # 'sub_commands' formalizes the notion of a "family" of commands, |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
29 # eg. "install" as the parent with sub-commands "install_lib", |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
30 # "install_headers", etc. The parent of a family of commands |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
31 # defines 'sub_commands' as a class attribute; it's a list of |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
32 # (command_name : string, predicate : unbound_method | string | None) |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
33 # tuples, where 'predicate' is a method of the parent command that |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
34 # determines whether the corresponding command is applicable in the |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
35 # current situation. (Eg. we "install_headers" is only applicable if |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
36 # we have any C header files to install.) If 'predicate' is None, |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
37 # that command is always applicable. |
| 21267 | 38 # |
|
14626
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
39 # 'sub_commands' is usually defined at the *end* of a class, because |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
40 # predicates can be unbound methods, so they must already have been |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
41 # defined. The canonical example is the "install" command. |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
42 sub_commands = [] |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
43 |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
44 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
45 # -- Creation/initialization methods ------------------------------- |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
46 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
47 def __init__(self, dist): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
48 """Create and initialize a new Command object. Most importantly, |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
49 invokes the 'initialize_options()' method, which is the real |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
50 initializer and depends on the actual command being |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
51 instantiated. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
52 """ |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
53 # late import because of mutual dependence between these classes |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
54 from distutils.dist import Distribution |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
55 |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
56 if not isinstance(dist, Distribution): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
57 raise TypeError("dist must be a Distribution instance") |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
58 if self.__class__ is Command: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
59 raise RuntimeError("Command is an abstract class") |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
60 |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
61 self.distribution = dist |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
62 self.initialize_options() |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
63 |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
64 # Per-command versions of the global flags, so that the user can |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
65 # customize Distutils' behaviour command-by-command and let some |
| 32379 | 66 # commands fall back on the Distribution's behaviour. None means |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
67 # "not defined, check self.distribution's copy", while 0 or 1 mean |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
68 # false and true (duh). Note that this means figuring out the real |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
69 # value of each flag is a touch complicated -- hence "self._dry_run" |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
70 # will be handled by __getattr__, below. |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
71 # XXX This needs to be fixed. |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
72 self._dry_run = None |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
73 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
74 # verbose is largely ignored, but needs to be set for |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
75 # backwards compatibility (I think)? |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
76 self.verbose = dist.verbose |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
32379
diff
changeset
|
77 |
|
12322
d7629fa3b29f
Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents:
12317
diff
changeset
|
78 # Some commands define a 'self.force' option to ignore file |
|
d7629fa3b29f
Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents:
12317
diff
changeset
|
79 # timestamps, but methods defined *here* assume that |
|
d7629fa3b29f
Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents:
12317
diff
changeset
|
80 # 'self.force' exists for all commands. So define it here |
|
d7629fa3b29f
Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents:
12317
diff
changeset
|
81 # just to be safe. |
|
d7629fa3b29f
Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents:
12317
diff
changeset
|
82 self.force = None |
|
d7629fa3b29f
Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents:
12317
diff
changeset
|
83 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
84 # The 'help' flag is just used for command-line parsing, so |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
85 # none of that complicated bureaucracy is needed. |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
86 self.help = 0 |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
87 |
|
12783
b91b35c1d4c0
Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents:
12747
diff
changeset
|
88 # 'finalized' records whether or not 'finalize_options()' has been |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
89 # called. 'finalize_options()' itself should not pay attention to |
|
12783
b91b35c1d4c0
Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents:
12747
diff
changeset
|
90 # this flag: it is the business of 'ensure_finalized()', which |
|
b91b35c1d4c0
Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents:
12747
diff
changeset
|
91 # always calls 'finalize_options()', to respect/update it. |
|
b91b35c1d4c0
Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents:
12747
diff
changeset
|
92 self.finalized = 0 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
93 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
94 # XXX A more explicit way to customize dry_run would be better. |
|
53148
71f48adad892
Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52892
diff
changeset
|
95 def __getattr__(self, attr): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
96 if attr == 'dry_run': |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
97 myval = getattr(self, "_" + attr) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
98 if myval is None: |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
99 return getattr(self.distribution, attr) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
100 else: |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
101 return myval |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
102 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
103 raise AttributeError(attr) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
104 |
|
53148
71f48adad892
Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52892
diff
changeset
|
105 def ensure_finalized(self): |
|
12783
b91b35c1d4c0
Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents:
12747
diff
changeset
|
106 if not self.finalized: |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
107 self.finalize_options() |
|
12783
b91b35c1d4c0
Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents:
12747
diff
changeset
|
108 self.finalized = 1 |
| 21267 | 109 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
110 # Subclasses must define: |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
111 # initialize_options() |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
112 # provide default values for all options; may be customized by |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
113 # setup script, by options from config file(s), or by command-line |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
114 # options |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
115 # finalize_options() |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
116 # decide on the final values for all options; this is called |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
117 # after all possible intervention from the outside world |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
118 # (command-line, option file, etc.) has been processed |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
119 # run() |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
120 # run the command: do whatever it is we're here to do, |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
121 # controlled by the command's various option values |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
122 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
123 def initialize_options(self): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
124 """Set default values for all the options that this command |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
125 supports. Note that these defaults may be overridden by other |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
126 commands, by the setup script, by config files, or by the |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
127 command-line. Thus, this is not the place to code dependencies |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
128 between options; generally, 'initialize_options()' implementations |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
129 are just a bunch of "self.foo = None" assignments. |
| 21267 | 130 |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
131 This method must be implemented by all command classes. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
132 """ |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
133 raise RuntimeError("abstract method -- subclass %s must override" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
134 % self.__class__) |
| 21267 | 135 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
136 def finalize_options(self): |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
137 """Set final values for all the options that this command supports. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
138 This is always called as late as possible, ie. after any option |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
139 assignments from the command-line or from other commands have been |
| 30723 | 140 done. Thus, this is the place to code option dependencies: if |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
141 'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
142 long as 'foo' still has the same value it was assigned in |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
143 'initialize_options()'. |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
144 |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
145 This method must be implemented by all command classes. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
146 """ |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
147 raise RuntimeError("abstract method -- subclass %s must override" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
148 % self.__class__) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
149 |
|
12789
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
150 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
151 def dump_options(self, header=None, indent=""): |
|
12789
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
152 from distutils.fancy_getopt import longopt_xlate |
|
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
153 if header is None: |
|
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
154 header = "command options for '%s':" % self.get_command_name() |
|
51418
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
155 self.announce(indent + header, level=log.INFO) |
|
12789
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
156 indent = indent + " " |
|
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
157 for (option, _, _) in self.user_options: |
|
56155
4008a0137de7
Merged revisions 74990 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53148
diff
changeset
|
158 option = option.translate(longopt_xlate) |
|
12789
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
159 if option[-1] == "=": |
|
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
160 option = option[:-1] |
|
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
161 value = getattr(self, option) |
|
51418
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
162 self.announce(indent + "%s = %s" % (option, value), |
|
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
163 level=log.INFO) |
|
12789
f0d03689c1ae
Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
164 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
165 def run(self): |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
166 """A command's raison d'etre: carry out the action it exists to |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
167 perform, controlled by the options initialized in |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
168 'initialize_options()', customized by other commands, the setup |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
169 script, the command-line, and config files, and finalized in |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
170 'finalize_options()'. All terminal output and filesystem |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
171 interaction should be done by 'run()'. |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
172 |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
173 This method must be implemented by all command classes. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
174 """ |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
175 raise RuntimeError("abstract method -- subclass %s must override" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
176 % self.__class__) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
177 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
178 def announce(self, msg, level=1): |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
179 """If the current verbosity level is of greater than or equal to |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
180 'level' print 'msg' to stdout. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
181 """ |
|
27988
b26f5758414a
announce(): use the level argument to control the log level.
Guido van Rossum <guido@python.org>
parents:
26285
diff
changeset
|
182 log.log(level, msg) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
183 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
184 def debug_print(self, msg): |
|
12886
1ae035a31cb4
Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents:
12849
diff
changeset
|
185 """Print 'msg' to stdout if the global DEBUG (taken from the |
|
1ae035a31cb4
Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents:
12849
diff
changeset
|
186 DISTUTILS_DEBUG environment variable) flag is true. |
|
1ae035a31cb4
Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents:
12849
diff
changeset
|
187 """ |
|
25212
12949eced55f
Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23668
diff
changeset
|
188 from distutils.debug import DEBUG |
|
12886
1ae035a31cb4
Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents:
12849
diff
changeset
|
189 if DEBUG: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
33965
diff
changeset
|
190 print(msg) |
|
19583
44a62e3b706f
Flush output more aggressively. This makes things look better if
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
17129
diff
changeset
|
191 sys.stdout.flush() |
| 21267 | 192 |
|
12886
1ae035a31cb4
Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents:
12849
diff
changeset
|
193 |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
194 # -- Option validation methods ------------------------------------- |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
195 # (these are very handy in writing the 'finalize_options()' method) |
| 21267 | 196 # |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
197 # NB. the general philosophy here is to ensure that a particular option |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
198 # value meets certain type and value constraints. If not, we try to |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
199 # force it into conformance (eg. if we expect a list but have a string, |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
200 # split the string on comma and/or whitespace). If we can't force the |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
201 # option into conformance, raise DistutilsOptionError. Thus, command |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
202 # classes need do nothing more than (eg.) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
203 # self.ensure_string_list('foo') |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
204 # and they can be guaranteed that thereafter, self.foo will be |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
205 # a list of strings. |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
206 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
207 def _ensure_stringlike(self, option, what, default=None): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
208 val = getattr(self, option) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
209 if val is None: |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
210 setattr(self, option, default) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
211 return default |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
212 elif not isinstance(val, str): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
213 raise DistutilsOptionError("'%s' must be a %s (got `%s`)" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
214 % (option, what, val)) |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
215 return val |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
216 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
217 def ensure_string(self, option, default=None): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
218 """Ensure that 'option' is a string; if not defined, set it to |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
219 'default'. |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
220 """ |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
221 self._ensure_stringlike(option, "string", default) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
222 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
223 def ensure_string_list(self, option): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
224 """Ensure that 'option' is a list of strings. If 'option' is |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
225 currently a string, we split it either on /,\s*/ or /\s+/, so |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
226 "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
227 ["foo", "bar", "baz"]. |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
228 """ |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
229 val = getattr(self, option) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
230 if val is None: |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
231 return |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
232 elif isinstance(val, str): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
233 setattr(self, option, re.split(r',\s*|\s+', val)) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
234 else: |
|
41986
6464cc638faa
Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
235 if isinstance(val, list): |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
236 ok = all(isinstance(v, str) for v in val) |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
237 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
238 ok = False |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
239 if not ok: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
240 raise DistutilsOptionError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
241 "'%s' must be a list of strings (got %r)" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
242 % (option, val)) |
| 21267 | 243 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
244 def _ensure_tested_string(self, option, tester, what, error_fmt, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
245 default=None): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
246 val = self._ensure_stringlike(option, what, default) |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
247 if val is not None and not tester(val): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
248 raise DistutilsOptionError(("error in '%s' option: " + error_fmt) |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
249 % (option, val)) |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
250 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
251 def ensure_filename(self, option): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
252 """Ensure that 'option' is the name of an existing file.""" |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
253 self._ensure_tested_string(option, os.path.isfile, |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
254 "filename", |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
255 "'%s' does not exist or is not a file") |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
256 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
257 def ensure_dirname(self, option): |
|
12849
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
258 self._ensure_tested_string(option, os.path.isdir, |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
259 "directory name", |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
260 "'%s' does not exist or is not a directory") |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
261 |
|
594c27c870ad
Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
262 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
263 # -- Convenience methods for commands ------------------------------ |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
264 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
265 def get_command_name(self): |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
266 if hasattr(self, 'command_name'): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
267 return self.command_name |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
268 else: |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
269 return self.__class__.__name__ |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
270 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
271 def set_undefined_options(self, src_cmd, *option_pairs): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
272 """Set the values of any "undefined" options from corresponding |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
273 option values in some other command object. "Undefined" here means |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
274 "is None", which is the convention used to indicate that an option |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
275 has not been changed between 'initialize_options()' and |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
276 'finalize_options()'. Usually called from 'finalize_options()' for |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
277 options that depend on some other command rather than another |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
278 option of the same command. 'src_cmd' is the other command from |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
279 which option values will be taken (a command object will be created |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
280 for it if necessary); the remaining arguments are |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
281 '(src_option,dst_option)' tuples which mean "take the value of |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
282 'src_option' in the 'src_cmd' command object, and copy it to |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
283 'dst_option' in the current command object". |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
284 """ |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
285 # Option_pairs: list of (src_option, dst_option) tuples |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
286 src_cmd_obj = self.distribution.get_command_obj(src_cmd) |
|
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
287 src_cmd_obj.ensure_finalized() |
|
12407
01cff9fe2d45
Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents:
12322
diff
changeset
|
288 for (src_option, dst_option) in option_pairs: |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
289 if getattr(self, dst_option) is None: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
290 setattr(self, dst_option, getattr(src_cmd_obj, src_option)) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
291 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
292 def get_finalized_command(self, command, create=1): |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
293 """Wrapper around Distribution's 'get_command_obj()' method: find |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
294 (create if necessary and 'create' is true) the command object for |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
295 'command', call its 'ensure_finalized()' method, and return the |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
296 finalized command object. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
297 """ |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
298 cmd_obj = self.distribution.get_command_obj(command, create) |
|
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
299 cmd_obj.ensure_finalized() |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
300 return cmd_obj |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
301 |
|
12810
711b32960934
Added 'reinitialize_command()' method -- delegated to Distribution instance.
Greg Ward <gward@python.net>
parents:
12789
diff
changeset
|
302 # XXX rename to 'get_reinitialized_command()'? (should do the |
|
711b32960934
Added 'reinitialize_command()' method -- delegated to Distribution instance.
Greg Ward <gward@python.net>
parents:
12789
diff
changeset
|
303 # same in dist.py, if so) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
304 def reinitialize_command(self, command, reinit_subcommands=0): |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
305 return self.distribution.reinitialize_command(command, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
306 reinit_subcommands) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
307 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
308 def run_command(self, command): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
309 """Run some other command: uses the 'run_command()' method of |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
310 Distribution, which creates and finalizes the command object if |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
311 necessary and then invokes its 'run()' method. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
312 """ |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
313 self.distribution.run_command(command) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
314 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
315 def get_sub_commands(self): |
|
14626
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
316 """Determine the sub-commands that are relevant in the current |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
317 distribution (ie., that need to be run). This is based on the |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
318 'sub_commands' class attribute: each tuple in that list may include |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
319 a method that we call to determine if the subcommand needs to be |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
320 run for the current distribution. Return a list of command names. |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
321 """ |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
322 commands = [] |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
323 for (cmd_name, method) in self.sub_commands: |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
324 if method is None or method(self): |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
325 commands.append(cmd_name) |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
326 return commands |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
327 |
|
fe47d238b50d
Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents:
13947
diff
changeset
|
328 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
329 # -- External world manipulation ----------------------------------- |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
330 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
331 def warn(self, msg): |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52594
diff
changeset
|
332 log.warn("warning: %s: %s\n" % |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52594
diff
changeset
|
333 (self.get_command_name(), msg)) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
334 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
335 def execute(self, func, args, msg=None, level=1): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
336 util.execute(func, args, msg, dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
337 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
338 def mkpath(self, name, mode=0o777): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
339 dir_util.mkpath(name, mode, dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
340 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
341 def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
342 link=None, level=1): |
|
12317
29e753493d8e
Added a check for the 'force' attribute in '__getattr__()' -- better than
Greg Ward <gward@python.net>
parents:
12313
diff
changeset
|
343 """Copy a file respecting verbose, dry-run and force flags. (The |
|
29e753493d8e
Added a check for the 'force' attribute in '__getattr__()' -- better than
Greg Ward <gward@python.net>
parents:
12313
diff
changeset
|
344 former two default to whatever is in the Distribution object, and |
|
29e753493d8e
Added a check for the 'force' attribute in '__getattr__()' -- better than
Greg Ward <gward@python.net>
parents:
12313
diff
changeset
|
345 the latter defaults to false for commands that don't define it.)""" |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
346 return file_util.copy_file(infile, outfile, preserve_mode, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
347 preserve_times, not self.force, link, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
348 dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
349 |
|
53148
71f48adad892
Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52892
diff
changeset
|
350 def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1, |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
351 preserve_symlinks=0, level=1): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
352 """Copy an entire directory tree respecting verbose, dry-run, |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
353 and force flags. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
354 """ |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
355 return dir_util.copy_tree(infile, outfile, preserve_mode, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
356 preserve_times, preserve_symlinks, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
357 not self.force, dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
358 |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
359 def move_file (self, src, dst, level=1): |
|
68585
bf94b6a73fc8
#11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56155
diff
changeset
|
360 """Move a file respecting dry-run flag.""" |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
361 return file_util.move_file(src, dst, dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
362 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
363 def spawn(self, cmd, search_path=1, level=1): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
364 """Spawn an external command respecting dry-run flag.""" |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
365 from distutils.spawn import spawn |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
366 spawn(cmd, search_path, dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
367 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
368 def make_archive(self, base_name, format, root_dir=None, base_dir=None): |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
369 return archive_util.make_archive(base_name, format, root_dir, base_dir, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
370 dry_run=self.dry_run) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
371 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
372 def make_file(self, infiles, outfile, func, args, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
373 exec_msg=None, skip_msg=None, level=1): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
374 """Special case of 'execute()' for operations that process one or |
|
12313
90b2a3cd365f
Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents:
12296
diff
changeset
|
375 more input files and generate one output file. Works just like |
|
90b2a3cd365f
Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents:
12296
diff
changeset
|
376 'execute()', except the operation is skipped and a different |
|
90b2a3cd365f
Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents:
12296
diff
changeset
|
377 message printed if 'outfile' already exists and is newer than all |
|
90b2a3cd365f
Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents:
12296
diff
changeset
|
378 files listed in 'infiles'. If the command defined 'self.force', |
|
90b2a3cd365f
Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents:
12296
diff
changeset
|
379 and it is true, then the command is unconditionally run -- does no |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
380 timestamp checks. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12810
diff
changeset
|
381 """ |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
382 if skip_msg is None: |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
383 skip_msg = "skipping %s (inputs unchanged)" % outfile |
| 21267 | 384 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
385 # Allow 'infiles' to be a single string |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
386 if isinstance(infiles, str): |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
387 infiles = (infiles,) |
|
41986
6464cc638faa
Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
388 elif not isinstance(infiles, (list, tuple)): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
389 raise TypeError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
390 "'infiles' must be a string, or a list or tuple of strings") |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
391 |
|
51418
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
392 if exec_msg is None: |
|
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
393 exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles)) |
|
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
394 |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
395 # If 'outfile' must be regenerated (either because it doesn't |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
396 # exist, is out-of-date, or the 'force' flag is true) then |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
397 # perform the action that presumably regenerates it |
|
51418
b091bf834226
Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51393
diff
changeset
|
398 if self.force or dep_util.newer_group(infiles, outfile): |
|
14863
c3f0d6f19f7b
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14628
diff
changeset
|
399 self.execute(func, args, exec_msg, level) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
400 # Otherwise, print the "skip" message |
|
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
401 else: |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21267
diff
changeset
|
402 log.debug(skip_msg) |
|
12225
c405dbdd26c9
Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff
changeset
|
403 |
|
12747
6c6844a2fa30
Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents:
12729
diff
changeset
|
404 # XXX 'install_misc' class not currently used -- it was the base class for |
|
6c6844a2fa30
Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents:
12729
diff
changeset
|
405 # both 'install_scripts' and 'install_data', but they outgrew it. It might |
|
6c6844a2fa30
Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents:
12729
diff
changeset
|
406 # still be useful for 'install_headers', though, so I'm keeping it around |
|
6c6844a2fa30
Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents:
12729
diff
changeset
|
407 # for the time being. |
|
6c6844a2fa30
Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents:
12729
diff
changeset
|
408 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42084
diff
changeset
|
409 class install_misc(Command): |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
410 """Common base class for installing some files in a subdirectory. |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
411 Currently used by install_data and install_scripts. |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
412 """ |
| 21267 | 413 |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
414 user_options = [('install-dir=', 'd', "directory to install the files to")] |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
415 |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
416 def initialize_options (self): |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
417 self.install_dir = None |
|
12705
7ff5ae10a771
In 'install_misc': 'self.outfiles' defaults to the empty list, so we don't
Gregory P. Smith <greg@mad-scientist.com>
parents:
12677
diff
changeset
|
418 self.outfiles = [] |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
419 |
|
53148
71f48adad892
Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52892
diff
changeset
|
420 def _install_dir_from(self, dirname): |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
421 self.set_undefined_options('install', (dirname, 'install_dir')) |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
422 |
|
53148
71f48adad892
Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52892
diff
changeset
|
423 def _copy_files(self, filelist): |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
424 self.outfiles = [] |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
425 if not filelist: |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
426 return |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
427 self.mkpath(self.install_dir) |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
428 for f in filelist: |
|
12677
234074545eb4
In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12675
diff
changeset
|
429 self.copy_file(f, self.install_dir) |
|
234074545eb4
In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12675
diff
changeset
|
430 self.outfiles.append(os.path.join(self.install_dir, f)) |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12601
diff
changeset
|
431 |
|
53148
71f48adad892
Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52892
diff
changeset
|
432 def get_outputs(self): |
|
12677
234074545eb4
In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents:
12675
diff
changeset
|
433 return self.outfiles |
