diff --git a/mpcdf_remove.py b/mpcdf_remove.py index 8a79d952f06825a0d029a41315b48a1d20925cfb..c2b2c8a7cc02c865f2678618059401fa1836c80c 100644 --- a/mpcdf_remove.py +++ b/mpcdf_remove.py @@ -1,20 +1,17 @@ -from __future__ import print_function - import os import osc import osc.conf import osc.core import osc.cmdln +import urllib - +@osc.cmdln.option('--ignore-missing', action="store_true", + help="Ignore if package is missing in some/all sub-projects") def do_mpcdf_remove(self, subcmd, opts, *args): - """${cmd_name}: Removes a package from all sub-projects of software: + """mpcdf_remove: Removes a package from all sub-projects of software: Usage: - osc ${cmd_name} [PACKAGE] - - ${cmd_option_list} - + osc mpcdf_remove [PACKAGE] """ if len(args) == 0: @@ -34,8 +31,15 @@ def do_mpcdf_remove(self, subcmd, opts, *args): if p.startswith("software:") and not (p == "software:dist" or p == "software:images")] for project in projects: - print("Removing from", project) - osc.core.delete_package(api_url, project, package) + print("Removing from", project, "...") + try: + osc.core.delete_package(api_url, project, package) + except urllib.error.HTTPError as e: + if e.code == 404 and opts.ignore_missing: + print(" .. not present there!") + continue + else: + raise print("\nThe package still exists in 'software', you can undo what you did with\n\n" " osc mcpdf_push\n\n"