]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/command/rotate.py
1 from distutils
.util
import convert_path
2 from distutils
import log
3 from distutils
.errors
import DistutilsOptionError
7 from setuptools
import Command
10 class rotate(Command
):
11 """Delete older distributions"""
13 description
= "delete older distributions, keeping N newest files"
15 ('match=', 'm', "patterns to match (required)"),
16 ('dist-dir=', 'd', "directory where the distributions are"),
17 ('keep=', 'k', "number of matching distributions to keep"),
22 def initialize_options(self
):
27 def finalize_options(self
):
28 if self
.match
is None:
29 raise DistutilsOptionError(
30 "Must specify one or more (comma-separated) match patterns "
31 "(e.g. '.zip' or '.egg')"
34 raise DistutilsOptionError("Must specify number of files to keep")
36 self
.keep
= int(self
.keep
)
37 except ValueError as e
:
38 raise DistutilsOptionError("--keep must be an integer") from e
39 if isinstance(self
.match
, str):
41 convert_path(p
.strip()) for p
in self
.match
.split(',')
43 self
.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
46 self
.run_command("egg_info")
49 for pattern
in self
.match
:
50 pattern
= self
.distribution
.get_name() + '*' + pattern
51 files
= glob(os
.path
.join(self
.dist_dir
, pattern
))
52 files
= [(os
.path
.getmtime(f
), f
) for f
in files
]
56 log
.info("%d file(s) matching %s", len(files
), pattern
)
57 files
= files
[self
.keep
:]
59 log
.info("Deleting %s", f
)