annotate Lib/distutils/cmd.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents b26f5758414a
children 6f15e73b59f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
26285
42bfc98d295b Add comment to Distutil files about requiring 1.5.2 compatibility, as
Andrew M. Kuchling <amk@amk.ca>
parents: 26210
diff changeset
7 # This module should be kept compatible with Python 1.5.2.
42bfc98d295b Add comment to Distutil files about requiring 1.5.2 compatibility, as
Andrew M. Kuchling <amk@amk.ca>
parents: 26210
diff changeset
8
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
9 __revision__ = "$Id$"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
10
17129
32bcb4e21005 Back out conversion to string methods; the Distutils is intended to work
Andrew M. Kuchling <amk@amk.ca>
parents: 16517
diff changeset
11 import sys, os, string, re
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
12 from types import *
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
13 from distutils.errors import *
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
14 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
15 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
16
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
17 class Command:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
18 """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
19 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
20 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
21 are "declared" in 'initialize_options()' and "defined" (given their
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
22 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
23 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
24 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
25 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
26 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
27 been processed -- hence 'finalize_options()'. The "body" of the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
28 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
29 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
30 command class.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
31 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
32
14626
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
33 # '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
34 # 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
35 # "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
36 # 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
37 # (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
38 # 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
39 # 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
40 # 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
41 # 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
42 # that command is always applicable.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
43 #
14626
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
44 # '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
45 # 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
46 # 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
47 sub_commands = []
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
48
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
49
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
50 # -- Creation/initialization methods -------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
51
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
52 def __init__ (self, dist):
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
53 """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
54 invokes the 'initialize_options()' method, which is the real
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
55 initializer and depends on the actual command being
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
56 instantiated.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
57 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
58 # 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
59 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
60
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
61 if not isinstance(dist, Distribution):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
62 raise TypeError, "dist must be a Distribution instance"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
63 if self.__class__ is Command:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
64 raise RuntimeError, "Command is an abstract class"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
65
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
66 self.distribution = dist
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
67 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
68
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
69 # 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
70 # customize Distutils' behaviour command-by-command and let some
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
71 # commands fallback on the Distribution's behaviour. None means
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
72 # "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
73 # 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
74 # 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
75 # will be handled by __getattr__, below.
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
76 # 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
77 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
78
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
79 # 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
80 # backwards compatibility (I think)?
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
81 self.verbose = dist.verbose
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
82
12322
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
83 # 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
84 # 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
85 # '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
86 # 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
87 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
88
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
89 # 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
90 # 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
91 self.help = 0
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
92
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
93 # '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
94 # 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
95 # 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
96 # always calls 'finalize_options()', to respect/update it.
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
97 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
98
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
99 # __init__ ()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
100
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
101
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
102 # XXX A more explicit way to customize dry_run would be better.
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
103
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
104 def __getattr__ (self, attr):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
105 if attr == 'dry_run':
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
106 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
107 if myval is None:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
108 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
109 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
110 return myval
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
111 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
112 raise AttributeError, attr
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
113
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
114
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
115 def ensure_finalized (self):
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
116 if not self.finalized:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
117 self.finalize_options()
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
118 self.finalized = 1
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
119
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
120
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
121 # Subclasses must define:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
122 # initialize_options()
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
123 # 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
124 # 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
125 # options
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
126 # finalize_options()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
127 # 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
128 # 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
129 # (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
130 # run()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
131 # 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
132 # 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
133
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
134 def initialize_options (self):
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
135 """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
136 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
137 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
138 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
139 between options; generally, 'initialize_options()' implementations
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
140 are just a bunch of "self.foo = None" assignments.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
141
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
142 This method must be implemented by all command classes.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
143 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
144 raise RuntimeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
145 "abstract method -- subclass %s must override" % self.__class__
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
146
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
147 def finalize_options (self):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
148 """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
149 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
150 assignments from the command-line or from other commands have been
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
151 done. Thus, this is the place to to code option dependencies: if
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
152 '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
153 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
154 'initialize_options()'.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
155
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
156 This method must be implemented by all command classes.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
157 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
158 raise RuntimeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
159 "abstract method -- subclass %s must override" % self.__class__
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
160
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
161
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
162 def dump_options (self, header=None, indent=""):
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
163 from distutils.fancy_getopt import longopt_xlate
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
164 if header is None:
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
165 header = "command options for '%s':" % self.get_command_name()
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
166 print indent + header
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
167 indent = indent + " "
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
168 for (option, _, _) in self.user_options:
17129
32bcb4e21005 Back out conversion to string methods; the Distutils is intended to work
Andrew M. Kuchling <amk@amk.ca>
parents: 16517
diff changeset
169 option = string.translate(option, longopt_xlate)
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
170 if option[-1] == "=":
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
171 option = option[:-1]
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
172 value = getattr(self, option)
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
173 print indent + "%s = %s" % (option, value)
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
174
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
175
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
176 def run (self):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
177 """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
178 perform, controlled by the options initialized in
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
179 'initialize_options()', customized by other commands, the setup
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
180 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
181 'finalize_options()'. All terminal output and filesystem
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
182 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
183
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
184 This method must be implemented by all command classes.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
185 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
186
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
187 raise RuntimeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
188 "abstract method -- subclass %s must override" % self.__class__
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
189
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
190 def announce (self, msg, level=1):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
191 """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
192 'level' print 'msg' to stdout.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
193 """
27988
b26f5758414a announce(): use the level argument to control the log level.
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
194 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
195
12886
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
196 def debug_print (self, msg):
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
197 """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
198 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
199 """
25212
12949eced55f Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
200 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
201 if DEBUG:
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
202 print msg
19583
44a62e3b706f Flush output more aggressively. This makes things look better if
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 17129
diff changeset
203 sys.stdout.flush()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
204
12886
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
205
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
206
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
207 # -- Option validation methods -------------------------------------
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
208 # (these are very handy in writing the 'finalize_options()' method)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
209 #
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
210 # 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
211 # 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
212 # 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
213 # 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
214 # 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
215 # 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
216 # 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
217 # 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
218 # a list of strings.
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
219
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
220 def _ensure_stringlike (self, option, what, default=None):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
221 val = getattr(self, option)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
222 if val is None:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
223 setattr(self, option, default)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
224 return default
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
225 elif type(val) is not StringType:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
226 raise DistutilsOptionError, \
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
227 "'%s' must be a %s (got `%s`)" % (option, what, val)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
228 return val
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
229
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
230 def ensure_string (self, option, default=None):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
231 """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
232 'default'.
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
233 """
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
234 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
235
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
236 def ensure_string_list (self, option):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
237 """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
238 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
239 "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
240 ["foo", "bar", "baz"].
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
241 """
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
242 val = getattr(self, option)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
243 if val is None:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
244 return
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
245 elif type(val) is StringType:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
246 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
247 else:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
248 if type(val) is ListType:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
249 types = map(type, val)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
250 ok = (types == [StringType] * len(val))
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
251 else:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
252 ok = 0
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
253
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
254 if not ok:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
255 raise DistutilsOptionError, \
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
256 "'%s' must be a list of strings (got %s)" % \
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
257 (option, `val`)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
258
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
259 def _ensure_tested_string (self, option, tester,
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
260 what, error_fmt, default=None):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
261 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
262 if val is not None and not tester(val):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
263 raise DistutilsOptionError, \
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
264 ("error in '%s' option: " + error_fmt) % (option, val)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
265
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
266 def ensure_filename (self, option):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
267 """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
268 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
269 "filename",
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
270 "'%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
271
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
272 def ensure_dirname (self, option):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
273 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
274 "directory name",
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
275 "'%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
276
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
277
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
278 # -- 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
279
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
280 def get_command_name (self):
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
281 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
282 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
283 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
284 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
285
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
286
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
287 def set_undefined_options (self, src_cmd, *option_pairs):
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
288 """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
289 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
290 "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
291 has not been changed between 'initialize_options()' and
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
292 'finalize_options()'. Usually called from 'finalize_options()' for
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
293 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
294 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
295 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
296 for it if necessary); the remaining arguments are
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
297 '(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
298 '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
299 'dst_option' in the current command object".
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
300 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
301
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
302 # Option_pairs: list of (src_option, dst_option) tuples
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
303
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
304 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
305 src_cmd_obj.ensure_finalized()
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12322
diff changeset
306 for (src_option, dst_option) in option_pairs:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
307 if getattr(self, dst_option) is None:
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
308 setattr(self, dst_option,
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
309 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
310
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
311
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
312 def get_finalized_command (self, command, create=1):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
313 """Wrapper around Distribution's 'get_command_obj()' method: find
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
314 (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
315 'command', call its 'ensure_finalized()' method, and return the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
316 finalized command object.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
317 """
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
318 cmd_obj = self.distribution.get_command_obj(command, create)
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
319 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
320 return cmd_obj
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
321
12810
711b32960934 Added 'reinitialize_command()' method -- delegated to Distribution instance.
Greg Ward <gward@python.net>
parents: 12789
diff changeset
322 # 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
323 # same in dist.py, if so)
14628
7211fbe0db9d In 'reinitialize_subcommand()', pass 'reinit_subcommands' flag on to the
Greg Ward <gward@python.net>
parents: 14626
diff changeset
324 def reinitialize_command (self, command, reinit_subcommands=0):
7211fbe0db9d In 'reinitialize_subcommand()', pass 'reinit_subcommands' flag on to the
Greg Ward <gward@python.net>
parents: 14626
diff changeset
325 return self.distribution.reinitialize_command(
7211fbe0db9d In 'reinitialize_subcommand()', pass 'reinit_subcommands' flag on to the
Greg Ward <gward@python.net>
parents: 14626
diff changeset
326 command, reinit_subcommands)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
327
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
328 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
329 """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
330 Distribution, which creates and finalizes the command object if
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
331 necessary and then invokes its 'run()' method.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
332 """
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
333 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
334
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
335
14626
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
336 def get_sub_commands (self):
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
337 """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
338 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
339 '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
340 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
341 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
342 """
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
343 commands = []
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
344 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
345 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
346 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
347 return commands
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
348
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
349
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
350 # -- External world manipulation -----------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
351
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
352 def warn (self, msg):
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
353 sys.stderr.write("warning: %s: %s\n" %
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
354 (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
355
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
356
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
357 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
358 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
359
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
360
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
361 def mkpath (self, name, mode=0777):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
362 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
363
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
364
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
365 def copy_file (self, infile, outfile,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
366 preserve_mode=1, preserve_times=1, 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
367 """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
368 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
369 the latter defaults to false for commands that don't define it.)"""
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
370
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
371 return file_util.copy_file(
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
372 infile, outfile,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
373 preserve_mode, preserve_times,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
374 not self.force,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
375 link,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
376 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
377
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
378
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
379 def copy_tree (self, infile, outfile,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
380 preserve_mode=1, preserve_times=1, preserve_symlinks=0,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
381 level=1):
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
382 """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
383 and force flags.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
384 """
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
385 return dir_util.copy_tree(
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
386 infile, outfile,
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
387 preserve_mode,preserve_times,preserve_symlinks,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
388 not self.force,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
389 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
390
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
391 def move_file (self, src, dst, level=1):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
392 """Move a file respectin dry-run flag."""
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
393 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
394
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
395 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
396 """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
397 from distutils.spawn import spawn
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
398 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
399
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
400 def make_archive (self, base_name, format,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
401 root_dir=None, base_dir=None):
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
402 return archive_util.make_archive(
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
403 base_name, format, root_dir, base_dir, 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
404
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
405
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
406 def make_file (self, infiles, outfile, func, args,
12313
90b2a3cd365f Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents: 12296
diff changeset
407 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
408 """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
409 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
410 '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
411 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
412 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
413 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
414 timestamp checks.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
415 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
416 if exec_msg is None:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
417 exec_msg = "generating %s from %s" % \
17129
32bcb4e21005 Back out conversion to string methods; the Distutils is intended to work
Andrew M. Kuchling <amk@amk.ca>
parents: 16517
diff changeset
418 (outfile, string.join(infiles, ', '))
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
419 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
420 skip_msg = "skipping %s (inputs unchanged)" % outfile
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
421
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
422
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
423 # Allow 'infiles' to be a single string
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
424 if type(infiles) is StringType:
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
425 infiles = (infiles,)
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
426 elif type(infiles) not in (ListType, TupleType):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
427 raise TypeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
428 "'infiles' must be a string, or a list or tuple of strings"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
429
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
430 # 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
431 # 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
432 # perform the action that presumably regenerates it
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
433 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
434 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
435
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
436 # 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
437 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
438 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
439
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
440 # make_file ()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
441
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
442 # class Command
12296
b157256dba76 Added (currently) pointless and trivial main body (for future tests).
Greg Ward <gward@python.net>
parents: 12225
diff changeset
443
b157256dba76 Added (currently) pointless and trivial main body (for future tests).
Greg Ward <gward@python.net>
parents: 12225
diff changeset
444
12747
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
445 # 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
446 # 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
447 # 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
448 # 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
449
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
450 class install_misc (Command):
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
451 """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
452 Currently used by install_data and install_scripts.
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
453 """
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
454
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
455 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
456
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
457 def initialize_options (self):
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
458 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
459 self.outfiles = []
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
460
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
461 def _install_dir_from (self, dirname):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
462 self.set_undefined_options('install', (dirname, 'install_dir'))
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
463
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
464 def _copy_files (self, filelist):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
465 self.outfiles = []
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
466 if not filelist:
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
467 return
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
468 self.mkpath(self.install_dir)
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
469 for f in filelist:
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
470 self.copy_file(f, self.install_dir)
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
471 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
472
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
473 def get_outputs (self):
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
474 return self.outfiles
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
475
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
476
12296
b157256dba76 Added (currently) pointless and trivial main body (for future tests).
Greg Ward <gward@python.net>
parents: 12225
diff changeset
477 if __name__ == "__main__":
b157256dba76 Added (currently) pointless and trivial main body (for future tests).
Greg Ward <gward@python.net>
parents: 12225
diff changeset
478 print "ok"