mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Add --custom-container option, to run a container built locally instead of requiring download from dockerhub
This commit is contained in:
parent
8845ac6440
commit
d519303150
4 changed files with 45 additions and 17 deletions
|
@ -6,6 +6,7 @@ import platform
|
||||||
import click
|
import click
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from .global_common import GlobalCommon
|
from .global_common import GlobalCommon
|
||||||
from .main_window import MainWindow
|
from .main_window import MainWindow
|
||||||
|
@ -39,12 +40,10 @@ class Application(QtWidgets.QApplication):
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@click.option("--custom-container") # Use this container instead of flmcode/dangerzone
|
||||||
@click.argument("filename", required=False)
|
@click.argument("filename", required=False)
|
||||||
def main(filename):
|
def main(custom_container, filename):
|
||||||
print(f"dangerzone {dangerzone_version}")
|
click.echo(f"dangerzone {dangerzone_version}")
|
||||||
|
|
||||||
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
||||||
|
|
||||||
# Create the Qt app
|
# Create the Qt app
|
||||||
app = Application()
|
app = Application()
|
||||||
|
@ -53,20 +52,35 @@ def main(filename):
|
||||||
# GlobalCommon object
|
# GlobalCommon object
|
||||||
global_common = GlobalCommon(app)
|
global_common = GlobalCommon(app)
|
||||||
|
|
||||||
|
if custom_container:
|
||||||
|
# Do we have this container?
|
||||||
|
output = subprocess.check_output(
|
||||||
|
[global_common.container_runtime, "image", "ls", custom_container],
|
||||||
|
startupinfo=global_common.get_subprocess_startupinfo(),
|
||||||
|
)
|
||||||
|
if custom_container.encode() not in output:
|
||||||
|
click.echo(f"Container '{container}' not found")
|
||||||
|
return
|
||||||
|
|
||||||
|
global_common.custom_container = custom_container
|
||||||
|
|
||||||
|
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
|
||||||
# If we're using Linux and docker, see if we need to add the user to the docker group
|
# If we're using Linux and docker, see if we need to add the user to the docker group
|
||||||
if (
|
if (
|
||||||
platform.system() == "Linux"
|
platform.system() == "Linux"
|
||||||
and global_common.container_runtime == "/usr/bin/docker"
|
and global_common.container_runtime == "/usr/bin/docker"
|
||||||
):
|
):
|
||||||
if not global_common.ensure_user_is_in_docker_group():
|
if not global_common.ensure_user_is_in_docker_group():
|
||||||
print("Failed to add user to docker group")
|
click.echo("Failed to add user to docker group")
|
||||||
return
|
return
|
||||||
|
|
||||||
# See if we need to install Docker...
|
# See if we need to install Docker...
|
||||||
if (platform.system() == "Darwin" or platform.system() == "Windows") and (
|
if (platform.system() == "Darwin" or platform.system() == "Windows") and (
|
||||||
not is_docker_installed(global_common) or not is_docker_ready(global_common)
|
not is_docker_installed(global_common) or not is_docker_ready(global_common)
|
||||||
):
|
):
|
||||||
print("Docker is either not installed or not running")
|
click.echo("Docker is either not installed or not running")
|
||||||
docker_installer = DockerInstaller(global_common)
|
docker_installer = DockerInstaller(global_common)
|
||||||
docker_installer.start()
|
docker_installer.start()
|
||||||
return
|
return
|
||||||
|
@ -97,10 +111,10 @@ def main(filename):
|
||||||
try:
|
try:
|
||||||
open(filename, "rb")
|
open(filename, "rb")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("File not found")
|
click.echo("File not found")
|
||||||
return False
|
return False
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
print("Permission denied")
|
click.echo("Permission denied")
|
||||||
return False
|
return False
|
||||||
window.common.document_filename = filename
|
window.common.document_filename = filename
|
||||||
window.doc_selection_widget.document_selected.emit()
|
window.doc_selection_widget.document_selected.emit()
|
||||||
|
|
|
@ -73,6 +73,9 @@ class GlobalCommon(object):
|
||||||
else:
|
else:
|
||||||
self.container_runtime = "/usr/bin/docker"
|
self.container_runtime = "/usr/bin/docker"
|
||||||
|
|
||||||
|
# In case we have a custom container
|
||||||
|
self.custom_container = None
|
||||||
|
|
||||||
# Preload list of PDF viewers on computer
|
# Preload list of PDF viewers on computer
|
||||||
self.pdf_viewers = self._find_pdf_viewers()
|
self.pdf_viewers = self._find_pdf_viewers()
|
||||||
|
|
||||||
|
@ -243,6 +246,12 @@ class GlobalCommon(object):
|
||||||
# Load settings
|
# Load settings
|
||||||
self.settings = Settings(self)
|
self.settings = Settings(self)
|
||||||
|
|
||||||
|
def get_container_name(self):
|
||||||
|
if self.custom_container:
|
||||||
|
return self.custom_container
|
||||||
|
else:
|
||||||
|
return "flmcode/dangerzone"
|
||||||
|
|
||||||
def get_resource_path(self, filename):
|
def get_resource_path(self, filename):
|
||||||
if getattr(sys, "dangerzone_dev", False):
|
if getattr(sys, "dangerzone_dev", False):
|
||||||
# Look for resources directory relative to python file
|
# Look for resources directory relative to python file
|
||||||
|
|
|
@ -135,13 +135,18 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
self.update_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
self.update_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# Is update containers required?
|
# Is update containers required?
|
||||||
output = subprocess.check_output(
|
if self.global_common.custom_container:
|
||||||
[self.global_common.container_runtime, "image", "ls", "flmcode/dangerzone"],
|
self.update_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
startupinfo=self.global_common.get_subprocess_startupinfo(),
|
|
||||||
)
|
|
||||||
if b"dangerzone" not in output:
|
|
||||||
self.update_checkbox.setCheckState(QtCore.Qt.Checked)
|
|
||||||
self.update_checkbox.setEnabled(False)
|
self.update_checkbox.setEnabled(False)
|
||||||
|
self.update_checkbox.hide()
|
||||||
|
else:
|
||||||
|
output = subprocess.check_output(
|
||||||
|
[self.global_common.container_runtime, "image", "ls", self.global_common.get_container_name()],
|
||||||
|
startupinfo=self.global_common.get_subprocess_startupinfo(),
|
||||||
|
)
|
||||||
|
if b"dangerzone" not in output:
|
||||||
|
self.update_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
self.update_checkbox.setEnabled(False)
|
||||||
|
|
||||||
def update_ui(self):
|
def update_ui(self):
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
|
|
@ -85,7 +85,7 @@ class ConvertToPixels(TaskBase):
|
||||||
f"{self.common.document_filename}:/tmp/input_file",
|
f"{self.common.document_filename}:/tmp/input_file",
|
||||||
"-v",
|
"-v",
|
||||||
f"{self.common.pixel_dir.name}:/dangerzone",
|
f"{self.common.pixel_dir.name}:/dangerzone",
|
||||||
"flmcode/dangerzone",
|
self.global_common.get_container_name(),
|
||||||
"document-to-pixels",
|
"document-to-pixels",
|
||||||
]
|
]
|
||||||
returncode, output = self.exec_container(args)
|
returncode, output = self.exec_container(args)
|
||||||
|
@ -194,7 +194,7 @@ class ConvertToPDF(TaskBase):
|
||||||
f"{self.common.safe_dir.name}:/safezone",
|
f"{self.common.safe_dir.name}:/safezone",
|
||||||
]
|
]
|
||||||
+ envs
|
+ envs
|
||||||
+ ["flmcode/dangerzone", "pixels-to-pdf",]
|
+ [self.global_common.get_container_name(), "pixels-to-pdf",]
|
||||||
)
|
)
|
||||||
returncode, output = self.exec_container(args)
|
returncode, output = self.exec_container(args)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue