Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
progress bar for the document importer
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaswinkler committed Dec 22, 2020
1 parent 8dc1535 commit ebcb2cf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/documents/management/commands/document_importer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import logging
import os
import shutil
from contextlib import contextmanager

import tqdm
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandError
Expand Down Expand Up @@ -43,6 +45,8 @@ def __init__(self, *args, **kwargs):

def handle(self, *args, **options):

logging.getLogger().handlers[0].level = logging.ERROR

self.source = options["source"]

if not os.path.exists(self.source):
Expand Down Expand Up @@ -111,10 +115,13 @@ def _import_files_from_manifest(self):
os.makedirs(settings.THUMBNAIL_DIR, exist_ok=True)
os.makedirs(settings.ARCHIVE_DIR, exist_ok=True)

for record in self.manifest:
print("Copy files into paperless...")

if not record["model"] == "documents.document":
continue
manifest_documents = list(filter(
lambda r: r["model"] == "documents.document",
self.manifest))

for record in tqdm.tqdm(manifest_documents):

document = Document.objects.get(pk=record["pk"])

Expand All @@ -138,7 +145,6 @@ def _import_files_from_manifest(self):

create_source_path_directory(document.source_path)

print(f"Moving {document_path} to {document.source_path}")
shutil.copy(document_path, document.source_path)
shutil.copy(thumbnail_path, document.thumbnail_path)
if archive_path:
Expand Down

0 comments on commit ebcb2cf

Please sign in to comment.