From 40242ba51b761e036749eada3d41fe0db7fa3533 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Thu, 19 Dec 2024 18:55:36 +0200 Subject: [PATCH] WIP: Work with HWPX files --- Dockerfile | 3 ++- dangerzone/conversion/common.py | 17 ++++------------- dangerzone/conversion/doc_to_pixels.py | 2 ++ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index d1760f9..4c4e412 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,8 @@ RUN mkdir /libreoffice_ext && cd libreoffice_ext \ && H2ORESTART_FILENAME=h2orestart.oxt \ && wget https://github.com/ebandal/H2Orestart/releases/download/$H2ORESTART_VERSION/$H2ORESTART_FILENAME \ && echo "$H2ORESTART_CHECKSUM $H2ORESTART_FILENAME" | sha256sum -c \ - && install -dm777 "/usr/lib/libreoffice/share/extensions/" + && install -dm777 "/usr/lib/libreoffice/share/extensions/" \ + && rm /root/.wget-hsts RUN mkdir -p /opt/dangerzone/dangerzone && \ touch /opt/dangerzone/dangerzone/__init__.py && \ diff --git a/dangerzone/conversion/common.py b/dangerzone/conversion/common.py index 2ff10ec..9bbfe8b 100644 --- a/dangerzone/conversion/common.py +++ b/dangerzone/conversion/common.py @@ -8,15 +8,6 @@ DEFAULT_DPI = 150 # Pixels per inch INT_BYTES = 2 -class CommandError(RuntimeError): - - def __init__(self, msg, stdout, stderr): - self.stdout = stdout - self.stderr = stderr - msg += f"\n====\nCommand output:\n{stdout}\n=====\nCommand stderr:\n{stderr}\n======" - super().__init__(msg) - - def running_on_qubes() -> bool: # https://www.qubes-os.org/faq/#what-is-the-canonical-way-to-detect-qubes-vm return os.path.exists("/usr/share/qubes/marker-vm") @@ -105,7 +96,7 @@ class DangerzoneConverter: Run a command using asyncio.subprocess, consume its standard streams, and return its output in bytes. - :raises CommandError: if the process returns a non-zero exit status + :raises RuntimeError: if the process returns a non-zero exit status """ # Start the provided command, and return a handle. The command will run in the # background. @@ -134,15 +125,15 @@ class DangerzoneConverter: # Wait until the command has finished. Then, verify that the command # has completed successfully. In any other case, raise an exception. ret = await proc.wait() + if ret != 0: + raise RuntimeError(error_message) + # Wait until the tasks that consume the command's standard streams have exited as # well, and return their output. stdout = await stdout_task stderr = await stderr_task - if ret != 0: - raise CommandError(error_message, stdout, stderr) - return (stdout, stderr) @abstractmethod diff --git a/dangerzone/conversion/doc_to_pixels.py b/dangerzone/conversion/doc_to_pixels.py index 6737607..a7a7776 100644 --- a/dangerzone/conversion/doc_to_pixels.py +++ b/dangerzone/conversion/doc_to_pixels.py @@ -129,6 +129,8 @@ class DocumentToPixels(DangerzoneConverter): # At least .odt, .docx, .odg, .odp, .ods, and .pptx "application/zip": { "type": "libreoffice", + # NOTE: Older `file` command cannot detect hwpx files properly. + "libreoffice_ext": "h2orestart.oxt", }, # At least .doc, .docx, .odg, .odp, .odt, .pdf, .ppt, .pptx, .xls, and .xlsx "application/octet-stream": {