annotate Lib/distutils/cmd.py @ 25838:8540887bcec6 2.2

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