mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
Make GlobalCommon completely static except for __init__
This commit is contained in:
parent
4978ab78bd
commit
2da6ce02c8
5 changed files with 21 additions and 13 deletions
|
@ -23,7 +23,7 @@ def cli_main(output_filename, ocr_lang, filename):
|
||||||
global_common = GlobalCommon()
|
global_common = GlobalCommon()
|
||||||
common = Common()
|
common = Common()
|
||||||
|
|
||||||
global_common.display_banner()
|
GlobalCommon.display_banner()
|
||||||
|
|
||||||
# Validate filename
|
# Validate filename
|
||||||
valid = True
|
valid = True
|
||||||
|
@ -85,7 +85,7 @@ def cli_main(output_filename, ocr_lang, filename):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Ensure container is installed
|
# Ensure container is installed
|
||||||
global_common.install_container()
|
GlobalCommon.install_container()
|
||||||
|
|
||||||
# Convert the document
|
# Convert the document
|
||||||
print_header("Converting document to safe PDF")
|
print_header("Converting document to safe PDF")
|
||||||
|
|
|
@ -42,7 +42,7 @@ def convert(input_filename, output_filename, ocr_lang, stdout_callback):
|
||||||
else:
|
else:
|
||||||
ocr = "0"
|
ocr = "0"
|
||||||
|
|
||||||
dz_tmp = os.path.join(appdirs.user_config_dir("dangerzone"), "tmp")
|
dz_tmp = os.path.join(dzutil.APPDATA_PATH, "tmp")
|
||||||
os.makedirs(dz_tmp, exist_ok=True)
|
os.makedirs(dz_tmp, exist_ok=True)
|
||||||
|
|
||||||
tmpdir = tempfile.TemporaryDirectory(dir=dz_tmp)
|
tmpdir = tempfile.TemporaryDirectory(dir=dz_tmp)
|
||||||
|
|
|
@ -14,15 +14,14 @@ class GlobalCommon(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.version = dzutil.VERSION
|
|
||||||
|
|
||||||
# Initialize terminal colors
|
# Initialize terminal colors
|
||||||
colorama.init(autoreset=True)
|
colorama.init(autoreset=True)
|
||||||
|
|
||||||
# Load settings
|
# Load settings
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
|
|
||||||
def display_banner(self):
|
@staticmethod
|
||||||
|
def display_banner():
|
||||||
"""
|
"""
|
||||||
Raw ASCII art example:
|
Raw ASCII art example:
|
||||||
╭──────────────────────────╮
|
╭──────────────────────────╮
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import sys
|
|
||||||
|
|
||||||
from PySide6 import QtCore
|
from PySide6 import QtCore
|
||||||
from PySide6.QtCore import QEvent
|
from PySide6.QtCore import QEvent
|
||||||
from PySide6.QtWidgets import QApplication
|
from PySide6.QtWidgets import QApplication
|
||||||
|
|
||||||
|
import dangerzone.util as dzutil
|
||||||
|
|
||||||
|
|
||||||
class Application(QApplication):
|
class Application(QApplication):
|
||||||
document_selected = QtCore.Signal(str)
|
document_selected = QtCore.Signal(str)
|
||||||
|
@ -19,7 +19,7 @@ class Application(QApplication):
|
||||||
# In macOS, handle the file open event
|
# In macOS, handle the file open event
|
||||||
if event.type() == QtCore.QEvent.FileOpen:
|
if event.type() == QtCore.QEvent.FileOpen:
|
||||||
# Skip file open events in dev mode
|
# Skip file open events in dev mode
|
||||||
if not hasattr(sys, "dangerzone_dev"):
|
if not dzutil.dev_mode():
|
||||||
self.document_selected.emit(event.file())
|
self.document_selected.emit(event.file())
|
||||||
return True
|
return True
|
||||||
elif event.type() == QtCore.QEvent.ApplicationActivate:
|
elif event.type() == QtCore.QEvent.ApplicationActivate:
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import appdirs
|
import appdirs
|
||||||
|
|
||||||
# If a general-purpose function doesn't depend on anything else in the dangerzone package, then it belongs here.
|
# If a general-purpose function or constant doesn't depend on anything else in the dangerzone package,
|
||||||
|
# then it belongs here.
|
||||||
|
|
||||||
|
SYSTEM = platform.system()
|
||||||
|
|
||||||
|
|
||||||
|
def dev_mode() -> bool:
|
||||||
|
return hasattr(sys, "dangerzone_dev")
|
||||||
|
|
||||||
|
|
||||||
def get_resource_path(filename):
|
def get_resource_path(filename):
|
||||||
|
@ -35,7 +45,7 @@ def get_resource_path(filename):
|
||||||
|
|
||||||
|
|
||||||
def get_subprocess_startupinfo():
|
def get_subprocess_startupinfo():
|
||||||
if platform.system() == "Windows":
|
if SYSTEM == "Windows":
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
return startupinfo
|
return startupinfo
|
||||||
|
@ -44,7 +54,7 @@ def get_subprocess_startupinfo():
|
||||||
|
|
||||||
|
|
||||||
def _get_version() -> str:
|
def _get_version() -> str:
|
||||||
"""Dangerzone version number. Prefer dangerzone.VERSION to this function."""
|
"""Dangerzone version number. Prefer VERSION to this function."""
|
||||||
try:
|
try:
|
||||||
with open(get_resource_path("version.txt")) as f:
|
with open(get_resource_path("version.txt")) as f:
|
||||||
version = f.read().strip()
|
version = f.read().strip()
|
||||||
|
@ -57,7 +67,6 @@ def _get_version() -> str:
|
||||||
|
|
||||||
VERSION = _get_version()
|
VERSION = _get_version()
|
||||||
APPDATA_PATH = appdirs.user_config_dir("dangerzone")
|
APPDATA_PATH = appdirs.user_config_dir("dangerzone")
|
||||||
SYSTEM = platform.system()
|
|
||||||
CONTAINER_NAME = "dangerzone.rocks/dangerzone"
|
CONTAINER_NAME = "dangerzone.rocks/dangerzone"
|
||||||
CONTAINER_COMMAND = "podman" if SYSTEM == "Linux" else "docker"
|
CONTAINER_COMMAND = "podman" if SYSTEM == "Linux" else "docker"
|
||||||
CONTAINER_RUNTIME = shutil.which(CONTAINER_COMMAND)
|
CONTAINER_RUNTIME = shutil.which(CONTAINER_COMMAND)
|
||||||
|
|
Loading…
Reference in a new issue