Skip to content

Commit

Permalink
first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
amcmahon-rh committed Oct 17, 2024
1 parent ef4cbcf commit 73f3938
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions src/pubtools/_pulp/tasks/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ def add_args(self):

self.parser.add_argument(
"--repo",
help="remove content from these comma-seperated repositories ",
help="remove content from these comma-seperated repositories",
type=str,
action=SplitAndExtend,
split_on=",",
)

self.parser.add_argument(
"--all-repos",
help="remove content from all repos it belongs to. "
"If --repo is used, this behaviour will not run.",
action="store_true"
)

self.parser.add_argument(
"--advisory",
help="remove packages and modules in these comma-separated advisories",
Expand Down Expand Up @@ -130,8 +137,13 @@ def run(self):
if not (self.args.file or self.args.advisory):
self.fail("One of --file or --advisory is required")

if self.args.file and not self.args.repo:
self.fail("Repository names in --repo is required")
if self.args.repos and self.args.all_repos:
LOG.warning("Both --repos and --all_repos have been used. "
"Defaulting to the repos specified with --repo.")
self.args.all_repos = False

if self.args.file and not (self.args.repo or self.args.all_repos):
self.fail("Repository names in --repo or --all_repos is required")

if not signing_keys and self.args.allow_unsigned:
signing_keys = [None]
Expand Down Expand Up @@ -564,26 +576,35 @@ def map_to_repo(self, units, repos, unit_attr):
repo_map = {}
unit_map = {}
repos = sorted(repos)

for unit in sorted(units):
unit_name = getattr(unit, unit_attr)
unit_map.setdefault(unit_name, RemoveUnitItem(unit=unit, repos=[]))
for repo in repos:
if repo not in unit.repository_memberships:
LOG.warning(
"%s is not present in %s",
unit_name,
repo,
)
else:
if repos:
for unit in sorted(units):
unit_name = getattr(unit, unit_attr)
unit_map.setdefault(unit_name, RemoveUnitItem(unit=unit, repos=[]))
for repo in repos:
if repo not in unit.repository_memberships:
LOG.warning(
"%s is not present in %s",
unit_name,
repo,
)
else:
repo_map.setdefault(repo, []).append(unit)
unit_map.get(unit_name).repos.append(repo)

missing = set(repos) - set(repo_map.keys())
if missing:
missing = ", ".join(sorted(list(missing)))
LOG.warning("No units to remove from %s", missing)
else:
for unit in sorted(units):
unit_name = getattr(unit, unit_attr)
unit_map.setdefault(unit_name, RemoveUnitItem(unit=unit, repos=[]))
for repo in unit.repository_memberships:
if re.match("all-rpm-content-.*", repo):
continue
repo_map.setdefault(repo, []).append(unit)
unit_map.get(unit_name).repos.append(repo)

missing = set(repos) - set(repo_map.keys())
if missing:
missing = ", ".join(sorted(list(missing)))
LOG.warning("No units to remove from %s", missing)

return repo_map, unit_map

@step("Unassociate RPMs")
Expand Down

0 comments on commit 73f3938

Please sign in to comment.