2019-02-14 13:42:04 +01:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from django.conf import settings
|
2024-05-24 16:49:56 +02:00
|
|
|
from django.core.management.base import CommandError, CommandParser
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2019-02-14 13:42:04 +01:00
|
|
|
|
2024-05-24 16:49:56 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2019-02-14 13:42:04 +01:00
|
|
|
from zerver.lib.transfer import transfer_uploads_to_s3
|
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2024-05-24 16:49:56 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2019-02-14 13:42:04 +01:00
|
|
|
help = """Transfer uploads to S3 """
|
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2019-02-14 13:42:04 +01:00
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"--processes",
|
2021-02-12 08:19:30 +01:00
|
|
|
default=settings.DEFAULT_DATA_EXPORT_IMPORT_PARALLELISM,
|
2021-02-12 08:20:45 +01:00
|
|
|
help="Processes to use for exporting uploads in parallel",
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2019-02-14 13:42:04 +01:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2019-02-14 13:42:04 +01:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
num_processes = int(options["processes"])
|
2019-02-14 13:42:04 +01:00
|
|
|
if num_processes < 1:
|
2021-02-12 08:20:45 +01:00
|
|
|
raise CommandError("You must have at least one process.")
|
2019-02-14 13:42:04 +01:00
|
|
|
|
|
|
|
if not settings.LOCAL_UPLOADS_DIR:
|
2021-02-12 08:20:45 +01:00
|
|
|
raise CommandError("Please set the value of LOCAL_UPLOADS_DIR.")
|
2019-02-14 13:42:04 +01:00
|
|
|
|
|
|
|
transfer_uploads_to_s3(num_processes)
|
|
|
|
print("Transfer to S3 completed successfully.")
|