blob: 62307a1968e51e5b16138c6f5287b5b6dbee3508 [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. Smitha04d8072000-05-13 02:30:15 +000023 ('bdist-base=', None,
Gregory P. Smitha1902682000-05-13 01:56:55 +000024 "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. Smitha04d8072000-05-13 02:30:15 +000033 self.bdist_base = 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'),
Gregory P. Smitha04d8072000-05-13 02:30:15 +000047 ('build_temp', 'build_temp'))
48 self.set_undefined_options('bdist',
49 ('bdist_base', 'bdist_base'))
Greg Ward06537a52000-03-18 15:37:26 +000050
51 def run(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000052 # remove the build/temp.<plat> directory (unless it's already
53 # gone)
54 if os.path.exists (self.build_temp):
55 remove_tree (self.build_temp, self.verbose, self.dry_run)
Greg Ward06537a52000-03-18 15:37:26 +000056
57 if self.all:
Greg Ward11fc7e42000-03-18 17:33:18 +000058 # remove the module build directory (unless already gone)
59 if os.path.exists (self.build_lib):
60 remove_tree (self.build_lib, self.verbose, self.dry_run)
Gregory P. Smitha1902682000-05-13 01:56:55 +000061 # remove the temporary directory used for creating built
62 # distributions (default "build/bdist") -- eg. type of
63 # built distribution will have its own subdirectory under
64 # "build/bdist", but they'll be taken care of by
65 # 'remove_tree()'.
Gregory P. Smitha04d8072000-05-13 02:30:15 +000066 if os.path.exists (self.bdist_base):
67 remove_tree (self.bdist_base, self.verbose, self.dry_run)
Greg Ward11fc7e42000-03-18 17:33:18 +000068
69 # just for the heck of it, try to remove the base build directory:
70 # we might have emptied it right now, but if not we don't care
71 if not self.dry_run:
72 try:
73 os.rmdir (self.build_base)
74 self.announce ("removing '%s'" % self.build_base)
75 except OSError:
76 pass
Greg Wardfcd974e2000-05-25 01:10:04 +000077
78# class clean