mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
Check if conversion code runs on Qubes
Add a way to check if the code runs (or should run) on Qubes. Refs #451
This commit is contained in:
parent
a0d1a68302
commit
9410da762c
2 changed files with 18 additions and 8 deletions
|
@ -17,6 +17,14 @@ TIMEOUT_PER_MB: float = 30 # (seconds)
|
||||||
TIMEOUT_MIN: float = 60 # (seconds)
|
TIMEOUT_MIN: float = 60 # (seconds)
|
||||||
|
|
||||||
|
|
||||||
|
def running_on_qubes() -> bool:
|
||||||
|
# https://www.qubes-os.org/faq/#what-is-the-canonical-way-to-detect-qubes-vm
|
||||||
|
if os.environ.get("DZ_USE_CONTAINERS", "0") == "0":
|
||||||
|
return os.path.exists("/usr/share/qubes/marker-vm")
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def read_stream(
|
async def read_stream(
|
||||||
sr: asyncio.StreamReader, callback: Optional[Callable] = None
|
sr: asyncio.StreamReader, callback: Optional[Callable] = None
|
||||||
) -> bytes:
|
) -> bytes:
|
||||||
|
@ -126,6 +134,7 @@ class DangerzoneConverter:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_progress(self, text: str, *, error: bool = False) -> None:
|
def update_progress(self, text: str, *, error: bool = False) -> None:
|
||||||
|
if not running_on_qubes():
|
||||||
print(
|
print(
|
||||||
json.dumps(
|
json.dumps(
|
||||||
{"error": error, "text": text, "percentage": int(self.percentage)}
|
{"error": error, "text": text, "percentage": int(self.percentage)}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .common import DangerzoneConverter, run_command
|
from .common import DangerzoneConverter, run_command, running_on_qubes
|
||||||
|
|
||||||
|
|
||||||
class PixelsToPDF(DangerzoneConverter):
|
class PixelsToPDF(DangerzoneConverter):
|
||||||
|
@ -146,6 +146,7 @@ class PixelsToPDF(DangerzoneConverter):
|
||||||
self.update_progress("Safe PDF created")
|
self.update_progress("Safe PDF created")
|
||||||
|
|
||||||
# Move converted files into /safezone
|
# Move converted files into /safezone
|
||||||
|
if not running_on_qubes():
|
||||||
shutil.move("/tmp/safe-output.pdf", "/safezone")
|
shutil.move("/tmp/safe-output.pdf", "/safezone")
|
||||||
shutil.move("/tmp/safe-output-compressed.pdf", "/safezone")
|
shutil.move("/tmp/safe-output-compressed.pdf", "/safezone")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue