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:
|
2016-09-13 22:40:13 +02:00
|
|
|
parser.add_argument('app_label', nargs='?',
|
2016-12-03 00:04:17 +01:00
|
|
|
help='App label of an application to synchronize the state.')
|
2016-09-13 22:40:13 +02:00
|
|
|
|
|
|
|
parser.add_argument('--database', action='store', dest='database',
|
2016-12-03 00:04:17 +01:00
|
|
|
default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
|
|
|
|
'Defaults to the "default" database.')
|
2016-09-13 22:40:13 +02:00
|
|
|
|
2017-10-18 04:39:55 +02:00
|
|
|
parser.add_argument('--output', action='store',
|
|
|
|
help='Path to store the status to (default to stdout).')
|
|
|
|
|
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)
|
|
|
|
if options['output'] is not None:
|
2017-10-18 04:23:06 +02:00
|
|
|
uuid_var_path = get_dev_uuid_var_path()
|
|
|
|
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)
|