Files
zulip/zerver/management/commands/transfer_uploads_to_s3.py
Tim Abbott 8e7ce7cc79 python: Sort migrations/management command imports with isort.
This is a preparatory commit for using isort for sorting all of our
imports, merging changes to files where we can easily review the
changes as something we're happy with.

These are also files with relatively little active development, which
means we don't expect much merge conflict risk from these changes.
2020-01-14 13:07:47 -08:00

30 lines
1.0 KiB
Python

from typing import Any
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError, \
CommandParser
from zerver.lib.transfer import transfer_uploads_to_s3
class Command(BaseCommand):
help = """Transfer uploads to S3 """
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument('--processes',
dest='processes',
action="store",
default=6,
help='Processes to use for exporting uploads in parallel')
def handle(self, *args: Any, **options: Any) -> None:
num_processes = int(options['processes'])
if num_processes < 1:
raise CommandError('You must have at least one process.')
if not settings.LOCAL_UPLOADS_DIR:
raise CommandError('Please set the value of LOCAL_UPLOADS_DIR.')
transfer_uploads_to_s3(num_processes)
print("Transfer to S3 completed successfully.")