mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +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 .container import convert
|
||||||
from .settings import Settings
|
from .settings import Settings
|
||||||
from .util import get_resource_path
|
from .util import get_resource_path, get_subprocess_startupinfo
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -50,14 +50,6 @@ class GlobalCommon(object):
|
||||||
raise Exception(f"{runtime_name} is not installed")
|
raise Exception(f"{runtime_name} is not installed")
|
||||||
return runtime
|
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]:
|
def install_container(self) -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
Make sure the podman container is installed. Linux only.
|
Make sure the podman container is installed. Linux only.
|
||||||
|
@ -71,7 +63,7 @@ class GlobalCommon(object):
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[self.get_container_runtime(), "load"],
|
[self.get_container_runtime(), "load"],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
startupinfo=self.get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
|
|
||||||
chunk_size = 10240
|
chunk_size = 10240
|
||||||
|
@ -113,7 +105,7 @@ class GlobalCommon(object):
|
||||||
self.container_name,
|
self.container_name,
|
||||||
],
|
],
|
||||||
text=True,
|
text=True,
|
||||||
startupinfo=self.get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
found_image_id = found_image_id.strip()
|
found_image_id = found_image_id.strip()
|
||||||
|
|
||||||
|
@ -127,7 +119,7 @@ class GlobalCommon(object):
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
[self.get_container_runtime(), "rmi", "--force", found_image_id],
|
[self.get_container_runtime(), "rmi", "--force", found_image_id],
|
||||||
startupinfo=self.get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
log.warning("Couldn't delete old container image, so leaving it there")
|
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 ..common import Common
|
||||||
from ..container import convert
|
from ..container import convert
|
||||||
from ..global_common import GlobalCommon
|
from ..global_common import GlobalCommon
|
||||||
from ..util import get_resource_path
|
from ..util import get_resource_path, get_subprocess_startupinfo
|
||||||
from .common import GuiCommon
|
from .common import GuiCommon
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -171,7 +171,7 @@ class WaitingWidget(QtWidgets.QWidget):
|
||||||
[container_runtime, "image", "ls"],
|
[container_runtime, "image", "ls"],
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
startupinfo=self.global_common.get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
) as p:
|
) as p:
|
||||||
p.communicate()
|
p.communicate()
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
|
@ -626,7 +626,7 @@ class ConvertWidget(QtWidgets.QWidget):
|
||||||
subprocess.Popen(
|
subprocess.Popen(
|
||||||
f'explorer.exe /select,"{dest_filename_windows}"',
|
f'explorer.exe /select,"{dest_filename_windows}"',
|
||||||
shell=True,
|
shell=True,
|
||||||
startupinfo=self.global_common.get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Open
|
# Open
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import pathlib
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,3 +35,12 @@ def get_version() -> str:
|
||||||
# it doesn't need to know the version
|
# it doesn't need to know the version
|
||||||
version = "unknown"
|
version = "unknown"
|
||||||
return version
|
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
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
import dangerzone.util as util
|
import dangerzone.util as util
|
||||||
|
|
||||||
VERSION_FILE_NAME = "version.txt"
|
VERSION_FILE_NAME = "version.txt"
|
||||||
|
@ -11,3 +14,9 @@ def test_get_resource_path():
|
||||||
assert share_dir.samefile(
|
assert share_dir.samefile(
|
||||||
resource_path
|
resource_path
|
||||||
), f"{share_dir} is not the same file as {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