Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repomanage): Add new option --oldonly #453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/repomanage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ The following options set what packages are displayed. These options are mutuall
``--old``
Show older packages (for a package or a stream show all versions except the newest one).

``--oldonly``
Show older packages (same as --old, but exclude the newest packages even when it's included in the older stream versions).

``--new``
Show newest packages.

Expand Down
46 changes: 43 additions & 3 deletions plugins/repomanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def configure(self):
def run(self):
if self.opts.new and self.opts.old:
raise dnf.exceptions.Error(_("Pass either --old or --new, not both!"))
if self.opts.new and self.opts.oldonly:
raise dnf.exceptions.Error(_("Pass either --oldonly or --new, not both!"))
if self.opts.old and self.opts.oldonly:
raise dnf.exceptions.Error(_("Pass either --old or --oldonly, not both!"))
if not self.opts.old and not self.opts.oldonly:
self.opts.new = True

verfile = {}
pkgdict = {}
Expand Down Expand Up @@ -118,8 +124,7 @@ def run(self):
# modular packages
keepnum_latest_stream_artifacts = set()

# if new
if not self.opts.old:
if self.opts.new:
# regular packages
for (n, a) in pkgdict.keys():
evrlist = pkgdict[(n, a)]
Expand All @@ -141,7 +146,6 @@ def run(self):
for stream in streams_by_version[i]:
keepnum_latest_stream_artifacts.update(set(stream.getArtifacts()))


if self.opts.old:
# regular packages
for (n, a) in pkgdict.keys():
Expand All @@ -164,6 +168,40 @@ def run(self):
for stream in streams_by_version[i]:
keepnum_latest_stream_artifacts.update(set(stream.getArtifacts()))

if self.opts.oldonly:
# regular packages
for (n, a) in pkgdict.keys():
evrlist = pkgdict[(n, a)]

oldevrs = evrlist[:-keepnum]

for package in oldevrs:
nevra = self._package_to_nevra(package)
for fpkg in verfile[nevra]:
outputpackages.append(fpkg)

# modular packages
keepnum_newer_stream_artifacts = set()

for streams_by_version in module_dict.values():
sorted_stream_versions = sorted(streams_by_version.keys())

new_sorted_stream_versions = sorted_stream_versions[-keepnum:]

for i in new_sorted_stream_versions:
for stream in streams_by_version[i]:
keepnum_newer_stream_artifacts.update(set(stream.getArtifacts()))

for streams_by_version in module_dict.values():
sorted_stream_versions = sorted(streams_by_version.keys())

old_sorted_stream_versions = sorted_stream_versions[:-keepnum]

for i in old_sorted_stream_versions:
for stream in streams_by_version[i]:
for artifact in stream.getArtifacts():
if artifact not in keepnum_newer_stream_artifacts:
keepnum_latest_stream_artifacts.add(artifact)

modular_packages = [self._package_to_path(x) for x in query.filter(pkg__eq=query.filter(nevra_strict=keepnum_latest_stream_artifacts)).available()]
outputpackages = outputpackages + modular_packages
Expand All @@ -178,6 +216,8 @@ def run(self):
def set_argparser(parser):
parser.add_argument("-o", "--old", action="store_true",
help=_("Print the older packages"))
parser.add_argument("-O", "--oldonly", action="store_true",
help=_("Print the older packages. Exclude the newest packages."))
parser.add_argument("-n", "--new", action="store_true",
help=_("Print the newest packages"))
parser.add_argument("-s", "--space", action="store_true",
Expand Down