paperless-ngx/src/documents/management/commands/document_index.py

26 lines
803 B
Python
Raw Normal View History

from django.core.management import BaseCommand
2020-12-22 13:04:22 +01:00
from django.db import transaction
from documents.tasks import index_reindex, index_optimize
2021-02-04 23:40:53 +01:00
class Command(BaseCommand):
2020-10-27 17:08:18 +01:00
help = "Manages the document index."
2020-10-27 17:08:18 +01:00
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"
)
2020-10-27 17:08:18 +01:00
def handle(self, *args, **options):
2020-12-22 13:04:22 +01:00
with transaction.atomic():
if options['command'] == 'reindex':
index_reindex(progress_bar_disable=options['no_progress_bar'])
2020-12-22 13:04:22 +01:00
elif options['command'] == 'optimize':
index_optimize()