Includes the progress bar

This commit is contained in:
Trenton Holmes 2022-05-31 11:20:10 -07:00 committed by Michael Shamoon
parent dfd16c5187
commit b7250477b5

View File

@ -3,6 +3,7 @@ import shutil
from pathlib import Path from pathlib import Path
from typing import Type from typing import Type
import tqdm
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from documents.models import Document from documents.models import Document
@ -21,6 +22,14 @@ class Command(BaseCommand):
) )
def add_arguments(self, parser): 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",
)
parser.add_argument( parser.add_argument(
"documents", "documents",
nargs="+", nargs="+",
@ -33,9 +42,9 @@ class Command(BaseCommand):
all_docs = Document.objects.all() all_docs = Document.objects.all()
for doc_pk in args.documents: for doc_pk in tqdm.tqdm(args.documents, disable=options["no_progress_bar"]):
try: try:
self.stdout.write(f"Parsing document {doc_pk}") self.stdout.write(self.style.INFO(f"Parsing document {doc_pk}"))
doc: Document = all_docs.get(pk=doc_pk) doc: Document = all_docs.get(pk=doc_pk)
except ObjectDoesNotExist: except ObjectDoesNotExist:
self.stdout.write(self.style.ERROR(f"Document {doc_pk} does not exist")) self.stdout.write(self.style.ERROR(f"Document {doc_pk} does not exist"))