blob: 1d8c7b2200f18086806f25853f19f8b6c736ad58 [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
Greg Wardab3a0f32000-08-05 01:31:54 +000011from distutils.dir_util import remove_tree
Greg Ward06537a52000-03-18 15:37:26 +000012
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):
37 self.set_undefined_options('build',
Gregory P. Smitha1902682000-05-13 01:56:55 +000038 ('build_base', 'build_base'),
39 ('build_lib', 'build_lib'),
Gregory P. Smitha04d8072000-05-13 02:30:15 +000040 ('build_temp', 'build_temp'))
41 self.set_undefined_options('bdist',
42 ('bdist_base', 'bdist_base'))
Greg Ward06537a52000-03-18 15:37:26 +000043
44 def run(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000045 # remove the build/temp.<plat> directory (unless it's already
46 # gone)
47 if os.path.exists (self.build_temp):
48 remove_tree (self.build_temp, self.verbose, self.dry_run)
Greg Ward0eeebfd2000-05-28 23:47:00 +000049 else:
50 self.warn ("'%s' does not exist -- can't clean it" %
51 self.build_temp)
52
53
54
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)
Greg Ward0eeebfd2000-05-28 23:47:00 +000060 else:
61 self.warn ("'%s' does not exist -- can't clean it" %
62 self.build_lib)
63
Gregory P. Smitha1902682000-05-13 01:56:55 +000064 # remove the temporary directory used for creating built
65 # distributions (default "build/bdist") -- eg. type of
66 # built distribution will have its own subdirectory under
67 # "build/bdist", but they'll be taken care of by
68 # 'remove_tree()'.
Gregory P. Smitha04d8072000-05-13 02:30:15 +000069 if os.path.exists (self.bdist_base):
70 remove_tree (self.bdist_base, self.verbose, self.dry_run)
Greg Ward0eeebfd2000-05-28 23:47:00 +000071 else:
72 self.warn ("'%s' does not exist -- can't clean it" %
73 self.bdist_base)
Greg Ward11fc7e42000-03-18 17:33:18 +000074
75 # just for the heck of it, try to remove the base build directory:
76 # we might have emptied it right now, but if not we don't care
77 if not self.dry_run:
78 try:
79 os.rmdir (self.build_base)
80 self.announce ("removing '%s'" % self.build_base)
81 except OSError:
82 pass
Greg Wardfcd974e2000-05-25 01:10:04 +000083
84# class clean