]> git.saurik.com Git - wxWidgets.git/blob - wxPython/distutils/command/clean.py
added tech note about writing unit tests
[wxWidgets.git] / wxPython / distutils / command / clean.py
1 """distutils.command.clean
2
3 Implements the Distutils 'clean' command."""
4
5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
6
7 # This module should be kept compatible with Python 1.5.2.
8
9 __revision__ = "$Id$"
10
11 import os
12 from distutils.core import Command
13 from distutils.dir_util import remove_tree
14 from distutils import log
15
16 class clean (Command):
17
18 description = "clean up output of 'build' command"
19 user_options = [
20 ('build-base=', 'b',
21 "base build directory (default: 'build.build-base')"),
22 ('build-lib=', None,
23 "build directory for all modules (default: 'build.build-lib')"),
24 ('build-temp=', 't',
25 "temporary build directory (default: 'build.build-temp')"),
26 ('build-scripts=', None,
27 "build directory for scripts (default: 'build.build-scripts')"),
28 ('bdist-base=', None,
29 "temporary directory for built distributions"),
30 ('all', 'a',
31 "remove all build output, not just temporary by-products")
32 ]
33
34 boolean_options = ['all']
35
36 def initialize_options(self):
37 self.build_base = None
38 self.build_lib = None
39 self.build_temp = None
40 self.build_scripts = None
41 self.bdist_base = None
42 self.all = None
43
44 def finalize_options(self):
45 self.set_undefined_options('build',
46 ('build_base', 'build_base'),
47 ('build_lib', 'build_lib'),
48 ('build_scripts', 'build_scripts'),
49 ('build_temp', 'build_temp'))
50 self.set_undefined_options('bdist',
51 ('bdist_base', 'bdist_base'))
52
53 def run(self):
54 # remove the build/temp.<plat> directory (unless it's already
55 # gone)
56 if os.path.exists(self.build_temp):
57 remove_tree(self.build_temp, dry_run=self.dry_run)
58 else:
59 log.debug("'%s' does not exist -- can't clean it",
60 self.build_temp)
61
62 if self.all:
63 # remove build directories
64 for directory in (self.build_lib,
65 self.bdist_base,
66 self.build_scripts):
67 if os.path.exists(directory):
68 remove_tree(directory, dry_run=self.dry_run)
69 else:
70 log.warn("'%s' does not exist -- can't clean it",
71 directory)
72
73 # just for the heck of it, try to remove the base build directory:
74 # we might have emptied it right now, but if not we don't care
75 if not self.dry_run:
76 try:
77 os.rmdir(self.build_base)
78 log.info("removing '%s'", self.build_base)
79 except OSError:
80 pass
81
82 # class clean