0001 """distutils.command.clean 0002 0003 Implements the Distutils 'clean' command.""" 0004 0005 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18 0006 0007 # This module should be kept compatible with Python 1.5.2. 0008 0009 __revision__ = "$Id: clean.py,v 1.15 2002/11/19 13:12:28 akuchling Exp $" 0010 0011 import os 0012 from distutils.core import Command 0013 from distutils.dir_util import remove_tree 0014 from distutils import log 0015 0016 class clean (Command): 0017 0018 description = "clean up output of 'build' command" 0019 user_options = [ 0020 ('build-base=', 'b', 0021 "base build directory (default: 'build.build-base')"), 0022 ('build-lib=', None, 0023 "build directory for all modules (default: 'build.build-lib')"), 0024 ('build-temp=', 't', 0025 "temporary build directory (default: 'build.build-temp')"), 0026 ('build-scripts=', None, 0027 "build directory for scripts (default: 'build.build-scripts')"), 0028 ('bdist-base=', None, 0029 "temporary directory for built distributions"), 0030 ('all', 'a', 0031 "remove all build output, not just temporary by-products") 0032 ] 0033 0034 boolean_options = ['all'] 0035 0036 def initialize_options(self): 0037 self.build_base = None 0038 self.build_lib = None 0039 self.build_temp = None 0040 self.build_scripts = None 0041 self.bdist_base = None 0042 self.all = None 0043 0044 def finalize_options(self): 0045 self.set_undefined_options('build', 0046 ('build_base', 'build_base'), 0047 ('build_lib', 'build_lib'), 0048 ('build_scripts', 'build_scripts'), 0049 ('build_temp', 'build_temp')) 0050 self.set_undefined_options('bdist', 0051 ('bdist_base', 'bdist_base')) 0052 0053 def run(self): 0054 # remove the build/temp.<plat> directory (unless it's already 0055 # gone) 0056 if os.path.exists(self.build_temp): 0057 remove_tree(self.build_temp, dry_run=self.dry_run) 0058 else: 0059 log.debug("'%s' does not exist -- can't clean it", 0060 self.build_temp) 0061 0062 if self.all: 0063 # remove build directories 0064 for directory in (self.build_lib, 0065 self.bdist_base, 0066 self.build_scripts): 0067 if os.path.exists(directory): 0068 remove_tree(directory, dry_run=self.dry_run) 0069 else: 0070 log.warn("'%s' does not exist -- can't clean it", 0071 directory) 0072 0073 # just for the heck of it, try to remove the base build directory: 0074 # we might have emptied it right now, but if not we don't care 0075 if not self.dry_run: 0076 try: 0077 os.rmdir(self.build_base) 0078 log.info("removing '%s'", self.build_base) 0079 except OSError: 0080 pass 0081 0082 # class clean 0083
Generated by PyXR 0.9.4