mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-05-23 07:22:28 -04:00
05feadbb7a
commita4709b1175Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu Jul 28 15:36:13 2022 -0700 Update stale.yml [skip ci] commit3a031084f3Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu Jul 28 15:24:23 2022 -0700 Update changelog.md commit0c517e5351Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu Jul 28 15:18:49 2022 -0700 v1.8.0 version strings commit5fe435048bMerge:278cedf3a722bfd0Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu Jul 28 15:17:30 2022 -0700 Merge pull request #1240 from paperless-ngx/beta [Beta] Paperless-ngx v1.8.0 Release Candidate 1 commita722bfd099Author: Paperless-ngx Translation Bot [bot] <99855517+paperless-l10n@users.noreply.github.com> Date: Thu Jul 28 07:46:12 2022 -0700 New Crowdin updates (#1291) * New translations django.po (French) [ci skip] * New translations messages.xlf (French) [ci skip] * New translations django.po (French) [ci skip] * New translations messages.xlf (French) [ci skip] * New translations messages.xlf (Turkish) [ci skip] * New translations django.po (Turkish) [ci skip] commitf3d99a5fdbMerge:ca33477079de0989Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Jul 26 11:21:42 2022 -0700 Merge pull request #1277 from paperless-ngx/fix/redo-ocr-button-on-edit Fix/feature: add redo ocr button to document edit view commit79de0989d5Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Jul 26 09:54:05 2022 -0700 fix button icon spacing on mobile commitca334770b7Author: Paperless-ngx Translation Bot [bot] <99855517+paperless-l10n@users.noreply.github.com> Date: Tue Jul 26 09:45:21 2022 -0700 New Crowdin updates (#1242) * New translations messages.xlf (Turkish) [ci skip] * New translations messages.xlf (German) [ci skip] * New translations django.po (German) [ci skip] * New translations messages.xlf (Italian) [ci skip] * New translations messages.xlf (Italian) [ci skip] * New translations messages.xlf (Finnish) [ci skip] * New translations messages.xlf (Finnish) [ci skip] commit1071357505Merge:f32dfe02ef790ca6Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Jul 26 09:44:42 2022 -0700 Merge pull request #1268 from paperless-ngx/bugfix-db-locked Bugfix: Adds configuration for database timeout, fixing database locked error commitf32dfe0278Merge:611707a34e78ca5dAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon Jul 25 12:59:31 2022 -0700 Merge pull request #1261 from paperless-ngx/fix/b1.8.0-ng-select-dropdowns Fix: dropdown selected items not visible again commit278cedf3d0Merge:b141671decc4553eAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon Jul 25 09:25:52 2022 -0700 Merge pull request #1272 from paperless-ngx/fix-1263 Documentation: fix occasional code block color legibility commit45a6b5a436Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun Jul 24 20:15:26 2022 -0700 Add redo OCR button to document edit commit611707a3d1Merge:2d88638db4d20d9bAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun Jul 24 19:59:30 2022 -0700 Merge pull request #1276 from paperless-ngx/bugfix-webp-import Bugfix: Document import doesn't convert thumbnails to WebP commitb4d20d9b9aAuthor: Trenton Holmes <holmes.trenton@gmail.com> Date: Sun Jul 24 10:22:53 2022 -0700 Fixes document import copying PNG files to .webp extensions without actual conversion commitecc4553e67Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri Jul 22 15:10:33 2022 -0700 fix occasional code block color legibility commitef790ca6f4Author: Trenton Holmes <holmes.trenton@gmail.com> Date: Fri Jul 22 11:08:52 2022 -0700 Fixes the copy and paste of the log line commit2d88638da7Merge:0e2e5f3491ba0bd0Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri Jul 22 10:45:53 2022 -0700 Merge pull request #1269 from paperless-ngx/beta-deps-final Chore: Locks dependencies to the final versions for the beta commit91ba0bd0afAuthor: Trenton Holmes <holmes.trenton@gmail.com> Date: Fri Jul 22 08:53:02 2022 -0700 Locks dependencies to the final versions for the beta commit0e2e5f3413Author: Trenton Holmes <holmes.trenton@gmail.com> Date: Tue Jul 19 13:57:00 2022 -0700 Creates utiliy to ensure all paths in settings are normalized and absolute commit7a99dcf693Author: Trenton Holmes <holmes.trenton@gmail.com> Date: Thu Jul 21 08:02:11 2022 -0700 Adds configuration for database timeout, documentation and troubleshotting suggestion commit4e78ca5d82Author: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed Jul 20 11:15:35 2022 -0700 remove merge error ng-select css commit83de38e56fMerge:f4be2e4fb1b6d50aAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed Jul 20 08:26:12 2022 -0700 Merge pull request #1247 from paperless-ngx/bugfix-pikepdf-ocrmypdf-warnings Bugfix: Adds pngquant and jbig2dec to Docker image commitf4be2e4fe7Merge:4444925d16b0f7f9Author: Quinn Casey <quinn@quinncasey.com> Date: Tue Jul 19 21:03:16 2022 -0700 Merge pull request #1259 from paperless-ngx/chore-add-ci-hadolint Chore: Add Hadolint job to CI commit16b0f7f9eeAuthor: Trenton Holmes <holmes.trenton@gmail.com> Date: Tue Jul 19 14:18:47 2022 -0700 Removes a Dockerfile I can't find referenced anywhere commit27721aef71Author: Trenton Holmes <holmes.trenton@gmail.com> Date: Tue Jul 19 14:01:47 2022 -0700 Fixes and updates the Hadolint action version commit329a317fdfAuthor: Trenton Holmes <holmes.trenton@gmail.com> Date: Tue Jul 19 13:54:33 2022 -0700 Configure Hadolint in a single location for both hooks and CI commitdaad634894Author: Trenton Holmes <holmes.trenton@gmail.com> Date: Fri Jul 15 13:45:23 2022 -0700 Adds a CI job for hadolint over all the Dockerfiles, fixes the minor thing it complained about commit4444925deaMerge:4c697ab59c1ae96dAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon Jul 18 15:55:29 2022 -0700 Merge pull request #1249 from paperless-ngx/fix-generated-changelog [CI] Fix automatic changelog generation on release commit9c1ae96d33Author: Quinn Casey <quinn@quinncasey.com> Date: Mon Jul 18 09:48:03 2022 -0700 Create PR for changelog instead of direct commit commitb1b6d50af6Author: Trenton Holmes <holmes.trenton@gmail.com> Date: Mon Jul 18 09:46:31 2022 -0700 Adds a couple packages to the Docker image for ocrmypdf and pikepdf commit4c697ab50eAuthor: Quinn Casey <quinn@quinncasey.com> Date: Sun Jul 17 15:23:28 2022 -0700 Bump version to beta commitb141671d90Merge:48dfbbeb2ab2d912Author: Quinn Casey <quinn@quinncasey.com> Date: Sun Jul 17 13:18:57 2022 -0700 Merge pull request #1237 from tooomm/patch-1 chore: Run stale bot only on certain labels commit2ab2d9127dAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri Jul 15 20:19:28 2022 -0700 Use cant-reproduce for stale commit278453451eAuthor: tooomm <tooomm@users.noreply.github.com> Date: Fri Jul 15 21:18:38 2022 +0200 only run on certain labels commit48dfbbebc6Merge:8efb97efe568b300Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun Jul 3 07:42:20 2022 -0700 Merge pull request #1110 from paperless-ngx/update-issue-form commit8efb97ef4eAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat Jul 2 19:06:32 2022 -0700 Update stale.yml [ci skip] commitd8cda7fc1bAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat Jul 2 17:51:39 2022 -0700 Use any-of-labels for stalebot [ci skip] commit68f0cf419bMerge:666b938526b12512Author: Felix E <felix@eckhofer.com> Date: Mon Jun 20 14:25:59 2022 +0200 Merge pull request #1148 from pReya/patch-1 fix: update scanner capability commit26b12512b1Author: Moritz Stückler <moritz.stueckler@gmail.com> Date: Mon Jun 20 12:06:54 2022 +0200 fix: update scanner capability The Brother ADS-A1700W does indeed support SFTP. I've just bought it, and set it up like this. commite568b3000eAuthor: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Jun 7 15:28:49 2022 -0700 Add lsio to issue form commit666b938550Merge:de5eaf1c163231d3Author: Quinn Casey <quinn@quinncasey.com> Date: Thu May 19 17:23:23 2022 -0700 Merge pull request #990 from tooomm/patch-2 Docs: Fix headings and add links to PRs in changelog commit163231d307Author: tooomm <tooomm@users.noreply.github.com> Date: Thu May 19 23:12:40 2022 +0200 Link issues, capitalization and minor fixes commite530750fc6Author: tooomm <tooomm@users.noreply.github.com> Date: Thu May 19 22:05:43 2022 +0200 update heading levels for v1.7.0
236 lines
8.4 KiB
Python
236 lines
8.4 KiB
Python
import json
|
|
import logging
|
|
import os
|
|
import shutil
|
|
from contextlib import contextmanager
|
|
from pathlib import Path
|
|
|
|
import tqdm
|
|
from django.conf import settings
|
|
from django.core.exceptions import FieldDoesNotExist
|
|
from django.core.management import call_command
|
|
from django.core.management.base import BaseCommand
|
|
from django.core.management.base import CommandError
|
|
from django.core.serializers.base import DeserializationError
|
|
from django.db.models.signals import m2m_changed
|
|
from django.db.models.signals import post_save
|
|
from documents.models import Document
|
|
from documents.parsers import run_convert
|
|
from documents.settings import EXPORTER_ARCHIVE_NAME
|
|
from documents.settings import EXPORTER_FILE_NAME
|
|
from documents.settings import EXPORTER_THUMBNAIL_NAME
|
|
from filelock import FileLock
|
|
from paperless import version
|
|
|
|
from ...file_handling import create_source_path_directory
|
|
from ...signals.handlers import update_filename_and_move_files
|
|
|
|
|
|
@contextmanager
|
|
def disable_signal(sig, receiver, sender):
|
|
try:
|
|
sig.disconnect(receiver=receiver, sender=sender)
|
|
yield
|
|
finally:
|
|
sig.connect(receiver=receiver, sender=sender)
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """
|
|
Using a manifest.json file, load the data from there, and import the
|
|
documents it refers to.
|
|
""".replace(
|
|
" ",
|
|
"",
|
|
)
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("source")
|
|
parser.add_argument(
|
|
"--no-progress-bar",
|
|
default=False,
|
|
action="store_true",
|
|
help="If set, the progress bar will not be shown",
|
|
)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
BaseCommand.__init__(self, *args, **kwargs)
|
|
self.source = None
|
|
self.manifest = None
|
|
self.version = None
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
logging.getLogger().handlers[0].level = logging.ERROR
|
|
|
|
self.source = options["source"]
|
|
|
|
if not os.path.exists(self.source):
|
|
raise CommandError("That path doesn't exist")
|
|
|
|
if not os.access(self.source, os.R_OK):
|
|
raise CommandError("That path doesn't appear to be readable")
|
|
|
|
manifest_path = os.path.normpath(os.path.join(self.source, "manifest.json"))
|
|
self._check_manifest_exists(manifest_path)
|
|
|
|
with open(manifest_path) as f:
|
|
self.manifest = json.load(f)
|
|
|
|
version_path = os.path.normpath(os.path.join(self.source, "version.json"))
|
|
if os.path.exists(version_path):
|
|
with open(version_path) as f:
|
|
self.version = json.load(f)["version"]
|
|
# Provide an initial warning if needed to the user
|
|
if self.version != version.__full_version_str__:
|
|
self.stdout.write(
|
|
self.style.WARNING(
|
|
"Version mismatch: "
|
|
f"Currently {version.__full_version_str__},"
|
|
f" importing {self.version}."
|
|
" Continuing, but import may fail.",
|
|
),
|
|
)
|
|
|
|
else:
|
|
self.stdout.write(self.style.NOTICE("No version.json file located"))
|
|
|
|
self._check_manifest()
|
|
with disable_signal(
|
|
post_save,
|
|
receiver=update_filename_and_move_files,
|
|
sender=Document,
|
|
):
|
|
with disable_signal(
|
|
m2m_changed,
|
|
receiver=update_filename_and_move_files,
|
|
sender=Document.tags.through,
|
|
):
|
|
# Fill up the database with whatever is in the manifest
|
|
try:
|
|
call_command("loaddata", manifest_path)
|
|
except (FieldDoesNotExist, DeserializationError) as e:
|
|
self.stdout.write(self.style.ERROR("Database import failed"))
|
|
if (
|
|
self.version is not None
|
|
and self.version != version.__full_version_str__
|
|
):
|
|
self.stdout.write(
|
|
self.style.ERROR(
|
|
"Version mismatch: "
|
|
f"Currently {version.__full_version_str__},"
|
|
f" importing {self.version}",
|
|
),
|
|
)
|
|
raise e
|
|
else:
|
|
self.stdout.write(
|
|
self.style.ERROR("No version information present"),
|
|
)
|
|
raise e
|
|
|
|
self._import_files_from_manifest(options["no_progress_bar"])
|
|
|
|
self.stdout.write("Updating search index...")
|
|
call_command(
|
|
"document_index",
|
|
"reindex",
|
|
no_progress_bar=options["no_progress_bar"],
|
|
)
|
|
|
|
@staticmethod
|
|
def _check_manifest_exists(path):
|
|
if not os.path.exists(path):
|
|
raise CommandError(
|
|
"That directory doesn't appear to contain a manifest.json " "file.",
|
|
)
|
|
|
|
def _check_manifest(self):
|
|
|
|
for record in self.manifest:
|
|
|
|
if not record["model"] == "documents.document":
|
|
continue
|
|
|
|
if EXPORTER_FILE_NAME not in record:
|
|
raise CommandError(
|
|
"The manifest file contains a record which does not "
|
|
"refer to an actual document file.",
|
|
)
|
|
|
|
doc_file = record[EXPORTER_FILE_NAME]
|
|
if not os.path.exists(os.path.join(self.source, doc_file)):
|
|
raise CommandError(
|
|
'The manifest file refers to "{}" which does not '
|
|
"appear to be in the source directory.".format(doc_file),
|
|
)
|
|
|
|
if EXPORTER_ARCHIVE_NAME in record:
|
|
archive_file = record[EXPORTER_ARCHIVE_NAME]
|
|
if not os.path.exists(os.path.join(self.source, archive_file)):
|
|
raise CommandError(
|
|
f"The manifest file refers to {archive_file} which "
|
|
f"does not appear to be in the source directory.",
|
|
)
|
|
|
|
def _import_files_from_manifest(self, progress_bar_disable):
|
|
|
|
os.makedirs(settings.ORIGINALS_DIR, exist_ok=True)
|
|
os.makedirs(settings.THUMBNAIL_DIR, exist_ok=True)
|
|
os.makedirs(settings.ARCHIVE_DIR, exist_ok=True)
|
|
|
|
self.stdout.write("Copy files into paperless...")
|
|
|
|
manifest_documents = list(
|
|
filter(lambda r: r["model"] == "documents.document", self.manifest),
|
|
)
|
|
|
|
for record in tqdm.tqdm(manifest_documents, disable=progress_bar_disable):
|
|
|
|
document = Document.objects.get(pk=record["pk"])
|
|
|
|
doc_file = record[EXPORTER_FILE_NAME]
|
|
document_path = os.path.join(self.source, doc_file)
|
|
|
|
thumb_file = record[EXPORTER_THUMBNAIL_NAME]
|
|
thumbnail_path = Path(os.path.join(self.source, thumb_file)).resolve()
|
|
|
|
if EXPORTER_ARCHIVE_NAME in record:
|
|
archive_file = record[EXPORTER_ARCHIVE_NAME]
|
|
archive_path = os.path.join(self.source, archive_file)
|
|
else:
|
|
archive_path = None
|
|
|
|
document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED
|
|
|
|
with FileLock(settings.MEDIA_LOCK):
|
|
if os.path.isfile(document.source_path):
|
|
raise FileExistsError(document.source_path)
|
|
|
|
create_source_path_directory(document.source_path)
|
|
|
|
shutil.copy2(document_path, document.source_path)
|
|
|
|
if thumbnail_path.suffix in {".png", ".PNG"}:
|
|
run_convert(
|
|
density=300,
|
|
scale="500x5000>",
|
|
alpha="remove",
|
|
strip=True,
|
|
trim=False,
|
|
auto_orient=True,
|
|
input_file=f"{thumbnail_path}[0]",
|
|
output_file=str(document.thumbnail_path),
|
|
)
|
|
else:
|
|
shutil.copy2(thumbnail_path, document.thumbnail_path)
|
|
if archive_path:
|
|
create_source_path_directory(document.archive_path)
|
|
# TODO: this assumes that the export is valid and
|
|
# archive_filename is present on all documents with
|
|
# archived files
|
|
shutil.copy2(archive_path, document.archive_path)
|
|
|
|
document.save()
|