Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/clean.py @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 3e26c9033306 |
| children |
| 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 import os |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
8 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
|
9 from distutils.dir_util import remove_tree |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15216
diff
changeset
|
10 from distutils import log |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
11 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
34648
diff
changeset
|
12 class clean(Command): |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
13 |
|
34648
d48fa0afdcba
Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents:
33965
diff
changeset
|
14 description = "clean up temporary files from 'build' command" |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
15 user_options = [ |
| 12021 | 16 ('build-base=', 'b', |
| 17 "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
|
18 ('build-lib=', None, |
| 12021 | 19 "build directory for all modules (default: 'build.build-lib')"), |
| 20 ('build-temp=', 't', | |
| 21 "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
|
22 ('build-scripts=', None, |
|
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
23 "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
|
24 ('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
|
25 "temporary directory for built distributions"), |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
26 ('all', 'a', |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
27 "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
|
28 ] |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
29 |
|
14829
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14517
diff
changeset
|
30 boolean_options = ['all'] |
|
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14517
diff
changeset
|
31 |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
32 def initialize_options(self): |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
33 self.build_base = None |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
34 self.build_lib = None |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
35 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
|
36 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
|
37 self.bdist_base = None |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
38 self.all = None |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
39 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
40 def finalize_options(self): |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
41 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
|
42 ('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
|
43 ('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
|
44 ('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
|
45 ('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
|
46 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
|
47 ('bdist_base', 'bdist_base')) |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
48 |
|
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
49 def run(self): |
| 12021 | 50 # remove the build/temp.<plat> directory (unless it's already |
| 51 # gone) | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
52 if os.path.exists(self.build_temp): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15216
diff
changeset
|
53 remove_tree(self.build_temp, dry_run=self.dry_run) |
|
12785
f6e730f65bce
Moved warnings out of 'finalize_options()' into 'run()'.
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
54 else: |
|
23701
9a5c48579633
Change warning to debug level; it's a very minor issue.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23668
diff
changeset
|
55 log.debug("'%s' does not exist -- can't clean it", |
|
9a5c48579633
Change warning to debug level; it's a very minor issue.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23668
diff
changeset
|
56 self.build_temp) |
|
12785
f6e730f65bce
Moved warnings out of 'finalize_options()' into 'run()'.
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
57 |
|
12018
056972517191
Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff
changeset
|
58 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
|
59 # remove build directories |
|
bf844ac2c81a
Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents:
13871
diff
changeset
|
60 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
|
61 self.bdist_base, |
| 15216 | 62 self.build_scripts): |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
63 if os.path.exists(directory): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15216
diff
changeset
|
64 remove_tree(directory, dry_run=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
|
65 else: |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15216
diff
changeset
|
66 log.warn("'%s' does not exist -- can't clean it", |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15216
diff
changeset
|
67 directory) |
| 12021 | 68 |
| 69 # just for the heck of it, try to remove the base build directory: | |
| 70 # we might have emptied it right now, but if not we don't care | |
| 71 if not self.dry_run: | |
| 72 try: | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
73 os.rmdir(self.build_base) |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15216
diff
changeset
|
74 log.info("removing '%s'", self.build_base) |
| 12021 | 75 except OSError: |
| 76 pass |
