|
31 | 31 | VERSION = "0.1.0" |
32 | 32 | ZYPPER_PID_FILE = "/run/zypp.pid" |
33 | 33 | VALID_CMD = ["dup", "run", "rollback"] |
34 | | -VALID_OPT = ["--reboot", "--apply", "--shell", "--continue", "--no-verify", "--interactive", "--debug", "--help", "--version"] |
| 34 | +VALID_OPT = ["--reboot", "--apply", "--shell", "--continue", "--no-verify", \ |
| 35 | + "--interactive", "--debug", "--help", "--version"] |
35 | 36 |
|
36 | 37 | # Command help/usage info |
37 | 38 | help_text = """ |
|
59 | 60 |
|
60 | 61 | ################################ |
61 | 62 |
|
62 | | -# Function to query user for yes or no |
63 | | -def query_yes_no(question, default=None): |
64 | | - valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} |
65 | | - if default is None: |
66 | | - prompt = " [y/n]: " |
67 | | - elif default == "yes": |
68 | | - prompt = " [Y/n]: " |
69 | | - elif default == "no": |
70 | | - prompt = " [y/N]: " |
71 | | - else: |
72 | | - raise ValueError(f"Invalid default answer: {default!r}") |
73 | | - while True: |
74 | | - sys.stdout.write(question + prompt) |
75 | | - choice = input().lower() |
76 | | - if default is not None and choice == "": |
77 | | - return valid[default] |
78 | | - elif choice in valid: |
79 | | - return valid[choice] |
80 | | - else: |
81 | | - sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n") |
82 | | - |
83 | 63 | # Function to get output and exit code of shell command |
84 | 64 | def shell_exec(command): |
85 | 65 | res = subprocess.run(command, shell=True, capture_output=True, encoding="utf8", errors="replace") |
@@ -287,10 +267,16 @@ def sigint_handler(signum, frame): |
287 | 267 | active_snap, default_snap = get_snaps(snapper_root_config) |
288 | 268 | logging.debug(f"Active snapshot number: {active_snap}, Default snapshot number: {default_snap}") |
289 | 269 | base_snap = active_snap |
290 | | - if CONTINUE: |
| 270 | + if CONTINUE or APPLY: |
291 | 271 | base_snap = default_snap |
292 | 272 | if continue_num: |
293 | 273 | base_snap = continue_num |
| 274 | + # warn user when rebasing from old snapshot |
| 275 | + # thus losing changes to snapshots made in the interim |
| 276 | + if not continue_num and base_snap != default_snap: |
| 277 | + logging.warn(f"This snapshot is being created from a different base ({base_snap}) " \ |
| 278 | + f"than the previous default snapshot ({default_snap}) and does not " \ |
| 279 | + f"contain the changes from the latter.") |
294 | 280 | # create new read-write snapshot to perform atomic update in |
295 | 281 | out, ret = shell_exec(f"snapper -c {snapper_root_config} create -c number " \ |
296 | 282 | f"-d 'Atomic update of #{base_snap}' " \ |
@@ -409,12 +395,15 @@ def sigint_handler(signum, frame): |
409 | 395 |
|
410 | 396 | # Handle command: rollback |
411 | 397 | elif COMMAND == "rollback": |
412 | | - warn_opts = ["--apply", "--reboot"] |
413 | | - if warn_opts in OPT: |
414 | | - logging.warn(f"Options {', '.join(warn_opts)!r} do not apply to rollback command") |
| 398 | + invalid_opts = OPT.copy() |
| 399 | + invalid_opts.remove("--debug") |
| 400 | + if invalid_opts: |
| 401 | + logging.warn(f"Options {', '.join(invalid_opts)!r} do not apply to rollback command") |
415 | 402 | if rollback_num: |
| 403 | + logging.info(f"Rolling back to snapshot {rollback_num}") |
416 | 404 | os.system(f"snapper rollback {rollback_num}") |
417 | 405 | else: |
| 406 | + logging.info("Rolling back to currently booted snapshot") |
418 | 407 | os.system("snapper rollback") |
419 | 408 |
|
420 | 409 | # If we're here, remind user to reboot |
|
0 commit comments