mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-31 10:37:12 -04:00 
			
		
		
		
	Merge pull request #934 from sbrunner/no-progress
Add --no-progress-bar option to commands
This commit is contained in:
		
						commit
						f568a9fdfa
					
				| @ -106,6 +106,12 @@ class Command(BaseCommand): | ||||
|             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): | ||||
| 
 | ||||
| @ -140,7 +146,8 @@ class Command(BaseCommand): | ||||
|                         handle_document, | ||||
|                         document_ids | ||||
|                     ), | ||||
|                     total=len(document_ids) | ||||
|                     total=len(document_ids), | ||||
|                     disable=options['no_progress_bar'] | ||||
|                 )) | ||||
|         except KeyboardInterrupt: | ||||
|             print("Aborting...") | ||||
|  | ||||
| @ -57,6 +57,12 @@ class Command(BaseCommand): | ||||
|                  "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) | ||||
| @ -81,9 +87,9 @@ class Command(BaseCommand): | ||||
|             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( | ||||
| @ -124,8 +130,11 @@ class Command(BaseCommand): | ||||
|                 "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 | ||||
| 
 | ||||
|  | ||||
| @ -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) | ||||
| @ -70,7 +76,7 @@ class Command(BaseCommand): | ||||
|                 # 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') | ||||
| @ -111,7 +117,7 @@ class Command(BaseCommand): | ||||
|                         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) | ||||
| @ -123,7 +129,10 @@ class Command(BaseCommand): | ||||
|             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"]) | ||||
| 
 | ||||
|  | ||||
| @ -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,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) | ||||
|  | ||||
| @ -57,6 +57,12 @@ class Command(BaseCommand): | ||||
|                  "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): | ||||
| 
 | ||||
| @ -68,7 +74,10 @@ class Command(BaseCommand): | ||||
| 
 | ||||
|         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( | ||||
|  | ||||
| @ -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() | ||||
|  | ||||
| @ -47,6 +47,12 @@ class Command(BaseCommand): | ||||
|             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 | ||||
| @ -65,5 +71,7 @@ class Command(BaseCommand): | ||||
| 
 | ||||
|         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'] | ||||
|             )) | ||||
|  | ||||
| @ -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.") | ||||
|  | ||||
| @ -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) | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user