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-07-05 03:39:01 +02:00
|
|
|
from six import text_type
|
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
|
2013-10-19 15:28:59 +02:00
|
|
|
from zerver.models import Realm, get_realm
|
|
|
|
|
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
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('domain', metavar='<domain>', type=str,
|
|
|
|
help='domain in which to create the stream')
|
|
|
|
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
|
2015-08-21 02:10:41 +02:00
|
|
|
domain = options['domain']
|
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
|
|
|
|
2016-07-05 03:39:01 +02:00
|
|
|
realm = get_realm(force_text(domain, encoding))
|
|
|
|
if realm is None:
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Unknown domain %s" % (domain,))
|
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))
|