Skip to content

Commit

Permalink
feat(repomanage): Add new option --oldonly
Browse files Browse the repository at this point in the history
= changelog =
msg:           repomanage: Add new option --oldonly
type:          enhancement
resolves:      https://bugzilla.redhat.com/show_bug.cgi?id=2034736
resolves:      https://bugzilla.redhat.com/show_bug.cgi?id=2058676
  • Loading branch information
mmatsuya authored and kontura committed Apr 13, 2022
1 parent 7417e3e commit bfc1f7f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
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

0 comments on commit bfc1f7f

Please sign in to comment.