ยปCore Development>Code coverage>Lib/distutils/command/clean.py

Python code coverage for Lib/distutils/command/clean.py

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