home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / CLEAN.PY < prev    next >
Encoding:
Python Source  |  2000-10-14  |  2.9 KB  |  80 lines

  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. __revision__ = "$Id: clean.py,v 1.12 2000/10/14 04:06:40 gward Exp $"
  8.  
  9. import os
  10. from distutils.core import Command
  11. from distutils.dir_util import remove_tree
  12.  
  13. class clean (Command):
  14.  
  15.     description = "clean up output of 'build' command"
  16.     user_options = [
  17.         ('build-base=', 'b',
  18.          "base build directory (default: 'build.build-base')"),
  19.         ('build-lib=', None,
  20.          "build directory for all modules (default: 'build.build-lib')"),
  21.         ('build-temp=', 't',
  22.          "temporary build directory (default: 'build.build-temp')"),
  23.         ('build-scripts=', None,
  24.          "build directory for scripts (default: 'build.build-scripts')"),
  25.         ('bdist-base=', None,
  26.          "temporary directory for built distributions"),
  27.         ('all', 'a',
  28.          "remove all build output, not just temporary by-products")
  29.     ]
  30.  
  31.     boolean_options = ['all']
  32.  
  33.     def initialize_options(self):
  34.         self.build_base = None
  35.         self.build_lib = None
  36.         self.build_temp = None
  37.         self.build_scripts = None
  38.         self.bdist_base = None
  39.         self.all = None
  40.  
  41.     def finalize_options(self):
  42.         self.set_undefined_options('build',
  43.                                    ('build_base', 'build_base'),
  44.                                    ('build_lib', 'build_lib'),
  45.                                    ('build_scripts', 'build_scripts'),
  46.                                    ('build_temp', 'build_temp'))
  47.         self.set_undefined_options('bdist',
  48.                                    ('bdist_base', 'bdist_base'))
  49.  
  50.     def run(self):
  51.         # remove the build/temp.<plat> directory (unless it's already
  52.         # gone)
  53.         if os.path.exists(self.build_temp):
  54.             remove_tree(self.build_temp, self.verbose, self.dry_run)
  55.         else:
  56.             self.warn("'%s' does not exist -- can't clean it" %
  57.                       self.build_temp)
  58.  
  59.         if self.all:
  60.             # remove build directories
  61.             for directory in (self.build_lib,
  62.                               self.bdist_base,
  63.                               self.build_scripts):
  64.                 if os.path.exists(directory):
  65.                     remove_tree(directory, self.verbose, self.dry_run)
  66.                 else:
  67.                     self.warn("'%s' does not exist -- can't clean it" %
  68.                               directory)
  69.  
  70.         # just for the heck of it, try to remove the base build directory:
  71.         # we might have emptied it right now, but if not we don't care
  72.         if not self.dry_run:
  73.             try:
  74.                 os.rmdir(self.build_base)
  75.                 self.announce("removing '%s'" % self.build_base)
  76.             except OSError:
  77.                 pass
  78.  
  79. # class clean
  80.