<s> from getpass import getpass <EOL> try : <EOL> input = raw_input <EOL> except NameError : <EOL> pass <EOL> from ... gafferd . util import confirm <EOL> from ... httpclient . base import GafferConflict <EOL> from ... httpclient . users import Users <EOL> from . base import Command <EOL> class UserAdd ( Command ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> short_descr = "<STR_LIT>" <EOL> def run ( self , config , args ) : <EOL> server = config . get ( '<STR_LIT>' ) <EOL> username = args [ '<STR_LIT>' ] <EOL> password = args [ '<STR_LIT>' ] <EOL> api_key = args [ '<STR_LIT>' ] <EOL> user_type = args [ "<STR_LIT>" ] <EOL> try : <EOL> if username is None : <EOL> while True : <EOL> username = input ( "<STR_LIT>" ) <EOL> if username and username is not None : <EOL> break <EOL> print ( "<STR_LIT>" ) <EOL> if password is None : <EOL> while True : <EOL> password = getpass ( "<STR_LIT>" ) <EOL> if password and password is not None : <EOL> break <EOL> print ( "<STR_LIT>" ) <EOL> while True : <EOL> confirm_password = getpass ( "<STR_LIT>" ) <EOL> if confirm_password == password : <EOL> break <EOL> print ( "<STR_LIT>" ) <EOL> if api_key is None : <EOL> api_key = input ( "<STR_LIT>" ) <EOL> if not api_key : <EOL> api_key = None <EOL> if user_type is None or not user_type . isdigit ( ) : <EOL> while True : <EOL> user_type = input ( "<STR_LIT>" ) <EOL> if user_type . isdigit ( ) or not user_type : <EOL> break <EOL> print ( "<STR_LIT>" ) <EOL> except KeyboardInterrupt : <EOL> return <EOL> if not user_type : <EOL> user_type = "<STR_LIT:1>" <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % username ) <EOL> print ( "<STR_LIT>" % api_key ) <EOL> print ( "<STR_LIT>" % user_type ) <EOL> print ( "<STR_LIT>" ) <EOL> if not confirm ( "<STR_LIT>" % username ) : <EOL> return <EOL> users = Users ( server ) <EOL> try : <EOL> user = users . create_user ( username , password , <EOL> user_type = int ( user_type ) , key = api_key ) <EOL> except GafferConflict : <EOL> raise RuntimeError ( "<STR_LIT>" % username ) <EOL> print ( "<STR_LIT>" % username ) </s>
