diff --git a/dangerzone/cli.py b/dangerzone/cli.py index 8e07a41..33038e6 100644 --- a/dangerzone/cli.py +++ b/dangerzone/cli.py @@ -92,7 +92,7 @@ def cli_main( exit(1) # Ensure container is installed - container.install_container() + container.install() # Convert the document print_header("Converting document to safe PDF") diff --git a/dangerzone/container.py b/dangerzone/container.py index 0eb67ea..07cbb06 100644 --- a/dangerzone/container.py +++ b/dangerzone/container.py @@ -28,10 +28,11 @@ container_name = "dangerzone.rocks/dangerzone" class NoContainerTechException(Exception): - pass + def __init__(self, container_tech: str) -> None: + super().__init__(f"{container_tech} is not installed") -def get_container_tech() -> str: +def get_runtime_name() -> str: if platform.system() == "Linux": runtime_name = "podman" else: @@ -40,14 +41,15 @@ def get_container_tech() -> str: return runtime_name -def get_container_runtime() -> str: - runtime = shutil.which(get_container_tech()) +def get_runtime() -> str: + container_tech = get_runtime_name() + runtime = shutil.which(container_tech) if runtime is None: - raise NoContainerTechException(f"{runtime_name} is not installed") + raise NoContainerTechException(container_tech) return runtime -def install_container() -> Optional[bool]: +def install() -> Optional[bool]: """ Make sure the podman container is installed. Linux only. """ @@ -58,7 +60,7 @@ def install_container() -> Optional[bool]: log.info("Installing Dangerzone container image...") p = subprocess.Popen( - [get_container_runtime(), "load"], + [get_runtime(), "load"], stdin=subprocess.PIPE, startupinfo=get_subprocess_startupinfo(), ) @@ -95,7 +97,7 @@ def is_container_installed() -> bool: installed = False found_image_id = subprocess.check_output( [ - get_container_runtime(), + get_runtime(), "image", "list", "--format", @@ -116,7 +118,7 @@ def is_container_installed() -> bool: try: subprocess.check_output( - [get_container_runtime(), "rmi", "--force", found_image_id], + [get_runtime(), "rmi", "--force", found_image_id], startupinfo=get_subprocess_startupinfo(), ) except: @@ -151,9 +153,9 @@ def exec_container( extra_args: List[str] = [], stdout_callback: Callable[[str], None] = None, ) -> int: - container_runtime = container.get_container_runtime() + container_runtime = get_runtime() - if get_container_tech() == "podman": + if get_runtime_name() == "podman": platform_args = [] security_args = ["--security-opt", "no-new-privileges"] security_args += ["--userns", "keep-id"] diff --git a/dangerzone/gui/main_window.py b/dangerzone/gui/main_window.py index 12cf066..b8487a8 100644 --- a/dangerzone/gui/main_window.py +++ b/dangerzone/gui/main_window.py @@ -104,7 +104,7 @@ class InstallContainerThread(QtCore.QThread): self.global_common = global_common def run(self) -> None: - container.install_container() + container.install() self.finished.emit() @@ -157,7 +157,7 @@ class WaitingWidget(QtWidgets.QWidget): state: Optional[str] = None try: - container_runtime = container.get_container_runtime() + container_runtime = container.get_runtime() except container.NoContainerTechException: log.error("Docker is not installed") state = "not_installed"