From cfcd3180111b24b7fa8129d1e7dbb26d3299d7fd Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Tue, 27 Sep 2022 08:32:32 -0400 Subject: [PATCH] Call gs directly when compressing PDFs. I.e. avoid unnecessary bash invocation. --- undercover/fallback.py | 4 +++- undercover/pdf_builder.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/undercover/fallback.py b/undercover/fallback.py index 3bb4aa7..079b42e 100644 --- a/undercover/fallback.py +++ b/undercover/fallback.py @@ -1,6 +1,7 @@ import types import json + class MockConnection: mock_cursor = types.SimpleNamespace() mock_cursor.execute = lambda *a: () @@ -21,7 +22,8 @@ class MockConnection: class MockCreator: - def create(self, data=None, *a): + @staticmethod + def create(data=None, *a): print(json.JSONEncoder(indent=2).encode(data)) result = types.SimpleNamespace() result.status_code = 200 diff --git a/undercover/pdf_builder.py b/undercover/pdf_builder.py index 96a79d9..3f9dce2 100644 --- a/undercover/pdf_builder.py +++ b/undercover/pdf_builder.py @@ -73,10 +73,19 @@ class CLData: if result.returncode == 0: print(build_text + "[SUCCESS]") - compress_com = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -sOutputFile=outputs/" + unique_id + ".compressed.pdf outputs/" + unique_id + ".pdf" result = subprocess.run( - ['bash', '-c', compress_com], + [ + 'gs' + '-sDEVICE=pdfwrite' + '-dCompatibilityLevel=1.5' + '-dNOPAUSE' + '-dQUIET' + '-dBATCH' + '-dPrinted=false' + '-sOutputFile=outputs/' + unique_id + '.compressed.pdf', + 'outputs/' + unique_id + '.pdf' + ], stdout=subprocess.PIPE, text=True )