remove "container" from container.py method names

Container-related methods recently moved to container.py no longer
need to have 'container' in their name as they are within the
container scope already.

Additonally it made it awkward to call from another module:

    from .. import container
    container.get_container_runtime()
This commit is contained in:
deeplow 2022-09-15 11:16:41 +01:00
parent 6202c0dba9
commit 57e455bbf1
No known key found for this signature in database
GPG key ID: 577982871529A52A
3 changed files with 16 additions and 14 deletions

View file

@ -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")

View file

@ -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"]

View file

@ -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"