+class extra_clean(distutils.command.clean.clean):
+ """Also cleans stuff that setup.py copies itself. If the --all
+ flag was used also searches for .pyc, .pyd, .so files"""
+ def run(self):
+ from distutils import log
+ from distutils.filelist import FileList
+ global CLEANUP
+
+ distutils.command.clean.clean.run(self)
+
+ if self.all:
+ fl = FileList()
+ fl.include_pattern("*.pyc", 0)
+ fl.include_pattern("*.pyd", 0)
+ fl.include_pattern("*.so", 0)
+ CLEANUP += fl.files
+
+ for f in CLEANUP:
+ if os.path.isdir(f):
+ try:
+ if not self.dry_run and os.path.exists(f):
+ os.rmdir(f)
+ log.info("removing '%s'", f)
+ except IOError:
+ log.warning("unable to remove '%s'", f)
+
+ else:
+ try:
+ if not self.dry_run and os.path.exists(f):
+ os.remove(f)
+ log.info("removing '%s'", f)
+ except IOError:
+ log.warning("unable to remove '%s'", f)