1 """distutils.command.clean
3 Implements the Distutils 'clean' command."""
5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
10 from distutils
.core
import Command
11 from distutils
.dir_util
import remove_tree
13 class clean (Command
):
15 description
= "clean up output of 'build' command"
18 "base build directory (default: 'build.build-base')"),
20 "build directory for all modules (default: 'build.build-lib')"),
22 "temporary build directory (default: 'build.build-temp')"),
23 ('build-scripts=', None,
24 "build directory for scripts (default: 'build.build-scripts')"),
26 "temporary directory for built distributions"),
28 "remove all build output, not just temporary by-products")
31 boolean_options
= ['all']
33 def initialize_options(self
):
34 self
.build_base
= None
36 self
.build_temp
= None
37 self
.build_scripts
= None
38 self
.bdist_base
= None
41 def finalize_options(self
):
42 self
.set_undefined_options('build',
43 ('build_base', 'build_base'),
44 ('build_lib', 'build_lib'),
45 ('build_scripts', 'build_scripts'),
46 ('build_temp', 'build_temp'))
47 self
.set_undefined_options('bdist',
48 ('bdist_base', 'bdist_base'))
51 # remove the build/temp.<plat> directory (unless it's already
53 if os
.path
.exists(self
.build_temp
):
54 remove_tree(self
.build_temp
, self
.verbose
, self
.dry_run
)
56 self
.warn("'%s' does not exist -- can't clean it" %
60 # remove build directories
61 for directory
in (self
.build_lib
,
64 if os
.path
.exists(directory
):
65 remove_tree(directory
, self
.verbose
, self
.dry_run
)
67 self
.warn("'%s' does not exist -- can't clean it" %
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
74 os
.rmdir(self
.build_base
)
75 self
.announce("removing '%s'" % self
.build_base
)