]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
add prefix option to administration exporter
authorMatthieu Helleboid <mhelleboid@hotmail.com>
Fri, 13 Jan 2023 06:13:18 +0000 (07:13 +0100)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 24 Jan 2023 19:06:49 +0000 (11:06 -0800)
docs/administration.md
src/documents/management/commands/document_exporter.py

index e7fa74fec1aafdbdbbb34c5d7640b74b96e4aee6..7cbcf95b957cc3b85fc7c91c41286ca164011b7b 100644 (file)
@@ -227,11 +227,12 @@ is not a TTY" errors. For example:
 `docker-compose exec -T webserver document_exporter ../export`
 
 ```
-document_exporter target [-c] [-f] [-d] [-na] [-nt]
+document_exporter target [-c] [-f] [-p] [-d] [-na] [-nt]
 
 optional arguments:
 -c, --compare-checksums
 -f, --use-filename-format
+-p, --use-filename-prefix
 -d, --delete
 -na, --no-archive
 -nt, --no-thumbnail
@@ -277,6 +278,10 @@ The filenames generated by this command follow the format
 paperless to use `PAPERLESS_FILENAME_FORMAT` for exported filenames
 instead, specify `--use-filename-format`.
 
+If `-p` or `--use-filename-format` is provided, Files will be exported
+in dedicated folders according to their nature: `archive`, `originals`
+or `thumbnails`
+
 !!! warning
 
     If exporting with the file name format, there may be errors due to
index b44317969995ab30cbb5ac3a9391f87e87c4e69d..b6070b93d1df200fb85837babb8a0205df9126d5 100644 (file)
@@ -72,6 +72,15 @@ class Command(BaseCommand):
             "export directory, if configured.",
         )
 
+        parser.add_argument(
+            "-p",
+            "--use-filename-prefix",
+            default=False,
+            action="store_true",
+            help="Export files in dedicated folders according to their nature: "
+            "archive, originals or thumbnails",
+        )
+
         parser.add_argument(
             "-d",
             "--delete",
@@ -97,6 +106,7 @@ class Command(BaseCommand):
             action="store_true",
             help="Avoid exporting thumbnail files",
         )
+
         parser.add_argument(
             "--no-progress-bar",
             default=False,
@@ -119,6 +129,7 @@ class Command(BaseCommand):
         self.exported_files: List[Path] = []
         self.compare_checksums = False
         self.use_filename_format = False
+        self.use_filename_prefix = False
         self.delete = False
         self.no_archive = False
         self.no_thumbnail = False
@@ -128,6 +139,7 @@ class Command(BaseCommand):
         self.target = Path(options["target"]).resolve()
         self.compare_checksums = options["compare_checksums"]
         self.use_filename_format = options["use_filename_format"]
+        self.use_filename_prefix = options["use_filename_prefix"]
         self.delete = options["delete"]
         self.no_archive = options["no_archive"]
         self.no_thumbnail = options["no_thumbnail"]
@@ -262,11 +274,15 @@ class Command(BaseCommand):
 
             # 3.3. write filenames into manifest
             original_name = base_name
+            if self.use_filename_prefix:
+                original_name = ("originals" / Path(original_name)).resolve()
             original_target = (self.target / Path(original_name)).resolve()
             document_dict[EXPORTER_FILE_NAME] = original_name
 
             if not self.no_thumbnail:
                 thumbnail_name = base_name + "-thumbnail.webp"
+                if self.use_filename_prefix:
+                    thumbnail_name = ("thumbnails" / Path(thumbnail_name)).resolve()
                 thumbnail_target = (self.target / Path(thumbnail_name)).resolve()
                 document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_name
             else:
@@ -274,6 +290,8 @@ class Command(BaseCommand):
 
             if not self.no_archive and document.has_archive_version:
                 archive_name = base_name + "-archive.pdf"
+                if self.use_filename_prefix:
+                    archive_name = ("archive" / Path(archive_name)).resolve()
                 archive_target = (self.target / Path(archive_name)).resolve()
                 document_dict[EXPORTER_ARCHIVE_NAME] = archive_name
             else: