mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
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:
parent
6202c0dba9
commit
57e455bbf1
3 changed files with 16 additions and 14 deletions
|
@ -92,7 +92,7 @@ def cli_main(
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Ensure container is installed
|
# Ensure container is installed
|
||||||
container.install_container()
|
container.install()
|
||||||
|
|
||||||
# Convert the document
|
# Convert the document
|
||||||
print_header("Converting document to safe PDF")
|
print_header("Converting document to safe PDF")
|
||||||
|
|
|
@ -28,10 +28,11 @@ container_name = "dangerzone.rocks/dangerzone"
|
||||||
|
|
||||||
|
|
||||||
class NoContainerTechException(Exception):
|
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":
|
if platform.system() == "Linux":
|
||||||
runtime_name = "podman"
|
runtime_name = "podman"
|
||||||
else:
|
else:
|
||||||
|
@ -40,14 +41,15 @@ def get_container_tech() -> str:
|
||||||
return runtime_name
|
return runtime_name
|
||||||
|
|
||||||
|
|
||||||
def get_container_runtime() -> str:
|
def get_runtime() -> str:
|
||||||
runtime = shutil.which(get_container_tech())
|
container_tech = get_runtime_name()
|
||||||
|
runtime = shutil.which(container_tech)
|
||||||
if runtime is None:
|
if runtime is None:
|
||||||
raise NoContainerTechException(f"{runtime_name} is not installed")
|
raise NoContainerTechException(container_tech)
|
||||||
return runtime
|
return runtime
|
||||||
|
|
||||||
|
|
||||||
def install_container() -> Optional[bool]:
|
def install() -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
Make sure the podman container is installed. Linux only.
|
Make sure the podman container is installed. Linux only.
|
||||||
"""
|
"""
|
||||||
|
@ -58,7 +60,7 @@ def install_container() -> Optional[bool]:
|
||||||
log.info("Installing Dangerzone container image...")
|
log.info("Installing Dangerzone container image...")
|
||||||
|
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[get_container_runtime(), "load"],
|
[get_runtime(), "load"],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
startupinfo=get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
|
@ -95,7 +97,7 @@ def is_container_installed() -> bool:
|
||||||
installed = False
|
installed = False
|
||||||
found_image_id = subprocess.check_output(
|
found_image_id = subprocess.check_output(
|
||||||
[
|
[
|
||||||
get_container_runtime(),
|
get_runtime(),
|
||||||
"image",
|
"image",
|
||||||
"list",
|
"list",
|
||||||
"--format",
|
"--format",
|
||||||
|
@ -116,7 +118,7 @@ def is_container_installed() -> bool:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
[get_container_runtime(), "rmi", "--force", found_image_id],
|
[get_runtime(), "rmi", "--force", found_image_id],
|
||||||
startupinfo=get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
|
@ -151,9 +153,9 @@ def exec_container(
|
||||||
extra_args: List[str] = [],
|
extra_args: List[str] = [],
|
||||||
stdout_callback: Callable[[str], None] = None,
|
stdout_callback: Callable[[str], None] = None,
|
||||||
) -> int:
|
) -> int:
|
||||||
container_runtime = container.get_container_runtime()
|
container_runtime = get_runtime()
|
||||||
|
|
||||||
if get_container_tech() == "podman":
|
if get_runtime_name() == "podman":
|
||||||
platform_args = []
|
platform_args = []
|
||||||
security_args = ["--security-opt", "no-new-privileges"]
|
security_args = ["--security-opt", "no-new-privileges"]
|
||||||
security_args += ["--userns", "keep-id"]
|
security_args += ["--userns", "keep-id"]
|
||||||
|
|
|
@ -104,7 +104,7 @@ class InstallContainerThread(QtCore.QThread):
|
||||||
self.global_common = global_common
|
self.global_common = global_common
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
container.install_container()
|
container.install()
|
||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ class WaitingWidget(QtWidgets.QWidget):
|
||||||
state: Optional[str] = None
|
state: Optional[str] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
container_runtime = container.get_container_runtime()
|
container_runtime = container.get_runtime()
|
||||||
except container.NoContainerTechException:
|
except container.NoContainerTechException:
|
||||||
log.error("Docker is not installed")
|
log.error("Docker is not installed")
|
||||||
state = "not_installed"
|
state = "not_installed"
|
||||||
|
|
Loading…
Reference in a new issue