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

Commit

Permalink
Merge branch 'dev' of github.com:jonaswinkler/paperless-ng into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaswinkler committed May 15, 2021
2 parents b122a05 + f568a9f commit 9afc8ba
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/documents/management/commands/document_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ def add_arguments(self, parser):
help="Specify the ID of a document, and this command will only "
"run on this specific document."
)
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
help="If set, the progress bar will not be shown"
)

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

Expand Down Expand Up @@ -140,7 +146,8 @@ def handle(self, *args, **options):
handle_document,
document_ids
),
total=len(document_ids)
total=len(document_ids),
disable=options['no_progress_bar']
))
except KeyboardInterrupt:
print("Aborting...")
17 changes: 13 additions & 4 deletions src/documents/management/commands/document_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def add_arguments(self, parser):
"do not belong to the current export, such as files from "
"deleted documents."
)
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)
Expand All @@ -81,9 +87,9 @@ def handle(self, *args, **options):
raise CommandError("That path doesn't appear to be writable")

with FileLock(settings.MEDIA_LOCK):
self.dump()
self.dump(options['no_progress_bar'])

def dump(self):
def dump(self, progress_bar_disable=False):
# 1. Take a snapshot of what files exist in the current export folder
for root, dirs, files in os.walk(self.target):
self.files_in_export_dir.extend(
Expand Down Expand Up @@ -124,8 +130,11 @@ def dump(self):
"json", User.objects.all()))

# 3. Export files from each document
for index, document_dict in tqdm.tqdm(enumerate(document_manifest),
total=len(document_manifest)):
for index, document_dict in tqdm.tqdm(
enumerate(document_manifest),
total=len(document_manifest),
disable=progress_bar_disable
):
# 3.1. store files unencrypted
document_dict["fields"]["storage_type"] = Document.STORAGE_TYPE_UNENCRYPTED # NOQA: E501

Expand Down
15 changes: 12 additions & 3 deletions src/documents/management/commands/document_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class Command(BaseCommand):

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)
Expand Down Expand Up @@ -70,7 +76,7 @@ def handle(self, *args, **options):
# Fill up the database with whatever is in the manifest
call_command("loaddata", manifest_path)

self._import_files_from_manifest()
self._import_files_from_manifest(options['no_progress_bar'])

print("Updating search index...")
call_command('document_index', 'reindex')
Expand Down Expand Up @@ -111,7 +117,7 @@ def _check_manifest(self):
f"does not appear to be in the source directory."
)

def _import_files_from_manifest(self):
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)
Expand All @@ -123,7 +129,10 @@ def _import_files_from_manifest(self):
lambda r: r["model"] == "documents.document",
self.manifest))

for record in tqdm.tqdm(manifest_documents):
for record in tqdm.tqdm(
manifest_documents,
disable=progress_bar_disable
):

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

Expand Down
8 changes: 7 additions & 1 deletion src/documents/management/commands/document_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument("command", choices=['reindex', 'optimize'])
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
help="If set, the progress bar will not be shown"
)

def handle(self, *args, **options):
with transaction.atomic():
if options['command'] == 'reindex':
index_reindex()
index_reindex(progress_bar_disable=options['no_progress_bar'])
elif options['command'] == 'optimize':
index_optimize()
13 changes: 12 additions & 1 deletion src/documents/management/commands/document_renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ class Command(BaseCommand):
This will rename all documents to match the latest filename format.
""".replace(" ", "")

def add_arguments(self, parser):
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
help="If set, the progress bar will not be shown"
)

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

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

for document in tqdm.tqdm(Document.objects.all()):
for document in tqdm.tqdm(
Document.objects.all(),
disable=options['no_progress_bar']
):
post_save.send(Document, instance=document)
11 changes: 10 additions & 1 deletion src/documents/management/commands/document_retagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def add_arguments(self, parser):
"set correspondent, document and remove correspondents, types"
"and tags that do not match anymore due to changed rules."
)
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
help="If set, the progress bar will not be shown"
)

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

Expand All @@ -68,7 +74,10 @@ def handle(self, *args, **options):

classifier = load_classifier()

for document in tqdm.tqdm(documents):
for document in tqdm.tqdm(
documents,
disable=options['no_progress_bar']
):

if options['correspondent']:
set_correspondent(
Expand Down
10 changes: 9 additions & 1 deletion src/documents/management/commands/document_sanity_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ class Command(BaseCommand):
This command checks your document archive for issues.
""".replace(" ", "")

def add_arguments(self, parser):
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
help="If set, the progress bar will not be shown"
)

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

messages = check_sanity(progress=True)
messages = check_sanity(progress=not options['no_progress_bar'])

messages.log_messages()
10 changes: 9 additions & 1 deletion src/documents/management/commands/document_thumbnails.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def add_arguments(self, parser):
help="Specify the ID of a document, and this command will only "
"run on this specific document."
)
parser.add_argument(
"--no-progress-bar",
default=False,
action="store_true",
help="If set, the progress bar will not be shown"
)

def handle(self, *args, **options):
logging.getLogger().handlers[0].level = logging.ERROR
Expand All @@ -65,5 +71,7 @@ def handle(self, *args, **options):

with multiprocessing.Pool() as pool:
list(tqdm.tqdm(
pool.imap_unordered(_process_document, ids), total=len(ids)
pool.imap_unordered(_process_document, ids),
total=len(ids),
disable=options['no_progress_bar']
))
7 changes: 1 addition & 6 deletions src/documents/sanity_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ def check_sanity(progress=False):
if lockfile in present_files:
present_files.remove(lockfile)

if progress:
docs = tqdm(Document.objects.all())
else:
docs = Document.objects.all()

for doc in docs:
for doc in tqdm(Document.objects.all(), disable=not progress):
# Check sanity of the thumbnail
if not os.path.isfile(doc.thumbnail_path):
messages.error(f"Thumbnail of document {doc.pk} does not exist.")
Expand Down
4 changes: 2 additions & 2 deletions src/documents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def index_optimize():
writer.commit(optimize=True)


def index_reindex():
def index_reindex(progress_bar_disable=False):
documents = Document.objects.all()

ix = index.open_index(recreate=True)

with AsyncWriter(ix) as writer:
for document in tqdm.tqdm(documents):
for document in tqdm.tqdm(documents, disable=progress_bar_disable):
index.update_document(writer, document)


Expand Down

0 comments on commit 9afc8ba

Please sign in to comment.