From b12ab103e731862d1c4ed28bd6edc6ad41a7eeb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lorenz=20H=C3=BCdepohl?= <dev@stellardeath.org>
Date: Tue, 28 May 2024 11:02:31 +0200
Subject: [PATCH] Fix handling of missing packages in mpcdf_remove

---
 mpcdf_remove.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/mpcdf_remove.py b/mpcdf_remove.py
index 8a79d95..c2b2c8a 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"
-- 
GitLab