From 2561d07695cdc72c06d0440869510a4b42ec54dd Mon Sep 17 00:00:00 2001 From: "Samuel Hierholzer (Adfinis AG)" Date: Thu, 27 Jun 2024 15:16:44 +0200 Subject: [PATCH 1/3] fix: Don't fail if a to-be archived publish has wrong snapshots --- pyaptly/publish.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pyaptly/publish.py b/pyaptly/publish.py index 8f914af..f64f9f6 100644 --- a/pyaptly/publish.py +++ b/pyaptly/publish.py @@ -85,6 +85,9 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False) return cmd publish_fullname = "%s %s" % (publish_name, publish_config["distribution"]) + # This line might fail if no publish has been created yet + # TODO: add clag --create to create publishes when they haven't been created yet + # TODO: Fail gracefully and show an error when there is no existing publish current_snapshots = state_reader.state_reader().publish_map()[publish_fullname] if "snapshots" in publish_config: snapshots_config = publish_config["snapshots"] @@ -129,11 +132,13 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False) continue prefix_to_search = re.sub("%T$", "", snap["name"]) - current_snapshot = [ - snap_name - for snap_name in sorted(current_snapshots, key=lambda x: -len(x)) - if snap_name.startswith(prefix_to_search) - ][0] + current_snapshot = None + for snap_name in sorted(current_snapshots, key=lambda x: -len(x)): + if snap_name.startswith(prefix_to_search): + current_snapshot = snap_name + break + if current_snapshot is None: + lg.warn("Snapshot %s doesn't exist on to-be archived publish %s." % (snap["name"], publish_fullname)) snapshot.clone_snapshot(current_snapshot, archive).execute() From 0bd799fb1da0d037df3b329c8ca1a9d5d88e678e Mon Sep 17 00:00:00 2001 From: "Samuel Hierholzer (Adfinis AG)" Date: Wed, 24 Jul 2024 10:23:01 +0200 Subject: [PATCH 2/3] fix: only archive snapshot if possible --- pyaptly/publish.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyaptly/publish.py b/pyaptly/publish.py index f64f9f6..c79a2cf 100644 --- a/pyaptly/publish.py +++ b/pyaptly/publish.py @@ -139,8 +139,8 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False) break if current_snapshot is None: lg.warn("Snapshot %s doesn't exist on to-be archived publish %s." % (snap["name"], publish_fullname)) - - snapshot.clone_snapshot(current_snapshot, archive).execute() + else: + snapshot.clone_snapshot(current_snapshot, archive).execute() publish_cmd.append("switch") options.append("-component=%s" % ",".join(components)) From 8045a6643db03cead38540d1c060ff647fdd9eb6 Mon Sep 17 00:00:00 2001 From: "Samuel Hierholzer (Adfinis AG)" Date: Wed, 24 Jul 2024 10:23:23 +0200 Subject: [PATCH 3/3] fix: Properly fail if publish hasn't been created yet --- pyaptly/publish.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyaptly/publish.py b/pyaptly/publish.py index c79a2cf..bb18a83 100644 --- a/pyaptly/publish.py +++ b/pyaptly/publish.py @@ -85,10 +85,12 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False) return cmd publish_fullname = "%s %s" % (publish_name, publish_config["distribution"]) - # This line might fail if no publish has been created yet - # TODO: add clag --create to create publishes when they haven't been created yet + # TODO: add flag --create to create publishes when they haven't been created yet # TODO: Fail gracefully and show an error when there is no existing publish - current_snapshots = state_reader.state_reader().publish_map()[publish_fullname] + try: + current_snapshots = state_reader.state_reader().publish_map()[publish_fullname] + except KeyError as e: + util.exit_with_error("The publish hasn't been created yet: " + e) if "snapshots" in publish_config: snapshots_config = publish_config["snapshots"] new_snapshots = [