<s> from django . core . management . base import LabelCommand , CommandError <EOL> from corehq . apps . domain . models import Domain <EOL> from django . conf import settings <EOL> class Command ( LabelCommand ) : <EOL> help = "<STR_LIT>" <EOL> args = "<STR_LIT>" <EOL> label = "<STR_LIT>" <EOL> def handle ( self , * args , ** options ) : <EOL> from corehq . apps . users . models import WebUser <EOL> if len ( args ) != <NUM_LIT:3> : <EOL> raise CommandError ( '<STR_LIT>' ) <EOL> domain_name , username , passwd = args <EOL> domain = Domain . get_or_create_with_name ( domain_name , is_active = True ) <EOL> couch_user = WebUser . get_by_username ( username ) <EOL> membership = None <EOL> if couch_user : <EOL> if not isinstance ( couch_user , WebUser ) : <EOL> raise CommandError ( '<STR_LIT>' ) <EOL> membership = couch_user . get_domain_membership ( domain_name ) <EOL> else : <EOL> couch_user = WebUser . create ( domain_name , username , passwd ) <EOL> if not membership : <EOL> couch_user . add_domain_membership ( domain_name , is_admin = True ) <EOL> couch_user . is_superuser = True <EOL> couch_user . is_staff = True <EOL> couch_user . save ( ) <EOL> print "<STR_LIT>" % ( couch_user . username , domain ) <EOL> if not getattr ( settings , '<STR_LIT>' , None ) : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) </s>
