From 9fb5381acbb4af78d1e9a416aac74b71b3231f02 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Mon, 7 Aug 2017 20:26:52 +0000 Subject: [PATCH] management: Use self.get_realm in set_default_streams. --- .../commands/set_default_streams.py | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/zerver/management/commands/set_default_streams.py b/zerver/management/commands/set_default_streams.py index 6f4c1e808c..7ce0c3f090 100644 --- a/zerver/management/commands/set_default_streams.py +++ b/zerver/management/commands/set_default_streams.py @@ -4,15 +4,12 @@ from __future__ import print_function from argparse import ArgumentParser, RawTextHelpFormatter from typing import Any, Dict, Text -from django.core.management.base import BaseCommand, CommandParser - -from zerver.models import get_realm from zerver.lib.actions import set_default_streams +from zerver.lib.management import ZulipBaseCommand -from optparse import make_option import sys -class Command(BaseCommand): +class Command(ZulipBaseCommand): help = """Set default streams for a realm Users created under this realm will start out with these streams. This @@ -36,27 +33,24 @@ For example: def add_arguments(self, parser): # type: (ArgumentParser) -> None - parser.add_argument('-r', '--realm', - dest='string_id', - type=str, - help='The subdomain or string_id of the existing realm to which to ' - 'attach default streams.') - parser.add_argument('-s', '--streams', dest='streams', type=str, help='A comma-separated list of stream names.') + self.add_realm_args(parser, True) def handle(self, **options): # type: (**str) -> None - if options["string_id"] is None or options["streams"] is None: - print("Please provide both a subdomain name or string_id and a default \ -set of streams (which can be empty, with `--streams=`).", file=sys.stderr) + realm = self.get_realm(options) + if options["streams"] is None: + print("Please provide a default set of streams (which can be empty,\ +with `--streams=`).", file=sys.stderr) exit(1) + realm = self.get_realm(options) stream_dict = { stream.strip(): {"description": stream.strip(), "invite_only": False} for stream in options["streams"].split(",") } # type: Dict[Text, Dict[Text, Any]] - realm = get_realm(options["string_id"]) + set_default_streams(realm, stream_dict)