From 592269afeaa4f96bddbaa8b6fbe8dddcea2445a4 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 04:48:20 +0000 Subject: * 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 --- setuptools/command/rotate.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 setuptools/command/rotate.py (limited to 'setuptools/command/rotate.py') 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) + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1 From 5eec64a05733986216d87dbdc52c78615ac3cda3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 05:11:20 +0000 Subject: Fix a couple of command descriptions. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041095 --- setuptools/command/rotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index f7330436..11b6eae8 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -7,7 +7,7 @@ from distutils.errors import * class rotate(Command): """Delete older distributions""" - description = "Delete older distributions, keeping N newest files" + description = "delete older distributions, keeping N newest files" user_options = [ ('match=', 'm', "patterns to match (required)"), ('dist-dir=', 'd', "directory where the distributions are"), -- cgit v1.2.1 From 58a658b26d1c95b31d02050dcccd648d2e4ce27b Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 20 Jun 2011 22:55:16 +0100 Subject: Changes to support 2.x and 3.x in the same codebase. --HG-- branch : distribute extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071 --- setuptools/command/rotate.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 11b6eae8..b10acfb4 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -1,5 +1,6 @@ import distutils, os from setuptools import Command +from setuptools.compat import basestring from distutils.util import convert_path from distutils import log from distutils.errors import * -- cgit v1.2.1 From 2394cfef645c1d22de240c0c8b1a9eb918a1f6ee Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 9 Feb 2014 18:51:37 -0500 Subject: Reorganize imports and remove excess whitespace --- setuptools/command/rotate.py | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index b10acfb4..c556aa17 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -1,9 +1,9 @@ -import distutils, os +import os from setuptools import Command from setuptools.compat import basestring from distutils.util import convert_path from distutils import log -from distutils.errors import * +from distutils.errors import DistutilsOptionError class rotate(Command): """Delete older distributions""" @@ -29,7 +29,7 @@ class rotate(Command): "(e.g. '.zip' or '.egg')" ) if self.keep is None: - raise DistutilsOptionError("Must specify number of files to keep") + raise DistutilsOptionError("Must specify number of files to keep") try: self.keep = int(self.keep) except ValueError: @@ -56,28 +56,3 @@ class rotate(Command): log.info("Deleting %s", f) if not self.dry_run: os.unlink(f) - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.1 From 8e3f9d3253d1d0fb820dad4249d5110d017595c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 18 Jun 2014 20:31:05 +0300 Subject: Fixed PEP 8 compliancy of the setuptools.command package --- setuptools/command/rotate.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index c556aa17..1b073620 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -1,18 +1,20 @@ -import os -from setuptools import Command -from setuptools.compat import basestring from distutils.util import convert_path from distutils import log from distutils.errors import DistutilsOptionError +import os + +from setuptools import Command +from setuptools.compat import basestring + class rotate(Command): """Delete older distributions""" description = "delete older distributions, keeping N newest files" user_options = [ - ('match=', 'm', "patterns to match (required)"), + ('match=', 'm', "patterns to match (required)"), ('dist-dir=', 'd', "directory where the distributions are"), - ('keep=', 'k', "number of matching distributions to keep"), + ('keep=', 'k', "number of matching distributions to keep"), ] boolean_options = [] @@ -38,21 +40,22 @@ class rotate(Command): self.match = [ convert_path(p.strip()) for p in self.match.split(',') ] - self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) + 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] + 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: + for (t, f) in files: log.info("Deleting %s", f) if not self.dry_run: os.unlink(f) -- cgit v1.2.1 From b49435397a5094f94678adf3549cc8941aa469b7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 15:06:51 -0400 Subject: Use six for Python 2 compatibility --HG-- branch : feature/issue-229 extra : source : 7b1997ececc5772798ce33a0f8e77387cb55a977 --- setuptools/command/rotate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 1b073620..09eac496 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -3,8 +3,9 @@ from distutils import log from distutils.errors import DistutilsOptionError import os +import six + from setuptools import Command -from setuptools.compat import basestring class rotate(Command): @@ -36,7 +37,7 @@ class rotate(Command): self.keep = int(self.keep) except ValueError: raise DistutilsOptionError("--keep must be an integer") - if isinstance(self.match, basestring): + if isinstance(self.match, six.string_types): self.match = [ convert_path(p.strip()) for p in self.match.split(',') ] -- cgit v1.2.1 From 06872bb0bbbeb953e90bd0941444b0d499056557 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 11:51:01 -0500 Subject: Update vendoring technique to match that used for packaging. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/command/rotate.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 09eac496..1ee1c538 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -3,7 +3,12 @@ from distutils import log from distutils.errors import DistutilsOptionError import os -import six +try: + from setuptools._vendor import six +except ImportError: + # fallback to naturally-installed version; allows system packagers to + # omit vendored packages. + import six from setuptools import Command -- cgit v1.2.1 From 952c1bafda1929c74c737646aa025e6ffad6632e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 16:30:47 -0500 Subject: Modeling after Astropy's technique for bundling libraries, the imports are now much cleaner. Thanks @embray. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/command/rotate.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 1ee1c538..804f962a 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -3,12 +3,7 @@ from distutils import log from distutils.errors import DistutilsOptionError import os -try: - from setuptools._vendor import six -except ImportError: - # fallback to naturally-installed version; allows system packagers to - # omit vendored packages. - import six +from setuptools.extern import six from setuptools import Command -- cgit v1.2.1 From 18b7ab638a52b1dc2899f2e32b33f41d931ce2f4 Mon Sep 17 00:00:00 2001 From: Rick Liu Date: Fri, 15 Apr 2016 12:19:52 -0700 Subject: Handle not-zip-safe egg (folder) deletion in rotate command --- setuptools/command/rotate.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 804f962a..b89353f5 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -2,6 +2,7 @@ from distutils.util import convert_path from distutils import log from distutils.errors import DistutilsOptionError import os +import shutil from setuptools.extern import six @@ -59,4 +60,7 @@ class rotate(Command): for (t, f) in files: log.info("Deleting %s", f) if not self.dry_run: - os.unlink(f) + if os.path.isdir(f): + shutil.rmtree(f) + else: + os.unlink(f) -- cgit v1.2.1 From ff371f18f0076bc63da05334f7e551c1cc29e10d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2017 22:34:28 -0500 Subject: Strip out vendored packages and require them instead. Ref #581. --- setuptools/command/rotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index b89353f5..7ea36e96 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -4,7 +4,7 @@ from distutils.errors import DistutilsOptionError import os import shutil -from setuptools.extern import six +import six from setuptools import Command -- cgit v1.2.1 From 3d0cc355fb5e8012cb8c72f0e25042a5a44f31d6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2017 11:49:51 -0500 Subject: Revert "Merge pull request #933 from pypa/feature/581-depend-not-bundle" This reverts commit 089cdeb489a0fa94d11b7307b54210ef9aa40511, reversing changes made to aaec654d804cb78dbb6391afff721a63f26a71cd. --- setuptools/command/rotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index 7ea36e96..b89353f5 100755 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -4,7 +4,7 @@ from distutils.errors import DistutilsOptionError import os import shutil -import six +from setuptools.extern import six from setuptools import Command -- cgit v1.2.1 From 760e2e1df9c9c9d1fc072e7b6ad9df4c32bfc835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 27 Jul 2018 14:36:34 +0200 Subject: Remove spurious executable permissions --- setuptools/command/rotate.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 setuptools/command/rotate.py (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py old mode 100755 new mode 100644 -- cgit v1.2.1 From a9eb9e73def8ca6c469e59f1b008746e368ad4c1 Mon Sep 17 00:00:00 2001 From: Ram Rachum Date: Tue, 16 Jun 2020 13:31:12 +0300 Subject: Fix exception causes all over the codebase --- setuptools/command/rotate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index b89353f5..e398834f 100644 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -36,8 +36,8 @@ class rotate(Command): raise DistutilsOptionError("Must specify number of files to keep") try: self.keep = int(self.keep) - except ValueError: - raise DistutilsOptionError("--keep must be an integer") + except ValueError as e: + raise DistutilsOptionError("--keep must be an integer") from e if isinstance(self.match, six.string_types): self.match = [ convert_path(p.strip()) for p in self.match.split(',') -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/command/rotate.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'setuptools/command/rotate.py') diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index e398834f..74795ba9 100644 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -4,8 +4,6 @@ from distutils.errors import DistutilsOptionError import os import shutil -from setuptools.extern import six - from setuptools import Command @@ -38,7 +36,7 @@ class rotate(Command): self.keep = int(self.keep) except ValueError as e: raise DistutilsOptionError("--keep must be an integer") from e - if isinstance(self.match, six.string_types): + if isinstance(self.match, str): self.match = [ convert_path(p.strip()) for p in self.match.split(',') ] -- cgit v1.2.1