mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 17:17:26 +01:00
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
|
|
import os
|
||
|
|
from argparse import ArgumentParser
|
||
|
|
|
||
|
|
from django.core.management import CommandError
|
||
|
|
|
||
|
|
|
||
|
|
class MultiProcessMixin:
|
||
|
|
"""
|
||
|
|
Small class to handle adding an argument and validating it
|
||
|
|
for the use of multiple processes
|
||
|
|
"""
|
||
|
|
|
||
|
|
def add_argument_processes_mixin(self, parser: ArgumentParser):
|
||
|
|
parser.add_argument(
|
||
|
|
"--processes",
|
||
|
|
default=max(1, os.cpu_count() // 4),
|
||
|
|
type=int,
|
||
|
|
help="Number of processes to distribute work amongst",
|
||
|
|
)
|
||
|
|
|
||
|
|
def handle_processes_mixin(self, *args, **options):
|
||
|
|
self.process_count = options["processes"]
|
||
|
|
if self.process_count < 1:
|
||
|
|
raise CommandError("There must be at least 1 process")
|
||
|
|
|
||
|
|
|
||
|
|
class ProgressBarMixin:
|
||
|
|
"""
|
||
|
|
Many commands use a progress bar, which can be disabled
|
||
|
|
via this class
|
||
|
|
"""
|
||
|
|
|
||
|
|
def add_argument_progress_bar_mixin(self, parser: ArgumentParser):
|
||
|
|
parser.add_argument(
|
||
|
|
"--no-progress-bar",
|
||
|
|
default=False,
|
||
|
|
action="store_true",
|
||
|
|
help="If set, the progress bar will not be shown",
|
||
|
|
)
|
||
|
|
|
||
|
|
def handle_progress_bar_mixin(self, *args, **options):
|
||
|
|
self.no_progress_bar = options["no_progress_bar"]
|
||
|
|
self.use_progress_bar = not self.no_progress_bar
|