blob: 78166f2642955e70ccfdfc7d3b02d705ce2a891b [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')"),
Gregory P. Smitha1902682000-05-13 01:56:55 +000023 ('build-bdist=', None,
24 "temporary directory for built distributions"),
Greg Ward06537a52000-03-18 15:37:26 +000025 ('all', 'a',
26 "remove all build output, not just temporary by-products")
27 ]
28
29 def initialize_options(self):
30 self.build_base = None
31 self.build_lib = None
32 self.build_temp = None
Gregory P. Smitha1902682000-05-13 01:56:55 +000033 self.build_bdist = None
Greg Ward06537a52000-03-18 15:37:26 +000034 self.all = None
35
36 def finalize_options(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000037 if self.build_lib and not os.path.exists (self.build_lib):
38 self.warn ("'%s' does not exist -- can't clean it" %
39 self.build_lib)
40 if self.build_temp and not os.path.exists (self.build_temp):
41 self.warn ("'%s' does not exist -- can't clean it" %
42 self.build_temp)
43
Greg Ward06537a52000-03-18 15:37:26 +000044 self.set_undefined_options('build',
Gregory P. Smitha1902682000-05-13 01:56:55 +000045 ('build_base', 'build_base'),
46 ('build_lib', 'build_lib'),
47 ('build_temp', 'build_temp'),
48 ('build_bdist', 'build_bdist'))
Greg Ward06537a52000-03-18 15:37:26 +000049
50 def run(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000051 # 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)
Greg Ward06537a52000-03-18 15:37:26 +000055
56 if self.all:
Greg Ward11fc7e42000-03-18 17:33:18 +000057 # remove the module build directory (unless already gone)
58 if os.path.exists (self.build_lib):
59 remove_tree (self.build_lib, self.verbose, self.dry_run)
Gregory P. Smitha1902682000-05-13 01:56:55 +000060 # remove the temporary directory used for creating built
61 # distributions (default "build/bdist") -- eg. type of
62 # built distribution will have its own subdirectory under
63 # "build/bdist", but they'll be taken care of by
64 # 'remove_tree()'.
65 if os.path.exists (self.build_bdist)
66 remove_tree (self.build_bdist, self.verbose, self.dry_run)
Greg Ward11fc7e42000-03-18 17:33:18 +000067
68 # just for the heck of it, try to remove the base build directory:
69 # we might have emptied it right now, but if not we don't care
70 if not self.dry_run:
71 try:
72 os.rmdir (self.build_base)
73 self.announce ("removing '%s'" % self.build_base)
74 except OSError:
75 pass