Updated for 2.1b2 distribution.
[python/dscho.git] / Lib / distutils / command / clean.py
blobb4a9be45f821f6f2f59dbc541fbd6752241006e2
1 """distutils.command.clean
3 Implements the Distutils 'clean' command."""
5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
7 __revision__ = "$Id$"
9 import os
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"
16 user_options = [
17 ('build-base=', 'b',
18 "base build directory (default: 'build.build-base')"),
19 ('build-lib=', None,
20 "build directory for all modules (default: 'build.build-lib')"),
21 ('build-temp=', 't',
22 "temporary build directory (default: 'build.build-temp')"),
23 ('build-scripts=', None,
24 "build directory for scripts (default: 'build.build-scripts')"),
25 ('bdist-base=', None,
26 "temporary directory for built distributions"),
27 ('all', 'a',
28 "remove all build output, not just temporary by-products")
31 boolean_options = ['all']
33 def initialize_options(self):
34 self.build_base = None
35 self.build_lib = None
36 self.build_temp = None
37 self.build_scripts = None
38 self.bdist_base = None
39 self.all = 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'))
50 def run(self):
51 # remove the build/temp.<plat> directory (unless it's already
52 # gone)
53 if os.path.exists(self.build_temp):
54 remove_tree(self.build_temp, self.verbose, self.dry_run)
55 else:
56 self.warn("'%s' does not exist -- can't clean it" %
57 self.build_temp)
59 if self.all:
60 # remove build directories
61 for directory in (self.build_lib,
62 self.bdist_base,
63 self.build_scripts):
64 if os.path.exists(directory):
65 remove_tree(directory, self.verbose, self.dry_run)
66 else:
67 self.warn("'%s' does not exist -- can't clean it" %
68 directory)
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:
74 os.rmdir(self.build_base)
75 self.announce("removing '%s'" % self.build_base)
76 except OSError:
77 pass
79 # class clean