mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +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)
|
||||
|
||||
|
||||
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(
|
||||
sr: asyncio.StreamReader, callback: Optional[Callable] = None
|
||||
) -> bytes:
|
||||
|
@ -126,6 +134,7 @@ class DangerzoneConverter:
|
|||
pass
|
||||
|
||||
def update_progress(self, text: str, *, error: bool = False) -> None:
|
||||
if not running_on_qubes():
|
||||
print(
|
||||
json.dumps(
|
||||
{"error": error, "text": text, "percentage": int(self.percentage)}
|
||||
|
|
|
@ -12,7 +12,7 @@ import os
|
|||
import shutil
|
||||
import sys
|
||||
|
||||
from .common import DangerzoneConverter, run_command
|
||||
from .common import DangerzoneConverter, run_command, running_on_qubes
|
||||
|
||||
|
||||
class PixelsToPDF(DangerzoneConverter):
|
||||
|
@ -146,6 +146,7 @@ class PixelsToPDF(DangerzoneConverter):
|
|||
self.update_progress("Safe PDF created")
|
||||
|
||||
# Move converted files into /safezone
|
||||
if not running_on_qubes():
|
||||
shutil.move("/tmp/safe-output.pdf", "/safezone")
|
||||
shutil.move("/tmp/safe-output-compressed.pdf", "/safezone")
|
||||
|
||||
|
|
Loading…
Reference in a new issue