diff --git a/pyaptly/publish.py b/pyaptly/publish.py index 8f914af..bb18a83 100644 --- a/pyaptly/publish.py +++ b/pyaptly/publish.py @@ -85,7 +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"]) - current_snapshots = state_reader.state_reader().publish_map()[publish_fullname] + # 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 + 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 = [ @@ -129,13 +134,15 @@ 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] - - snapshot.clone_snapshot(current_snapshot, archive).execute() + 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)) + else: + snapshot.clone_snapshot(current_snapshot, archive).execute() publish_cmd.append("switch") options.append("-component=%s" % ",".join(components))