Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/clean.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 | a3975d2811f0 |
| children | ca87119255eb |
| rev | line source |
|---|---|
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
1 """distutils.command.clean |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
2 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
3 Implements the Distutils 'clean' command.""" |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
4 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
6 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
7 __revision__ = "$Id$" |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
8 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
9 import os |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
10 from distutils.core import Command |
|
13871
8307446bc6aa
Fixed imports from '*util' modules to not just import everything from util.
Greg Ward <gward@python.net>
parents:
12785
diff
changeset
|
11 from distutils.dir_util import remove_tree |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
12 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
13 class clean (Command): |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
14 |
| 12021 | 15 description = "clean up output of 'build' command" |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
16 user_options = [ |
| 12021 | 17 ('build-base=', 'b', |
| 18 "base build directory (default: 'build.build-base')"), | |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
19 ('build-lib=', None, |
| 12021 | 20 "build directory for all modules (default: 'build.build-lib')"), |
| 21 ('build-temp=', 't', | |
| 22 "temporary build directory (default: 'build.build-temp')"), | |
|
14517
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
23 ('build-scripts=', None, |
|
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
24 "build directory for scripts (default: 'build.build-scripts')"), |
|
12700
94ede04b9a9e
Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12699
diff
changeset
|
25 ('bdist-base=', None, |
|
12693
1dee93eb9ee3
Added the 'build_bdist' option and code to clean it up -- this is the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12021
diff
changeset
|
26 "temporary directory for built distributions"), |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
27 ('all', 'a', |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
28 "remove all build output, not just temporary by-products") |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
29 ] |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
30 |
|
14829
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14517
diff
changeset
|
31 boolean_options = ['all'] |
|
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14517
diff
changeset
|
32 |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
33 def initialize_options(self): |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
34 self.build_base = None |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
35 self.build_lib = None |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
36 self.build_temp = None |
|
14517
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
37 self.build_scripts = None |
|
12700
94ede04b9a9e
Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12699
diff
changeset
|
38 self.bdist_base = None |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
39 self.all = None |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
40 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
41 def finalize_options(self): |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
42 self.set_undefined_options('build', |
|
12693
1dee93eb9ee3
Added the 'build_bdist' option and code to clean it up -- this is the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12021
diff
changeset
|
43 ('build_base', 'build_base'), |
|
1dee93eb9ee3
Added the 'build_bdist' option and code to clean it up -- this is the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12021
diff
changeset
|
44 ('build_lib', 'build_lib'), |
|
14517
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
45 ('build_scripts', 'build_scripts'), |
|
12700
94ede04b9a9e
Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12699
diff
changeset
|
46 ('build_temp', 'build_temp')) |
|
94ede04b9a9e
Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12699
diff
changeset
|
47 self.set_undefined_options('bdist', |
|
94ede04b9a9e
Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents:
12699
diff
changeset
|
48 ('bdist_base', 'bdist_base')) |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
49 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
50 def run(self): |
| 12021 | 51 # remove the build/temp.<plat> directory (unless it's already |
| 52 # gone) | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
53 if os.path.exists(self.build_temp): |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
54 remove_tree(self.build_temp, self.verbose, self.dry_run) |
|
12785
f6e730f65bce
Moved warnings out of 'finalize_options()' into 'run()'.
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
55 else: |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
56 self.warn("'%s' does not exist -- can't clean it" % |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
57 self.build_temp) |
|
12785
f6e730f65bce
Moved warnings out of 'finalize_options()' into 'run()'.
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
58 |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
59 if self.all: |
|
14517
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
60 # remove build directories |
|
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
61 for directory in (self.build_lib, |
|
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
62 self.bdist_base, |
| 15216 | 63 self.build_scripts): |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
64 if os.path.exists(directory): |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
65 remove_tree(directory, self.verbose, self.dry_run) |
|
14517
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
66 else: |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
67 self.warn("'%s' does not exist -- can't clean it" % |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
68 directory) |
| 12021 | 69 |
| 70 # just for the heck of it, try to remove the base build directory: | |
| 71 # we might have emptied it right now, but if not we don't care | |
| 72 if not self.dry_run: | |
| 73 try: | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
74 os.rmdir(self.build_base) |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
75 self.announce("removing '%s'" % self.build_base) |
| 12021 | 76 except OSError: |
| 77 pass | |
|
12743
e878a647e06e
Normalized all the end-of-class lines.
Greg Ward <gward@python.net>
parents:
12700
diff
changeset
|
78 |
|
e878a647e06e
Normalized all the end-of-class lines.
Greg Ward <gward@python.net>
parents:
12700
diff
changeset
|
79 # class clean |
