Skip to content
Snippets Groups Projects
Commit 6d433f63 authored by Lorenz Hüdepohl's avatar Lorenz Hüdepohl
Browse files

Add logic to remove old maintainers

Otherwise this failed with a rather cryptic 404, on needed manual
intervention
parent b12ab103
No related branches found
No related tags found
No related merge requests found
Pipeline #206442 failed
...@@ -652,25 +652,35 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False, dry_run= ...@@ -652,25 +652,35 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False, dry_run=
if len(build) > 0: if len(build) > 0:
build[-1].tail = "\n " build[-1].tail = "\n "
# This is potential place to remove old maintainers that
# otherwise cause issues when updating the pkg meta
old_users = set()
for user in root.iterfind("person"):
if user.attrib["userid"] in old_users:
root.remove(user)
new_pkg_meta = ElementTree.tostring(root, encoding=osc.core.ET_ENCODING) new_pkg_meta = ElementTree.tostring(root, encoding=osc.core.ET_ENCODING)
if pkg_meta != new_pkg_meta: if pkg_meta != new_pkg_meta:
print("Updating repositories for", package) print("Updating repositories for", package)
if dry_run: if dry_run:
print("osc meta pkg {0} {1} -F - <<EOF\n{2}\nEOF\n".format(project, package, new_pkg_meta)) print("osc meta pkg {0} {1} -F - <<EOF\n{2}\nEOF\n".format(project, package, new_pkg_meta))
else: else:
while True:
try: try:
osc.core.edit_meta("pkg", (project, package), data=new_pkg_meta, apiurl=api_url) osc.core.edit_meta("pkg", (project, package), data=new_pkg_meta, apiurl=api_url)
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
# Was this error due to a now invalid userid? If so, remove it!
data = e.data.decode("utf-8")
if "Couldn't find User with login" in data:
summary = ElementTree.fromstring(e.data.decode("utf-8")).find("summary").text
old_user = summary.split(" = ")[1]
removed = False
for user in root.iterfind("person[@userid='" + old_user + "']"):
print("-> Removing invalid userid '{0}' from list of maintainers...".format(old_user))
root.remove(user)
removed = True
if removed:
new_pkg_meta = ElementTree.tostring(root, encoding=osc.core.ET_ENCODING)
# Try again with new user list
continue
# Other error:
print("ERROR:", e.code, e.url, file=sys.stderr) print("ERROR:", e.code, e.url, file=sys.stderr)
e.osc_msg = 'Error editing meta of package {0} in project {1}'.format(package, project) e.osc_msg = 'Error editing meta of package {0} in project {1}'.format(package, project)
raise raise
break
elif dry_run: elif dry_run:
print("Would not do anything, package meta would be unchanged") print("Would not do anything, package meta would be unchanged")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment