Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 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$" |
| 8 | |
| 9 | import os |
| 10 | from distutils.core import Command |
Greg Ward | ab3a0f3 | 2000-08-05 01:31:54 +0000 | [diff] [blame^] | 11 | from distutils.dir_util import remove_tree |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 12 | |
| 13 | class clean (Command): |
| 14 | |
Greg Ward | 11fc7e4 | 2000-03-18 17:33:18 +0000 | [diff] [blame] | 15 | description = "clean up output of 'build' command" |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 16 | user_options = [ |
Greg Ward | 11fc7e4 | 2000-03-18 17:33:18 +0000 | [diff] [blame] | 17 | ('build-base=', 'b', |
| 18 | "base build directory (default: 'build.build-base')"), |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 19 | ('build-lib=', None, |
Greg Ward | 11fc7e4 | 2000-03-18 17:33:18 +0000 | [diff] [blame] | 20 | "build directory for all modules (default: 'build.build-lib')"), |
| 21 | ('build-temp=', 't', |
| 22 | "temporary build directory (default: 'build.build-temp')"), |
Gregory P. Smith | a04d807 | 2000-05-13 02:30:15 +0000 | [diff] [blame] | 23 | ('bdist-base=', None, |
Gregory P. Smith | a190268 | 2000-05-13 01:56:55 +0000 | [diff] [blame] | 24 | "temporary directory for built distributions"), |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 25 | ('all', 'a', |
| 26 | "remove all build output, not just temporary by-products") |
| 27 | ] |
| 28 | |
| 29 | def initialize_options(self): |
| 30 | self.build_base = None |
| 31 | self.build_lib = None |
| 32 | self.build_temp = None |
Gregory P. Smith | a04d807 | 2000-05-13 02:30:15 +0000 | [diff] [blame] | 33 | self.bdist_base = None |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 34 | self.all = None |
| 35 | |
| 36 | def finalize_options(self): |
| 37 | self.set_undefined_options('build', |
Gregory P. Smith | a190268 | 2000-05-13 01:56:55 +0000 | [diff] [blame] | 38 | ('build_base', 'build_base'), |
| 39 | ('build_lib', 'build_lib'), |
Gregory P. Smith | a04d807 | 2000-05-13 02:30:15 +0000 | [diff] [blame] | 40 | ('build_temp', 'build_temp')) |
| 41 | self.set_undefined_options('bdist', |
| 42 | ('bdist_base', 'bdist_base')) |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 43 | |
| 44 | def run(self): |
Greg Ward | 11fc7e4 | 2000-03-18 17:33:18 +0000 | [diff] [blame] | 45 | # remove the build/temp.<plat> directory (unless it's already |
| 46 | # gone) |
| 47 | if os.path.exists (self.build_temp): |
| 48 | remove_tree (self.build_temp, self.verbose, self.dry_run) |
Greg Ward | 0eeebfd | 2000-05-28 23:47:00 +0000 | [diff] [blame] | 49 | else: |
| 50 | self.warn ("'%s' does not exist -- can't clean it" % |
| 51 | self.build_temp) |
| 52 | |
| 53 | |
| 54 | |
Greg Ward | 06537a5 | 2000-03-18 15:37:26 +0000 | [diff] [blame] | 55 | |
| 56 | if self.all: |
Greg Ward | 11fc7e4 | 2000-03-18 17:33:18 +0000 | [diff] [blame] | 57 | # remove the module build directory (unless already gone) |
| 58 | if os.path.exists (self.build_lib): |
| 59 | remove_tree (self.build_lib, self.verbose, self.dry_run) |
Greg Ward | 0eeebfd | 2000-05-28 23:47:00 +0000 | [diff] [blame] | 60 | else: |
| 61 | self.warn ("'%s' does not exist -- can't clean it" % |
| 62 | self.build_lib) |
| 63 | |
Gregory P. Smith | a190268 | 2000-05-13 01:56:55 +0000 | [diff] [blame] | 64 | # remove the temporary directory used for creating built |
| 65 | # distributions (default "build/bdist") -- eg. type of |
| 66 | # built distribution will have its own subdirectory under |
| 67 | # "build/bdist", but they'll be taken care of by |
| 68 | # 'remove_tree()'. |
Gregory P. Smith | a04d807 | 2000-05-13 02:30:15 +0000 | [diff] [blame] | 69 | if os.path.exists (self.bdist_base): |
| 70 | remove_tree (self.bdist_base, self.verbose, self.dry_run) |
Greg Ward | 0eeebfd | 2000-05-28 23:47:00 +0000 | [diff] [blame] | 71 | else: |
| 72 | self.warn ("'%s' does not exist -- can't clean it" % |
| 73 | self.bdist_base) |
Greg Ward | 11fc7e4 | 2000-03-18 17:33:18 +0000 | [diff] [blame] | 74 | |
| 75 | # just for the heck of it, try to remove the base build directory: |
| 76 | # we might have emptied it right now, but if not we don't care |
| 77 | if not self.dry_run: |
| 78 | try: |
| 79 | os.rmdir (self.build_base) |
| 80 | self.announce ("removing '%s'" % self.build_base) |
| 81 | except OSError: |
| 82 | pass |
Greg Ward | fcd974e | 2000-05-25 01:10:04 +0000 | [diff] [blame] | 83 | |
| 84 | # class clean |