Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Lib / distutils / command / clean.py
blob4f0f7e3e940c5f08bdd86910e59c6cdf6d027e00
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.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 ('all', 'a',
24 "remove all build output, not just temporary by-products")
27 def initialize_options(self):
28 self.build_base = None
29 self.build_lib = None
30 self.build_temp = None
31 self.all = None
33 def finalize_options(self):
34 if self.build_lib and not os.path.exists (self.build_lib):
35 self.warn ("'%s' does not exist -- can't clean it" %
36 self.build_lib)
37 if self.build_temp and not os.path.exists (self.build_temp):
38 self.warn ("'%s' does not exist -- can't clean it" %
39 self.build_temp)
41 self.set_undefined_options('build',
42 ('build_base', 'build_base'),
43 ('build_lib', 'build_lib'),
44 ('build_temp', 'build_temp'))
46 def run(self):
47 # remove the build/temp.<plat> directory (unless it's already
48 # gone)
49 if os.path.exists (self.build_temp):
50 remove_tree (self.build_temp, self.verbose, self.dry_run)
52 if self.all:
53 # remove the module build directory (unless already gone)
54 if os.path.exists (self.build_lib):
55 remove_tree (self.build_lib, self.verbose, self.dry_run)
57 # just for the heck of it, try to remove the base build directory:
58 # we might have emptied it right now, but if not we don't care
59 if not self.dry_run:
60 try:
61 os.rmdir (self.build_base)
62 self.announce ("removing '%s'" % self.build_base)
63 except OSError:
64 pass