mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-10 00:18:57 +00:00
Adds additional warnings during an import if it might fail due to reasons (#4814)
This commit is contained in:
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
import tqdm
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.core.management import call_command
|
||||
@@ -60,10 +61,11 @@ class Command(BaseCommand):
|
||||
self.manifest = None
|
||||
self.version = None
|
||||
|
||||
def handle(self, *args, **options):
|
||||
logging.getLogger().handlers[0].level = logging.ERROR
|
||||
|
||||
self.source = Path(options["source"]).resolve()
|
||||
def pre_check(self) -> None:
|
||||
"""
|
||||
Runs some initial checks against the source directory, including looking for
|
||||
common mistakes like having files still and users other than expected
|
||||
"""
|
||||
|
||||
if not self.source.exists():
|
||||
raise CommandError("That path doesn't exist")
|
||||
@@ -71,6 +73,40 @@ class Command(BaseCommand):
|
||||
if not os.access(self.source, os.R_OK):
|
||||
raise CommandError("That path doesn't appear to be readable")
|
||||
|
||||
for document_dir in [settings.ORIGINALS_DIR, settings.ARCHIVE_DIR]:
|
||||
if document_dir.exists() and document_dir.is_dir():
|
||||
for entry in document_dir.glob("**/*"):
|
||||
if entry.is_dir():
|
||||
continue
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
f"Found file {entry.relative_to(document_dir)}, this might indicate a non-empty installation",
|
||||
),
|
||||
)
|
||||
break
|
||||
if (
|
||||
User.objects.exclude(username__in=["consumer", "AnonymousUser"]).count()
|
||||
!= 0
|
||||
):
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
"Found existing user(s), this might indicate a non-empty installation",
|
||||
),
|
||||
)
|
||||
if Document.objects.count() != 0:
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
"Found existing documents(s), this might indicate a non-empty installation",
|
||||
),
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
logging.getLogger().handlers[0].level = logging.ERROR
|
||||
|
||||
self.source = Path(options["source"]).resolve()
|
||||
|
||||
self.pre_check()
|
||||
|
||||
manifest_paths = []
|
||||
|
||||
main_manifest_path = self.source / "manifest.json"
|
||||
|
Reference in New Issue
Block a user