blob: 4f0f7e3e940c5f08bdd86910e59c6cdf6d027e00 [file] [log] [blame]
Greg Ward06537a52000-03-18 15:37:26 +00001"""distutils.command.clean
2
3Implements the Distutils 'clean' command."""
4
5# contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
6
7__revision__ = "$Id$"
8
9import os
10from distutils.core import Command
11from distutils.util import remove_tree
12
13class clean (Command):
14
Greg Ward11fc7e42000-03-18 17:33:18 +000015 description = "clean up output of 'build' command"
Greg Ward06537a52000-03-18 15:37:26 +000016 user_options = [
Greg Ward11fc7e42000-03-18 17:33:18 +000017 ('build-base=', 'b',
18 "base build directory (default: 'build.build-base')"),
Greg Ward06537a52000-03-18 15:37:26 +000019 ('build-lib=', None,
Greg Ward11fc7e42000-03-18 17:33:18 +000020 "build directory for all modules (default: 'build.build-lib')"),
21 ('build-temp=', 't',
22 "temporary build directory (default: 'build.build-temp')"),
Greg Ward06537a52000-03-18 15:37:26 +000023 ('all', 'a',
24 "remove all build output, not just temporary by-products")
25 ]
26
27 def initialize_options(self):
28 self.build_base = None
29 self.build_lib = None
30 self.build_temp = None
31 self.all = None
32
33 def finalize_options(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000034 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)
40
Greg Ward06537a52000-03-18 15:37:26 +000041 self.set_undefined_options('build',
42 ('build_base', 'build_base'),
43 ('build_lib', 'build_lib'),
44 ('build_temp', 'build_temp'))
45
46 def run(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000047 # 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)
Greg Ward06537a52000-03-18 15:37:26 +000051
52 if self.all:
Greg Ward11fc7e42000-03-18 17:33:18 +000053 # 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)
56
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