add prefix option to administration exporter

This commit is contained in:
Matthieu Helleboid 2023-01-13 07:13:18 +01:00 committed by Trenton H
parent 9ae186e6f9
commit 896304ccaa
2 changed files with 24 additions and 1 deletions

View 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

View 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: