<s> """<STR_LIT>""" <EOL> from lmi . scripts . common import command <EOL> from lmi . scripts . common . errors import LmiFailed <EOL> from lmi . scripts . common . errors import LmiInvalidOptions <EOL> from lmi . scripts import account <EOL> def get_user_info ( ns , user ) : <EOL> """<STR_LIT>""" <EOL> return ( user . Name , user . UserID , user . HomeDirectory , user . LoginShell , <EOL> user . PasswordLastChange ) <EOL> class Lister ( command . LmiLister ) : <EOL> COLUMNS = ( '<STR_LIT:Name>' , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def execute ( self , ns ) : <EOL> for s in sorted ( account . list_users ( ns ) , <EOL> key = lambda i : i . Name ) : <EOL> yield ( s . Name , s . UserID , s . ElementName ) <EOL> class Show ( command . LmiInstanceLister ) : <EOL> PROPERTIES = ( <EOL> '<STR_LIT:Name>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , lambda i : i . PasswordLastChange . datetime . strftime ( "<STR_LIT>" ) ) <EOL> ) <EOL> def transform_options ( self , options ) : <EOL> """<STR_LIT>""" <EOL> options [ '<STR_LIT>' ] = options . pop ( '<STR_LIT>' ) <EOL> def execute ( self , ns , users ) : <EOL> if users : <EOL> for user in users : <EOL> inst = account . get_user ( ns , user ) <EOL> yield inst <EOL> else : <EOL> for user in account . list_users ( ns ) : <EOL> yield user <EOL> class Delete ( command . LmiCheckResult ) : <EOL> OPT_NO_UNDERSCORES = True <EOL> EXPECT = None <EOL> def transform_options ( self , options ) : <EOL> """<STR_LIT>""" <EOL> options [ '<STR_LIT>' ] = options . pop ( '<STR_LIT>' ) <EOL> def execute ( self , ns , users , no_delete_group = False , no_delete_home = False , <EOL> force = False ) : <EOL> for user in users : <EOL> inst = account . get_user ( ns , user ) <EOL> account . delete_user ( ns , inst , no_delete_group , no_delete_home , <EOL> force ) <EOL> class Create ( command . LmiCheckResult ) : <EOL> OPT_NO_UNDERSCORES = True <EOL> EXPECT = None <EOL> def verify_options ( self , opts ) : <EOL> uid = opts [ '<STR_LIT>' ] <EOL> gid = opts [ '<STR_LIT>' ] <EOL> if uid is not None and not uid . isdigit ( ) : <EOL> raise LmiInvalidOptions ( "<STR_LIT>" ) <EOL> if gid is not None and not gid . isdigit ( ) : <EOL> raise LmiInvalidOptions ( "<STR_LIT>" ) <EOL> def execute ( self , ns , name , <EOL> gecos = None , <EOL> directory = None , <EOL> shell = None , <EOL> uid = None , <EOL> gid = None , <EOL> reserved = None , <EOL> no_user_home = False , <EOL> no_user_group = False , <EOL> password = None , <EOL> plain_password = False ) : <EOL> account . create_user ( ns , name , <EOL> gecos = gecos , <EOL> home = directory , <EOL> create_home = not no_user_home , <EOL> shell = shell , <EOL> uid = uid , <EOL> gid = gid , <EOL> create_group = not no_user_group , <EOL> reserved = reserved , <EOL> password = password , <EOL> plain_password = plain_password ) <EOL> User = command . register_subcommands ( <EOL> '<STR_LIT:user>' , __doc__ , <EOL> { '<STR_LIT:list>' : Lister <EOL> , '<STR_LIT>' : Show <EOL> , '<STR_LIT>' : Create <EOL> , '<STR_LIT>' : Delete <EOL> } , <EOL> ) </s>
