diff --git a/mpcdf_common.py b/mpcdf_common.py index 1d2970c26bddf6877ba50eda0a5f154f1815cc8c..a24955bc659edf6c0e140be74e5089bf25c79721 100644 --- a/mpcdf_common.py +++ b/mpcdf_common.py @@ -652,25 +652,35 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False, dry_run= if len(build) > 0: 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) if pkg_meta != new_pkg_meta: print("Updating repositories for", package) if dry_run: print("osc meta pkg {0} {1} -F - <<EOF\n{2}\nEOF\n".format(project, package, new_pkg_meta)) else: - try: - osc.core.edit_meta("pkg", (project, package), data=new_pkg_meta, apiurl=api_url) - except urllib.error.HTTPError as e: - print("ERROR:", e.code, e.url, file=sys.stderr) - e.osc_msg = 'Error editing meta of package {0} in project {1}'.format(package, project) - raise + while True: + try: + osc.core.edit_meta("pkg", (project, package), data=new_pkg_meta, apiurl=api_url) + 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) + e.osc_msg = 'Error editing meta of package {0} in project {1}'.format(package, project) + raise + break elif dry_run: print("Would not do anything, package meta would be unchanged")