diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 5673d159a..fdf7b2f6e 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -134,11 +134,19 @@ class Consumer(LoggingMixin): self.log("info", f"Executing pre-consume script {settings.PRE_CONSUME_SCRIPT}") + filepath_arg = os.path.normpath(self.path) + script_env = os.environ.copy() - script_env["DOCUMENT_SOURCE_PATH"] = os.path.normpath(self.path) + script_env["DOCUMENT_SOURCE_PATH"] = filepath_arg try: - Popen(settings.PRE_CONSUME_SCRIPT, env=script_env).wait() + Popen( + ( + settings.PRE_CONSUME_SCRIPT, + filepath_arg, + ), + env=script_env, + ).wait() except Exception as e: self._fail( MESSAGE_PRE_CONSUME_SCRIPT_ERROR, @@ -170,24 +178,38 @@ class Consumer(LoggingMixin): script_env["DOCUMENT_ADDED"] = str(document.added) script_env["DOCUMENT_FILE_NAME"] = document.get_public_filename() script_env["DOCUMENT_SOURCE_PATH"] = os.path.normpath(document.source_path) - script_env["DOCUMENT_ARCHIVE_PATH"] = os.path.normpath(str(document.archive_path)) + script_env["DOCUMENT_ARCHIVE_PATH"] = os.path.normpath( + str(document.archive_path), + ) script_env["DOCUMENT_THUMBNAIL_PATH"] = os.path.normpath( - document.thumbnail_path + document.thumbnail_path, ) script_env["DOCUMENT_DOWNLOAD_URL"] = reverse( - "document-download", kwargs={"pk": document.pk} + "document-download", + kwargs={"pk": document.pk}, ) script_env["DOCUMENT_THUMBNAIL_URL"] = reverse( - "document-thumb", kwargs={"pk": document.pk} + "document-thumb", + kwargs={"pk": document.pk}, ) script_env["DOCUMENT_CORRESPONDENT"] = str(document.correspondent) script_env["DOCUMENT_TAGS"] = str( - ",".join(document.tags.all().values_list("name", flat=True)) + ",".join(document.tags.all().values_list("name", flat=True)), ) try: Popen( - settings.POST_CONSUME_SCRIPT, + ( + settings.POST_CONSUME_SCRIPT, + str(document.pk), + document.get_public_filename(), + os.path.normpath(document.source_path), + os.path.normpath(document.thumbnail_path), + reverse("document-download", kwargs={"pk": document.pk}), + reverse("document-thumb", kwargs={"pk": document.pk}), + str(document.correspondent), + str(",".join(document.tags.all().values_list("name", flat=True))), + ), env=script_env, ).wait() except Exception as e: