aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command/rotate.py
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2005-07-08 04:48:20 +0000
committerPJ Eby <distutils-sig@python.org>2005-07-08 04:48:20 +0000
commit592269afeaa4f96bddbaa8b6fbe8dddcea2445a4 (patch)
tree5fe55dced4503fdbb70eb5ec692d86003c444fe3 /setuptools/command/rotate.py
parent56fcb8fdcc377acf0d74430a3d2d4dbffe306d44 (diff)
downloadexternal_python_setuptools-592269afeaa4f96bddbaa8b6fbe8dddcea2445a4.tar.gz
external_python_setuptools-592269afeaa4f96bddbaa8b6fbe8dddcea2445a4.tar.bz2
external_python_setuptools-592269afeaa4f96bddbaa8b6fbe8dddcea2445a4.zip
* Added "rotate" command to delete old distribution files, given a set of
patterns to match and the number of files to keep. (Keeps the most recently-modified distribution files matching each pattern.) * Added "saveopts" command that saves all command-line options for the current invocation to the local, global, or per-user configuration file. Useful for setting defaults without having to hand-edit a configuration file. * Added a "setopt" command that sets a single option in a specified distutils configuration file. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041093
Diffstat (limited to 'setuptools/command/rotate.py')
-rwxr-xr-xsetuptools/command/rotate.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py
new file mode 100755
index 00000000..f7330436
--- /dev/null
+++ b/setuptools/command/rotate.py
@@ -0,0 +1,82 @@
+import distutils, os
+from setuptools import Command
+from distutils.util import convert_path
+from distutils import log
+from distutils.errors import *
+
+class rotate(Command):
+ """Delete older distributions"""
+
+ description = "Delete older distributions, keeping N newest files"
+ user_options = [
+ ('match=', 'm', "patterns to match (required)"),
+ ('dist-dir=', 'd', "directory where the distributions are"),
+ ('keep=', 'k', "number of matching distributions to keep"),
+ ]
+
+ boolean_options = []
+
+ def initialize_options(self):
+ self.match = None
+ self.dist_dir = None
+ self.keep = None
+
+ def finalize_options(self):
+ if self.match is None:
+ raise DistutilsOptionError(
+ "Must specify one or more (comma-separated) match patterns "
+ "(e.g. '.zip' or '.egg')"
+ )
+ if self.keep is None:
+ raise DistutilsOptionError("Must specify number of files to keep")
+ try:
+ self.keep = int(self.keep)
+ except ValueError:
+ raise DistutilsOptionError("--keep must be an integer")
+ if isinstance(self.match, basestring):
+ self.match = [
+ convert_path(p.strip()) for p in self.match.split(',')
+ ]
+ self.set_undefined_options('bdist',('dist_dir', 'dist_dir'))
+
+ def run(self):
+ self.run_command("egg_info")
+ from glob import glob
+ for pattern in self.match:
+ pattern = self.distribution.get_name()+'*'+pattern
+ files = glob(os.path.join(self.dist_dir,pattern))
+ files = [(os.path.getmtime(f),f) for f in files]
+ files.sort()
+ files.reverse()
+
+ log.info("%d file(s) matching %s", len(files), pattern)
+ files = files[self.keep:]
+ for (t,f) in files:
+ log.info("Deleting %s", f)
+ if not self.dry_run:
+ os.unlink(f)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+