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:
deeplow 2023-06-23 06:46:55 +01:00
parent e2accc2da1
commit 95cef8cf0a
No known key found for this signature in database
GPG key ID: 577982871529A52A
4 changed files with 21 additions and 12 deletions

View file

@ -377,12 +377,16 @@ async def main() -> int:
try:
await converter.convert()
error_code = 0 # Success!
except (RuntimeError, TimeoutError, ValueError) as e:
converter.update_progress(str(e), error=True)
return 1
else:
return 0 # Success!
error_code = 1
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__":
sys.exit(asyncio.run(main()))

View file

@ -10,6 +10,8 @@ from ..util import replace_control_chars
log = logging.getLogger(__name__)
MAX_CONVERSION_LOG_CHARS = 150 * 50 # up to ~150 lines of 50 characters
class IsolationProvider(ABC):
"""

View file

@ -7,17 +7,13 @@ import platform
import shlex
import shutil
import subprocess
import sys
import tempfile
from typing import Any, Callable, List, Optional, Tuple
from ..document import Document
from ..util import (
get_resource_path,
get_subprocess_startupinfo,
get_tmp_dir,
replace_control_chars,
)
from .base import IsolationProvider
from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir
from .base import MAX_CONVERSION_LOG_CHARS, IsolationProvider
# Define startupinfo for subprocesses
if platform.system() == "Windows":
@ -288,6 +284,14 @@ class Container(IsolationProvider):
f"ENABLE_TIMEOUTS={self.enable_timeouts}",
]
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:
log.error("documents-to-pixels failed")
else:

View file

@ -22,14 +22,13 @@ log = logging.getLogger(__name__)
from ..conversion.common import running_on_qubes
from ..conversion.pixels_to_pdf import PixelsToPDF
from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir
from .base import MAX_CONVERSION_LOG_CHARS
CONVERTED_FILE_PATH = (
# FIXME won't work for parallel conversions (see #454)
"/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:
"""Read bytes from stdout."""