From 0d3ab3aaf7479d2b644c1746497f669d9f43d461 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Thu, 4 Feb 2021 23:40:53 +0100 Subject: [PATCH] remove lots of unused code --- .../management/commands/document_archiver.py | 7 +------ .../commands/document_create_classifier.py | 3 +-- .../management/commands/document_exporter.py | 3 +-- .../management/commands/document_importer.py | 3 +-- src/documents/management/commands/document_index.py | 9 +-------- src/documents/management/commands/document_logs.py | 12 ------------ .../management/commands/document_renamer.py | 9 +-------- .../management/commands/document_retagger.py | 9 +-------- .../management/commands/document_thumbnails.py | 10 +--------- src/documents/mixins.py | 9 --------- 10 files changed, 8 insertions(+), 66 deletions(-) delete mode 100644 src/documents/management/commands/document_logs.py delete mode 100755 src/documents/mixins.py diff --git a/src/documents/management/commands/document_archiver.py b/src/documents/management/commands/document_archiver.py index 01bd819c5..9e0d8fabf 100644 --- a/src/documents/management/commands/document_archiver.py +++ b/src/documents/management/commands/document_archiver.py @@ -17,7 +17,6 @@ from whoosh.writing import AsyncWriter from documents.models import Document from ... import index from ...file_handling import create_source_path_directory -from ...mixins import Renderable from ...parsers import get_parser_class_for_mime_type @@ -62,7 +61,7 @@ def handle_document(document_id): parser.cleanup() -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ Using the current classification model, assigns correspondents, tags @@ -71,10 +70,6 @@ class Command(Renderable, BaseCommand): modified) after their initial import. """.replace(" ", "") - def __init__(self, *args, **kwargs): - self.verbosity = 0 - BaseCommand.__init__(self, *args, **kwargs) - def add_arguments(self, parser): parser.add_argument( "-f", "--overwrite", diff --git a/src/documents/management/commands/document_create_classifier.py b/src/documents/management/commands/document_create_classifier.py index fbfb7f7e6..a4ede88b5 100755 --- a/src/documents/management/commands/document_create_classifier.py +++ b/src/documents/management/commands/document_create_classifier.py @@ -1,10 +1,9 @@ from django.core.management.base import BaseCommand -from ...mixins import Renderable from ...tasks import train_classifier -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ Trains the classifier on your data and saves the resulting models to a diff --git a/src/documents/management/commands/document_exporter.py b/src/documents/management/commands/document_exporter.py index 37fcf2024..1505b0856 100644 --- a/src/documents/management/commands/document_exporter.py +++ b/src/documents/management/commands/document_exporter.py @@ -16,10 +16,9 @@ from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAME, \ EXPORTER_ARCHIVE_NAME from paperless.db import GnuPG from ...file_handling import generate_filename, delete_empty_directories -from ...mixins import Renderable -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ Decrypt and rename all files in our collection into a given target diff --git a/src/documents/management/commands/document_importer.py b/src/documents/management/commands/document_importer.py index a2e19e3cc..7e5d32085 100644 --- a/src/documents/management/commands/document_importer.py +++ b/src/documents/management/commands/document_importer.py @@ -15,7 +15,6 @@ from documents.models import Document from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAME, \ EXPORTER_ARCHIVE_NAME from ...file_handling import create_source_path_directory -from ...mixins import Renderable from ...signals.handlers import update_filename_and_move_files @@ -28,7 +27,7 @@ def disable_signal(sig, receiver, sender): sig.connect(receiver=receiver, sender=sender) -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ Using a manifest.json file, load the data from there, and import the diff --git a/src/documents/management/commands/document_index.py b/src/documents/management/commands/document_index.py index 08e20e1d2..5faa70b9f 100644 --- a/src/documents/management/commands/document_index.py +++ b/src/documents/management/commands/document_index.py @@ -1,24 +1,17 @@ from django.core.management import BaseCommand from django.db import transaction -from documents.mixins import Renderable from documents.tasks import index_reindex, index_optimize -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = "Manages the document index." - def __init__(self, *args, **kwargs): - self.verbosity = 0 - BaseCommand.__init__(self, *args, **kwargs) - def add_arguments(self, parser): parser.add_argument("command", choices=['reindex', 'optimize']) def handle(self, *args, **options): - - self.verbosity = options["verbosity"] with transaction.atomic(): if options['command'] == 'reindex': index_reindex() diff --git a/src/documents/management/commands/document_logs.py b/src/documents/management/commands/document_logs.py deleted file mode 100644 index 06efc3850..000000000 --- a/src/documents/management/commands/document_logs.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.core.management.base import BaseCommand - -from documents.models import Log - - -class Command(BaseCommand): - - help = "A quick & dirty way to see what's in the logs" - - def handle(self, *args, **options): - for log in Log.objects.order_by("pk"): - print(log) diff --git a/src/documents/management/commands/document_renamer.py b/src/documents/management/commands/document_renamer.py index 745d2d03d..f311715c6 100644 --- a/src/documents/management/commands/document_renamer.py +++ b/src/documents/management/commands/document_renamer.py @@ -5,23 +5,16 @@ from django.core.management.base import BaseCommand from django.db.models.signals import post_save from documents.models import Document -from ...mixins import Renderable -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ This will rename all documents to match the latest filename format. """.replace(" ", "") - def __init__(self, *args, **kwargs): - self.verbosity = 0 - BaseCommand.__init__(self, *args, **kwargs) - def handle(self, *args, **options): - self.verbosity = options["verbosity"] - logging.getLogger().handlers[0].level = logging.ERROR for document in tqdm.tqdm(Document.objects.all()): diff --git a/src/documents/management/commands/document_retagger.py b/src/documents/management/commands/document_retagger.py index b2f5d8918..a37ab9ef2 100755 --- a/src/documents/management/commands/document_retagger.py +++ b/src/documents/management/commands/document_retagger.py @@ -4,11 +4,10 @@ from django.core.management.base import BaseCommand from documents.classifier import load_classifier from documents.models import Document -from ...mixins import Renderable from ...signals.handlers import set_correspondent, set_document_type, set_tags -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ Using the current classification model, assigns correspondents, tags @@ -17,10 +16,6 @@ class Command(Renderable, BaseCommand): modified) after their initial import. """.replace(" ", "") - def __init__(self, *args, **kwargs): - self.verbosity = 0 - BaseCommand.__init__(self, *args, **kwargs) - def add_arguments(self, parser): parser.add_argument( "-c", "--correspondent", @@ -61,8 +56,6 @@ class Command(Renderable, BaseCommand): def handle(self, *args, **options): - self.verbosity = options["verbosity"] - if options["inbox_only"]: queryset = Document.objects.filter(tags__is_inbox_tag=True) else: diff --git a/src/documents/management/commands/document_thumbnails.py b/src/documents/management/commands/document_thumbnails.py index 6f6451599..cf2cbeb77 100644 --- a/src/documents/management/commands/document_thumbnails.py +++ b/src/documents/management/commands/document_thumbnails.py @@ -7,7 +7,6 @@ from django import db from django.core.management.base import BaseCommand from documents.models import Document -from ...mixins import Renderable from ...parsers import get_parser_class_for_mime_type @@ -30,16 +29,12 @@ def _process_document(doc_in): parser.cleanup() -class Command(Renderable, BaseCommand): +class Command(BaseCommand): help = """ This will regenerate the thumbnails for all documents. """.replace(" ", "") - def __init__(self, *args, **kwargs): - self.verbosity = 0 - BaseCommand.__init__(self, *args, **kwargs) - def add_arguments(self, parser): parser.add_argument( "-d", "--document", @@ -51,9 +46,6 @@ class Command(Renderable, BaseCommand): ) def handle(self, *args, **options): - - self.verbosity = options["verbosity"] - logging.getLogger().handlers[0].level = logging.ERROR if options['document']: diff --git a/src/documents/mixins.py b/src/documents/mixins.py deleted file mode 100755 index 949be02e8..000000000 --- a/src/documents/mixins.py +++ /dev/null @@ -1,9 +0,0 @@ -class Renderable: - """ - A handy mixin to make it easier/cleaner to print output based on a - verbosity value. - """ - - def _render(self, text, verbosity): - if self.verbosity >= verbosity: - print(text)