<s> import logging <EOL> from grouper import public_key <EOL> from grouper . ctl . util import ensure_valid_username , make_session <EOL> from grouper . model_soup import User <EOL> from grouper . models . audit_log import AuditLog <EOL> from grouper . user import get_all_users <EOL> def handle_command ( args ) : <EOL> if args . subcommand == "<STR_LIT:list>" : <EOL> session = make_session ( ) <EOL> all_users = get_all_users ( session ) <EOL> for user in all_users : <EOL> user_enabled = "<STR_LIT>" if user . enabled else "<STR_LIT>" <EOL> logging . info ( "<STR_LIT>" . format ( user . name , user_enabled ) ) <EOL> return <EOL> else : <EOL> user_command ( args ) <EOL> @ ensure_valid_username <EOL> def user_command ( args ) : <EOL> session = make_session ( ) <EOL> if args . subcommand == "<STR_LIT>" : <EOL> for username in args . username : <EOL> user = User . get ( session , name = username ) <EOL> if not user : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> user = User . get_or_create ( session , username = username , role_user = args . role_user ) <EOL> session . commit ( ) <EOL> else : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> return <EOL> elif args . subcommand == "<STR_LIT>" : <EOL> for username in args . username : <EOL> user = User . get ( session , name = username ) <EOL> if not user : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> elif not user . enabled : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> else : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> user . disable ( ) <EOL> session . commit ( ) <EOL> return <EOL> elif args . subcommand == "<STR_LIT>" : <EOL> for username in args . username : <EOL> user = User . get ( session , name = username ) <EOL> if not user : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> elif user . enabled : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> else : <EOL> logging . info ( "<STR_LIT>" . format ( username ) ) <EOL> user . enable ( user , preserve_membership = args . preserve_membership ) <EOL> session . commit ( ) <EOL> return <EOL> user = User . get ( session , name = args . username ) <EOL> if not user : <EOL> logging . error ( "<STR_LIT>" . format ( args . username ) ) <EOL> return <EOL> if args . subcommand == "<STR_LIT>" : <EOL> print "<STR_LIT>" % ( args . username , args . metadata_key , args . metadata_value ) <EOL> if args . metadata_value == "<STR_LIT>" : <EOL> args . metadata_value = None <EOL> user . set_metadata ( args . metadata_key , args . metadata_value ) <EOL> session . commit ( ) <EOL> elif args . subcommand == "<STR_LIT>" : <EOL> print "<STR_LIT>" <EOL> try : <EOL> pubkey = public_key . add_public_key ( session , user , args . public_key ) <EOL> except public_key . DuplicateKey : <EOL> print "<STR_LIT>" <EOL> return <EOL> except public_key . PublicKeyParseError : <EOL> print "<STR_LIT>" <EOL> return <EOL> AuditLog . log ( session , user . id , '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( pubkey . fingerprint ) , <EOL> on_user_id = user . id ) <EOL> def add_parser ( subparsers ) : <EOL> user_parser = subparsers . add_parser ( <EOL> "<STR_LIT:user>" , help = "<STR_LIT>" ) <EOL> user_parser . set_defaults ( func = handle_command ) <EOL> user_subparser = user_parser . add_subparsers ( dest = "<STR_LIT>" ) <EOL> user_subparser . add_parser ( <EOL> "<STR_LIT:list>" , help = "<STR_LIT>" ) <EOL> user_create_parser = user_subparser . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> user_create_parser . add_argument ( "<STR_LIT:username>" , nargs = "<STR_LIT:+>" ) <EOL> user_create_parser . add_argument ( "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> user_disable_parser = user_subparser . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> user_disable_parser . add_argument ( "<STR_LIT:username>" , nargs = "<STR_LIT:+>" ) <EOL> user_enable_parser = user_subparser . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> user_enable_parser . add_argument ( "<STR_LIT:username>" , nargs = "<STR_LIT:+>" ) <EOL> user_enable_parser . add_argument ( "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> user_key_parser = user_subparser . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> user_key_parser . add_argument ( "<STR_LIT:username>" ) <EOL> user_key_parser . add_argument ( "<STR_LIT>" ) <EOL> user_set_metadata_parser = user_subparser . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> user_set_metadata_parser . add_argument ( "<STR_LIT:username>" ) <EOL> user_set_metadata_parser . add_argument ( "<STR_LIT>" ) <EOL> user_set_metadata_parser . add_argument ( "<STR_LIT>" ) </s>
