1
"""distutils.command.clean
3
Implements the Distutils 'clean' command."""
5
# contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
7
# This module should be kept compatible with Python 2.1.
9
__revision__ = "$Id: clean.py 38532 2005-03-03 08:12:27Z loewis $"
12
from distutils.core import Command
13
from distutils.dir_util import remove_tree
14
from distutils import log
16
class clean (Command):
18
description = "clean up temporary files from 'build' command"
21
"base build directory (default: 'build.build-base')"),
23
"build directory for all modules (default: 'build.build-lib')"),
25
"temporary build directory (default: 'build.build-temp')"),
26
('build-scripts=', None,
27
"build directory for scripts (default: 'build.build-scripts')"),
29
"temporary directory for built distributions"),
31
"remove all build output, not just temporary by-products")
34
boolean_options = ['all']
36
def initialize_options(self):
37
self.build_base = None
39
self.build_temp = None
40
self.build_scripts = None
41
self.bdist_base = None
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'))
54
# remove the build/temp.<plat> directory (unless it's already
56
if os.path.exists(self.build_temp):
57
remove_tree(self.build_temp, dry_run=self.dry_run)
59
log.debug("'%s' does not exist -- can't clean it",
63
# remove build directories
64
for directory in (self.build_lib,
67
if os.path.exists(directory):
68
remove_tree(directory, dry_run=self.dry_run)
70
log.warn("'%s' does not exist -- can't clean it",
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
77
os.rmdir(self.build_base)
78
log.info("removing '%s'", self.build_base)