From 57667a96bea81006170ef7cf079b2258448fab1b Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Wed, 2 Apr 2025 14:55:54 +0300 Subject: [PATCH] Add a way to unset the container runtime Add a way to set the container runtime that Dangerzone uses back to the default. --- dangerzone/cli.py | 20 +++++++++++++++----- dangerzone/settings.py | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/dangerzone/cli.py b/dangerzone/cli.py index ca5b644..1353995 100644 --- a/dangerzone/cli.py +++ b/dangerzone/cli.py @@ -52,7 +52,11 @@ def print_header(s: str) -> None: @click.option( "--set-container-runtime", required=False, - help="The path to the container runtime you want to set in the settings", + help=( + "The name or full path of the container runtime you want Dangerzone to use." + " You can specify the value 'default' if you want to take back your choice, and" + " let Dangerzone use the default runtime for this OS" + ), ) @click.version_option(version=get_version(), message="%(version)s") @errors.handle_document_errors @@ -69,10 +73,16 @@ def cli_main( display_banner() if set_container_runtime: settings = Settings() - container_runtime = settings.set_custom_runtime( - set_container_runtime, autosave=True - ) - click.echo(f"Set the settings container_runtime to {container_runtime}") + if set_container_runtime == "default": + settings.unset_custom_runtime() + click.echo( + "Instructed Dangerzone to use the default container runtime for this OS" + ) + else: + container_runtime = settings.set_custom_runtime( + set_container_runtime, autosave=True + ) + click.echo(f"Set the settings container_runtime to {container_runtime}") sys.exit(0) elif not filenames: raise click.UsageError("Missing argument 'FILENAMES...'") diff --git a/dangerzone/settings.py b/dangerzone/settings.py index a95917b..0e30896 100644 --- a/dangerzone/settings.py +++ b/dangerzone/settings.py @@ -52,6 +52,10 @@ class Settings: self.save() return container_runtime + def unset_custom_runtime(self) -> None: + self.settings.pop("container_runtime") + self.save() + def get(self, key: str) -> Any: return self.settings[key]