diff --git a/mpcdf_push.py b/mpcdf_push.py index 6b746dce08aa8adab1b3e98b9c67025f506e6110..d93ec24646f299a1756f3f36f6ed25aaa23cbc3f 100644 --- a/mpcdf_push.py +++ b/mpcdf_push.py @@ -64,26 +64,37 @@ def do_mpcdf_push(self, subcmd, opts, *args): project_attributes = ["MPCDF:compiler_modules", "MPCDF:cuda_modules", "MPCDF:mpi_modules"] package_attributes = ["MPCDF:enable_repositories"] + project_attributes + try: + root = ElementTree.fromstringlist(osc.core.show_package_meta(api_url, to_project, package)) + existing_maintainers = {e.get("userid") for e in root.findall("./person[@role='maintainer']")} + except osc.core.HTTPError as e: + if e.code == 404: + existing_maintainers = set() + else: + raise e + req_id = osc.core.create_submit_request(api_url, from_project, package, dst_project=to_project, message="Update {0} from {1}".format(package, from_project) if not opts.message else opts.message) print("Submitted package {0} to {1} in request {2}".format(package, to_project, req_id)) if not opts.batch: - print(" PLEASE review the request by 'osc request show {0} --diff', or in the web interface".format(req_id)) - print(" Do you want to accept the request right away? [y/N] ", end="") + print("\nPLEASE review the request by 'osc request show {0} --diff', or in the web interface\n".format(req_id)) + print("Do you want to accept the request right away? [y/N] ", end="") response = input().lower() if response == "y": result = osc.core.change_request_state(api_url, req_id, 'accepted', "Accepted on the command line via 'osc mpcdf_push'") - print(" Accepting request {0}:".format(req_id), result) + print(" Accepting request {0}:".format(req_id), result) - print("Adding you to the list of maintainers for this package (for informational purposes only)") user = osc.conf.get_apiurl_usr(api_url) - r = osc.core.Request() - r.add_action("add_role", tgt_project=to_project, tgt_package=package, person_name=user, person_role="maintainer") - r.description = "Add user {0} as maintainer due to 'osc mpcdf_push'".format(user) - r.create(api_url) - if response == "y": - result = osc.core.change_request_state(api_url, r.reqid, 'accepted', "Accepted on the command line via 'osc mpcdf_push'") - print(" Accepting request {0}:".format(r.reqid), result) + if user not in existing_maintainers: + print("Adding you to the list of maintainers for this package") + r = osc.core.Request() + r.add_action("add_role", tgt_project=to_project, tgt_package=package, person_name=user, person_role="maintainer") + r.description = "Add user {0} as maintainer due to 'osc mpcdf_push'".format(user) + r.create(api_url) + if response == "y": + result = osc.core.change_request_state(api_url, r.reqid, 'accepted', "Accepted on the command line via 'osc mpcdf_push'") + print(" Accepting request {0}:".format(r.reqid), result) + print() # Give the system some time, sadly there is no transactional guarantee time.sleep(2)