blob: 2f3597fdbcaabcd81e74d994e78b0f48712816af [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')"),
Greg Ward7ac743b2000-09-12 00:07:49 +000023 ('build-scripts=', None,
24 "build directory for scripts (default: 'build.build-scripts')"),
Gregory P. Smitha04d8072000-05-13 02:30:15 +000025 ('bdist-base=', None,
Gregory P. Smitha1902682000-05-13 01:56:55 +000026 "temporary directory for built distributions"),
Greg Ward06537a52000-03-18 15:37:26 +000027 ('all', 'a',
28 "remove all build output, not just temporary by-products")
29 ]
30
31 def initialize_options(self):
32 self.build_base = None
33 self.build_lib = None
34 self.build_temp = None
Greg Ward7ac743b2000-09-12 00:07:49 +000035 self.build_scripts = None
Gregory P. Smitha04d8072000-05-13 02:30:15 +000036 self.bdist_base = None
Greg Ward06537a52000-03-18 15:37:26 +000037 self.all = None
38
39 def finalize_options(self):
40 self.set_undefined_options('build',
Gregory P. Smitha1902682000-05-13 01:56:55 +000041 ('build_base', 'build_base'),
42 ('build_lib', 'build_lib'),
Greg Ward7ac743b2000-09-12 00:07:49 +000043 ('build_scripts', 'build_scripts'),
Gregory P. Smitha04d8072000-05-13 02:30:15 +000044 ('build_temp', 'build_temp'))
45 self.set_undefined_options('bdist',
46 ('bdist_base', 'bdist_base'))
Greg Ward06537a52000-03-18 15:37:26 +000047
48 def run(self):
Greg Ward11fc7e42000-03-18 17:33:18 +000049 # remove the build/temp.<plat> directory (unless it's already
50 # gone)
51 if os.path.exists (self.build_temp):
52 remove_tree (self.build_temp, self.verbose, self.dry_run)
Greg Ward0eeebfd2000-05-28 23:47:00 +000053 else:
54 self.warn ("'%s' does not exist -- can't clean it" %
55 self.build_temp)
56
Greg Ward06537a52000-03-18 15:37:26 +000057 if self.all:
Greg Ward7ac743b2000-09-12 00:07:49 +000058 # remove build directories
59 for directory in (self.build_lib,
60 self.bdist_base,
61 self.build_scripts):
62 if os.path.exists (directory):
63 remove_tree (directory, self.verbose, self.dry_run)
64 else:
65 self.warn ("'%s' does not exist -- can't clean it" %
66 directory)
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
Greg Wardfcd974e2000-05-25 01:10:04 +000076
77# class clean