2013-10-19 15:28:59 +02:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2013-10-19 15:28:59 +02:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2013-10-19 15:28:59 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
from zerver.lib.actions import do_create_stream
|
2016-07-05 03:39:01 +02:00
|
|
|
from zerver.lib.str_utils import force_text
|
2017-01-04 05:30:48 +01:00
|
|
|
from zerver.models import Realm, get_realm
|
2013-10-19 15:28:59 +02:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from argparse import ArgumentParser
|
2013-10-19 15:28:59 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Create a stream, and subscribe all active users (excluding bots).
|
|
|
|
|
|
|
|
This should be used for TESTING only, unless you understand the limitations of
|
2015-08-21 02:10:41 +02:00
|
|
|
the command."""
|
2013-10-19 15:28:59 +02:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2016-11-16 21:16:02 +01:00
|
|
|
parser.add_argument('realm', metavar='<realm>', type=str,
|
|
|
|
help='realm in which to create the stream')
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('stream_name', metavar='<stream name>', type=str,
|
|
|
|
help='name of stream to create')
|
2013-10-19 15:28:59 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
2016-11-16 21:16:02 +01:00
|
|
|
string_id = options['realm']
|
2013-10-19 15:28:59 +02:00
|
|
|
encoding = sys.getfilesystemencoding()
|
2016-07-05 03:39:01 +02:00
|
|
|
stream_name = options['stream_name']
|
2013-10-19 15:28:59 +02:00
|
|
|
|
2017-01-04 05:30:48 +01:00
|
|
|
realm = get_realm(force_text(string_id, encoding))
|
2016-07-05 03:39:01 +02:00
|
|
|
if realm is None:
|
2016-11-16 21:16:02 +01:00
|
|
|
print("Unknown string_id %s" % (string_id,))
|
2013-10-19 15:28:59 +02:00
|
|
|
exit(1)
|
2016-07-05 03:39:01 +02:00
|
|
|
else:
|
|
|
|
do_create_stream(realm, force_text(stream_name, encoding))
|