mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Containers: capture conversion logs
Store the conversion log to a file (captured-output.txt) in the container and when in development mode, have its output displayed on the terminal output.
This commit is contained in:
parent
e2accc2da1
commit
95cef8cf0a
4 changed files with 21 additions and 12 deletions
|
@ -377,12 +377,16 @@ async def main() -> int:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await converter.convert()
|
await converter.convert()
|
||||||
|
error_code = 0 # Success!
|
||||||
except (RuntimeError, TimeoutError, ValueError) as e:
|
except (RuntimeError, TimeoutError, ValueError) as e:
|
||||||
converter.update_progress(str(e), error=True)
|
converter.update_progress(str(e), error=True)
|
||||||
return 1
|
error_code = 1
|
||||||
else:
|
|
||||||
return 0 # Success!
|
|
||||||
|
|
||||||
|
if not running_on_qubes():
|
||||||
|
# Write debug information (containers version)
|
||||||
|
with open("/tmp/dangerzone/captured_output.txt", "wb") as container_log:
|
||||||
|
container_log.write(converter.captured_output)
|
||||||
|
return error_code
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(asyncio.run(main()))
|
sys.exit(asyncio.run(main()))
|
||||||
|
|
|
@ -10,6 +10,8 @@ from ..util import replace_control_chars
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
MAX_CONVERSION_LOG_CHARS = 150 * 50 # up to ~150 lines of 50 characters
|
||||||
|
|
||||||
|
|
||||||
class IsolationProvider(ABC):
|
class IsolationProvider(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -7,17 +7,13 @@ import platform
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import Any, Callable, List, Optional, Tuple
|
from typing import Any, Callable, List, Optional, Tuple
|
||||||
|
|
||||||
from ..document import Document
|
from ..document import Document
|
||||||
from ..util import (
|
from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir
|
||||||
get_resource_path,
|
from .base import MAX_CONVERSION_LOG_CHARS, IsolationProvider
|
||||||
get_subprocess_startupinfo,
|
|
||||||
get_tmp_dir,
|
|
||||||
replace_control_chars,
|
|
||||||
)
|
|
||||||
from .base import IsolationProvider
|
|
||||||
|
|
||||||
# Define startupinfo for subprocesses
|
# Define startupinfo for subprocesses
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
@ -288,6 +284,14 @@ class Container(IsolationProvider):
|
||||||
f"ENABLE_TIMEOUTS={self.enable_timeouts}",
|
f"ENABLE_TIMEOUTS={self.enable_timeouts}",
|
||||||
]
|
]
|
||||||
ret = self.exec_container(document, command, extra_args)
|
ret = self.exec_container(document, command, extra_args)
|
||||||
|
|
||||||
|
if getattr(sys, "dangerzone_dev", False):
|
||||||
|
log_path = pixel_dir / "captured_output.txt"
|
||||||
|
with open(log_path, "r", encoding="ascii", errors="replace") as f:
|
||||||
|
log.info(
|
||||||
|
f"Conversion output (doc to pixels):\n{f.read(MAX_CONVERSION_LOG_CHARS)}"
|
||||||
|
)
|
||||||
|
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
log.error("documents-to-pixels failed")
|
log.error("documents-to-pixels failed")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -22,14 +22,13 @@ log = logging.getLogger(__name__)
|
||||||
from ..conversion.common import running_on_qubes
|
from ..conversion.common import running_on_qubes
|
||||||
from ..conversion.pixels_to_pdf import PixelsToPDF
|
from ..conversion.pixels_to_pdf import PixelsToPDF
|
||||||
from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir
|
from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir
|
||||||
|
from .base import MAX_CONVERSION_LOG_CHARS
|
||||||
|
|
||||||
CONVERTED_FILE_PATH = (
|
CONVERTED_FILE_PATH = (
|
||||||
# FIXME won't work for parallel conversions (see #454)
|
# FIXME won't work for parallel conversions (see #454)
|
||||||
"/tmp/safe-output-compressed.pdf"
|
"/tmp/safe-output-compressed.pdf"
|
||||||
)
|
)
|
||||||
|
|
||||||
MAX_CONVERSION_LOG_CHARS = 150 * 50 # up to ~150 lines of 50 characters
|
|
||||||
|
|
||||||
|
|
||||||
def read_bytes(p: subprocess.Popen, buff_size: int) -> bytes:
|
def read_bytes(p: subprocess.Popen, buff_size: int) -> bytes:
|
||||||
"""Read bytes from stdout."""
|
"""Read bytes from stdout."""
|
||||||
|
|
Loading…
Reference in a new issue