WIP: Work with HWPX files

This commit is contained in:
Alex Pyrgiotis 2024-12-19 18:55:36 +02:00
parent e1b1f9432e
commit 40242ba51b
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
3 changed files with 8 additions and 14 deletions

View file

@ -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 && \

View file

@ -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

View file

@ -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": {