mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
move to util: get_subprocess_startupinfo
This commit is contained in:
parent
2d6826afa9
commit
272281a29e
5 changed files with 26 additions and 34 deletions
|
@ -13,7 +13,7 @@ import colorama
|
|||
|
||||
from .container import convert
|
||||
from .settings import Settings
|
||||
from .util import get_resource_path
|
||||
from .util import get_resource_path, get_subprocess_startupinfo
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -50,14 +50,6 @@ class GlobalCommon(object):
|
|||
raise Exception(f"{runtime_name} is not installed")
|
||||
return runtime
|
||||
|
||||
def get_subprocess_startupinfo(self): # type: ignore [no-untyped-def]
|
||||
if platform.system() == "Windows":
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
return startupinfo
|
||||
else:
|
||||
return None
|
||||
|
||||
def install_container(self) -> Optional[bool]:
|
||||
"""
|
||||
Make sure the podman container is installed. Linux only.
|
||||
|
@ -71,7 +63,7 @@ class GlobalCommon(object):
|
|||
p = subprocess.Popen(
|
||||
[self.get_container_runtime(), "load"],
|
||||
stdin=subprocess.PIPE,
|
||||
startupinfo=self.get_subprocess_startupinfo(),
|
||||
startupinfo=get_subprocess_startupinfo(),
|
||||
)
|
||||
|
||||
chunk_size = 10240
|
||||
|
@ -113,7 +105,7 @@ class GlobalCommon(object):
|
|||
self.container_name,
|
||||
],
|
||||
text=True,
|
||||
startupinfo=self.get_subprocess_startupinfo(),
|
||||
startupinfo=get_subprocess_startupinfo(),
|
||||
)
|
||||
found_image_id = found_image_id.strip()
|
||||
|
||||
|
@ -127,7 +119,7 @@ class GlobalCommon(object):
|
|||
try:
|
||||
subprocess.check_output(
|
||||
[self.get_container_runtime(), "rmi", "--force", found_image_id],
|
||||
startupinfo=self.get_subprocess_startupinfo(),
|
||||
startupinfo=get_subprocess_startupinfo(),
|
||||
)
|
||||
except:
|
||||
log.warning("Couldn't delete old container image, so leaving it there")
|
||||
|
|
|
@ -13,7 +13,7 @@ from PySide2 import QtCore, QtGui, QtWidgets
|
|||
from ..common import Common
|
||||
from ..container import convert
|
||||
from ..global_common import GlobalCommon
|
||||
from ..util import get_resource_path
|
||||
from ..util import get_resource_path, get_subprocess_startupinfo
|
||||
from .common import GuiCommon
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -171,7 +171,7 @@ class WaitingWidget(QtWidgets.QWidget):
|
|||
[container_runtime, "image", "ls"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
startupinfo=self.global_common.get_subprocess_startupinfo(),
|
||||
startupinfo=get_subprocess_startupinfo(),
|
||||
) as p:
|
||||
p.communicate()
|
||||
if p.returncode != 0:
|
||||
|
@ -626,7 +626,7 @@ class ConvertWidget(QtWidgets.QWidget):
|
|||
subprocess.Popen(
|
||||
f'explorer.exe /select,"{dest_filename_windows}"',
|
||||
shell=True,
|
||||
startupinfo=self.global_common.get_subprocess_startupinfo(),
|
||||
startupinfo=get_subprocess_startupinfo(),
|
||||
)
|
||||
|
||||
# Open
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import pathlib
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -34,3 +35,12 @@ def get_version() -> str:
|
|||
# it doesn't need to know the version
|
||||
version = "unknown"
|
||||
return version
|
||||
|
||||
|
||||
def get_subprocess_startupinfo(): # type: ignore [no-untyped-def]
|
||||
if platform.system() == "Windows":
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
return startupinfo
|
||||
else:
|
||||
return None
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import os
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import dangerzone.global_common
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def global_common():
|
||||
return dangerzone.global_common.GlobalCommon()
|
||||
|
||||
|
||||
class TestGlobalCommon:
|
||||
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows-specific")
|
||||
def test_get_subprocess_startupinfo(self, global_common):
|
||||
startupinfo = global_common.get_subprocess_startupinfo()
|
||||
self.assertIsInstance(startupinfo, subprocess.STARTUPINFO)
|
|
@ -1,5 +1,8 @@
|
|||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import dangerzone.util as util
|
||||
|
||||
VERSION_FILE_NAME = "version.txt"
|
||||
|
@ -11,3 +14,9 @@ def test_get_resource_path():
|
|||
assert share_dir.samefile(
|
||||
resource_path
|
||||
), f"{share_dir} is not the same file as {resource_path}"
|
||||
|
||||
|
||||
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows-specific")
|
||||
def test_get_subprocess_startupinfo():
|
||||
startupinfo = util.get_subprocess_startupinfo()
|
||||
self.assertIsInstance(startupinfo, subprocess.STARTUPINFO)
|
||||
|
|
Loading…
Reference in a new issue