1 | n/a | """distutils.command.clean |
---|
2 | n/a | |
---|
3 | n/a | Implements the Distutils 'clean' command.""" |
---|
4 | n/a | |
---|
5 | n/a | # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18 |
---|
6 | n/a | |
---|
7 | n/a | import os |
---|
8 | n/a | from distutils.core import Command |
---|
9 | n/a | from distutils.dir_util import remove_tree |
---|
10 | n/a | from distutils import log |
---|
11 | n/a | |
---|
12 | n/a | class clean(Command): |
---|
13 | n/a | |
---|
14 | n/a | description = "clean up temporary files from 'build' command" |
---|
15 | n/a | user_options = [ |
---|
16 | n/a | ('build-base=', 'b', |
---|
17 | n/a | "base build directory (default: 'build.build-base')"), |
---|
18 | n/a | ('build-lib=', None, |
---|
19 | n/a | "build directory for all modules (default: 'build.build-lib')"), |
---|
20 | n/a | ('build-temp=', 't', |
---|
21 | n/a | "temporary build directory (default: 'build.build-temp')"), |
---|
22 | n/a | ('build-scripts=', None, |
---|
23 | n/a | "build directory for scripts (default: 'build.build-scripts')"), |
---|
24 | n/a | ('bdist-base=', None, |
---|
25 | n/a | "temporary directory for built distributions"), |
---|
26 | n/a | ('all', 'a', |
---|
27 | n/a | "remove all build output, not just temporary by-products") |
---|
28 | n/a | ] |
---|
29 | n/a | |
---|
30 | n/a | boolean_options = ['all'] |
---|
31 | n/a | |
---|
32 | n/a | def initialize_options(self): |
---|
33 | n/a | self.build_base = None |
---|
34 | n/a | self.build_lib = None |
---|
35 | n/a | self.build_temp = None |
---|
36 | n/a | self.build_scripts = None |
---|
37 | n/a | self.bdist_base = None |
---|
38 | n/a | self.all = None |
---|
39 | n/a | |
---|
40 | n/a | def finalize_options(self): |
---|
41 | n/a | self.set_undefined_options('build', |
---|
42 | n/a | ('build_base', 'build_base'), |
---|
43 | n/a | ('build_lib', 'build_lib'), |
---|
44 | n/a | ('build_scripts', 'build_scripts'), |
---|
45 | n/a | ('build_temp', 'build_temp')) |
---|
46 | n/a | self.set_undefined_options('bdist', |
---|
47 | n/a | ('bdist_base', 'bdist_base')) |
---|
48 | n/a | |
---|
49 | n/a | def run(self): |
---|
50 | n/a | # remove the build/temp.<plat> directory (unless it's already |
---|
51 | n/a | # gone) |
---|
52 | n/a | if os.path.exists(self.build_temp): |
---|
53 | n/a | remove_tree(self.build_temp, dry_run=self.dry_run) |
---|
54 | n/a | else: |
---|
55 | n/a | log.debug("'%s' does not exist -- can't clean it", |
---|
56 | n/a | self.build_temp) |
---|
57 | n/a | |
---|
58 | n/a | if self.all: |
---|
59 | n/a | # remove build directories |
---|
60 | n/a | for directory in (self.build_lib, |
---|
61 | n/a | self.bdist_base, |
---|
62 | n/a | self.build_scripts): |
---|
63 | n/a | if os.path.exists(directory): |
---|
64 | n/a | remove_tree(directory, dry_run=self.dry_run) |
---|
65 | n/a | else: |
---|
66 | n/a | log.warn("'%s' does not exist -- can't clean it", |
---|
67 | n/a | directory) |
---|
68 | n/a | |
---|
69 | n/a | # just for the heck of it, try to remove the base build directory: |
---|
70 | n/a | # we might have emptied it right now, but if not we don't care |
---|
71 | n/a | if not self.dry_run: |
---|
72 | n/a | try: |
---|
73 | n/a | os.rmdir(self.build_base) |
---|
74 | n/a | log.info("removing '%s'", self.build_base) |
---|
75 | n/a | except OSError: |
---|
76 | n/a | pass |
---|