Add create-stream management command.

The current version should only be used for testing; for example,
if you want to create a bunch of streams for stress testing, you
can run this in a loop.

(imported from commit ec51a431fb9679fc18379e4c6ecdba66bc75a395)
This commit is contained in:
Steve Howell
2013-10-19 09:28:59 -04:00
parent e0fa6e427b
commit 03c856ce10
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
from __future__ import absolute_import
from django.core.management.base import BaseCommand
from zerver.lib.actions import do_create_stream
from zerver.models import Realm, get_realm
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
the command.
Usage: python manage.py create-stream <domain> <stream name>"""
def handle(self, *args, **options):
if len(args) != 2:
print "Please provide a domain and the stream name."
exit(1)
domain, stream_name = args
encoding = sys.getfilesystemencoding()
try:
realm = get_realm(domain)
except Realm.DoesNotExist:
print "Unknown domain %s" % (domain,)
exit(1)
do_create_stream(realm, stream_name.decode(encoding))