2016-09-13 22:40:13 +02:00
|
|
|
import argparse
|
2017-10-18 04:23:06 +02:00
|
|
|
import os
|
2016-09-13 22:40:13 +02:00
|
|
|
from typing import Any
|
2017-11-16 00:43:27 +01:00
|
|
|
|
2016-09-13 22:40:13 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
2017-11-16 00:43:27 +01:00
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
2016-09-13 22:40:13 +02:00
|
|
|
|
2017-10-18 04:23:06 +02:00
|
|
|
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
2017-11-16 00:43:27 +01:00
|
|
|
from zerver.lib.test_fixtures import get_migration_status
|
2016-09-13 22:40:13 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2016-09-13 22:40:13 +02:00
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Get status of migrations."
|
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"app_label", nargs="?", help="App label of an application to synchronize the state."
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2016-09-13 22:40:13 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"--database",
|
2021-02-12 08:19:30 +01:00
|
|
|
default=DEFAULT_DB_ALIAS,
|
2023-01-03 01:51:16 +01:00
|
|
|
help='Nominates a database to synchronize. Defaults to the "default" database.',
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2016-09-13 22:40:13 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("--output", help="Path to store the status to (default to stdout).")
|
2017-10-18 04:39:55 +02:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2017-10-18 04:39:55 +02:00
|
|
|
result = get_migration_status(**options)
|
2021-02-12 08:20:45 +01:00
|
|
|
if options["output"] is not None:
|
2017-10-18 04:23:06 +02:00
|
|
|
uuid_var_path = get_dev_uuid_var_path()
|
2021-02-12 08:20:45 +01:00
|
|
|
path = os.path.join(uuid_var_path, options["output"])
|
|
|
|
with open(path, "w") as f:
|
2017-10-18 04:39:55 +02:00
|
|
|
f.write(result)
|
|
|
|
else:
|
|
|
|
self.stdout.write(result)
|