<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from optparse import make_option <EOL> from django . conf import settings <EOL> from django . core . management . base import BaseCommand <EOL> from zerver . lib . actions import do_create_realm , set_default_streams <EOL> from zerver . models import RealmAlias <EOL> if not settings . VOYAGER : <EOL> from zilencer . models import Deployment <EOL> import re <EOL> import sys <EOL> class Command ( BaseCommand ) : <EOL> help = """<STR_LIT>""" <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> type = '<STR_LIT:str>' , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT:name>' , <EOL> type = '<STR_LIT:str>' , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> type = '<STR_LIT:int>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> def validate_domain ( self , domain ) : <EOL> if re . search ( "<STR_LIT>" , domain ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( domain . split ( "<STR_LIT:.>" ) ) < <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if RealmAlias . objects . filter ( domain = domain ) . count ( ) > <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def handle ( self , * args , ** options ) : <EOL> if options [ "<STR_LIT>" ] is None or options [ "<STR_LIT:name>" ] is None : <EOL> print ( "<STR_LIT>" , file = sys . stderr ) <EOL> self . print_help ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> if options [ "<STR_LIT>" ] and options [ "<STR_LIT>" ] is not None : <EOL> print ( "<STR_LIT>" , file = sys . stderr ) <EOL> self . print_help ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> if options [ "<STR_LIT>" ] is not None and settings . VOYAGER : <EOL> print ( "<STR_LIT>" , file = sys . stderr ) <EOL> exit ( <NUM_LIT:1> ) <EOL> domain = options [ "<STR_LIT>" ] <EOL> name = options [ "<STR_LIT:name>" ] <EOL> self . validate_domain ( domain ) <EOL> realm , created = do_create_realm ( <EOL> domain , name , restricted_to_domain = not options [ "<STR_LIT>" ] ) <EOL> if created : <EOL> print ( domain , "<STR_LIT>" ) <EOL> if options [ "<STR_LIT>" ] is not None : <EOL> deployment = Deployment . objects . get ( id = options [ "<STR_LIT>" ] ) <EOL> deployment . realms . add ( realm ) <EOL> deployment . save ( ) <EOL> print ( "<STR_LIT>" , str ( deployment . id ) ) <EOL> elif settings . ZULIP_COM : <EOL> deployment = Deployment . objects . get ( base_site_url = "<STR_LIT>" ) <EOL> deployment . realms . add ( realm ) <EOL> deployment . save ( ) <EOL> set_default_streams ( realm , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( domain , "<STR_LIT>" ) </s>
