rem
stringlengths
1
322k
add
stringlengths
0
2.05M
context
stringlengths
4
228k
meta
stringlengths
156
215
def skel(uri, login, sure = False, apply_skel = configuration.users.default_skel, yes = None) : """reapply a user's skel with confirmation.""" # forget about it, this is a scoria from the POST FORM to variable conversion. del yes # TODO : profiles.reload() groups.reload() users.reload() u = users.users g = groups.groups title = _("Reapply skel to user account %s") % login data = '%s<h1>%s</h1><br />' % (w.backto(), title) if users.is_system_login(login) : return w.page(title, w.error(_("Failed to reapply skel"), [ _("alter system account.") ], _("insufficient permissions to perform operation."))) if not sure : description = _('''This will rebuild his/her desktop from scratch, with defaults icons and so on.<br /><br />The user must be disconnected for the operation to be completely successfull.''') pri_group = g[u[users.login_to_uid(login)]['gid']]['name'] # liste des skels du profile en cours. def filter_skels(pri_group, sk_list) : ''' TODO: to be converted to licorn model if pri_group == configuration.mNames['RESPONSABLES_GROUP'] : return filter(lambda x: x.rfind("/%s/" % configuration.mNames['RESPONSABLES_GROUP']) != -1, sk_list) elif pri_group == configuration.mNames['USAGERS_GROUP'] : return filter(lambda x: x.rfind("/%s/" % configuration.mNames['USAGERS_GROUP']) != -1, sk_list) else : ''' return sk_list form_options = _("Which skel do you want to apply? %s") % w.select("apply_skel", filter_skels(pri_group, configuration.users.skels), func = os.path.basename) data += w.question(_("Are you sure you want to apply this skel to account <strong>%s</strong>?") % login, description, yes_values = [ _("Apply >>"), "/users/skel/%s/sure" % login, _("A") ], no_values = [ _("<< Cancel"), "/users/list", _("C") ], form_options = form_options) return w.page(title, data) else : # we are sure, do it ! command = [ "sudo", "mod", "user", "--quiet", "--no-colors", "--login", login, '--apply-skel', skel ] return w.page(title, data + w.run(command, uri, err_msg = _("Failed to apply skel <strong>%s</strong> on user account <strong>%s</strong>!") % (os.path.basename(apply_skel), login)))
8d0ea9eae6c1be319b21e5a49e5074e6478f580d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/8d0ea9eae6c1be319b21e5a49e5074e6478f580d/users.py
command = [ "sudo", "mod", "user", "--quiet", "--no-colors", "--login", login, '--apply-skel', skel ]
command = [ "sudo", "mod", "user", "--quiet", "--no-colors", "--login", login, '--apply-skel', apply_skel ]
def filter_skels(pri_group, sk_list) : ''' TODO: to be converted to licorn model if pri_group == configuration.mNames['RESPONSABLES_GROUP'] : return filter(lambda x: x.rfind("/%s/" % configuration.mNames['RESPONSABLES_GROUP']) != -1, sk_list) elif pri_group == configuration.mNames['USAGERS_GROUP'] : return filter(lambda x: x.rfind("/%s/" % configuration.mNames['USAGERS_GROUP']) != -1, sk_list) else : ''' return sk_list
8d0ea9eae6c1be319b21e5a49e5074e6478f580d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/8d0ea9eae6c1be319b21e5a49e5074e6478f580d/users.py
profile.add_option("--group", "--name",
profile.add_option("--name", action="store", type="string", dest="name", default = None, help="specify profile to modify by its name (%s)." % styles.stylize(styles.ST_IMPORTANT, "one of --name or --group is required")) profile.add_option("--group",
def mod_profile_parse_arguments(app): usage_text = "\n\t%s profile --group=<nom> [--name=<nouveau_nom>] [--rename-group=<nouveau_nom>]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--comment=<nouveau_commentaire>] [--shell=<nouveau_shell>] [--skel=<nouveau_skel>]\n" \ + "\t\t[--quota=<nouveau_quota>] [--add-groups=<groupes>] [--del-groups=<groupes>]\n" \ + "\t%s profile <--apply-groups|--apply-skel|--apply-all> [--force]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--to-users=<user1[[,user2][,...]]>] [--to-groups=<group1[[,group2][,...]]>]\n" \ + "\t\t[--to-all] [--to-members] [--no-instant-apply] [--no-sync]" parser = OptionParser(usage = usage_text, version = __build_version_string(app)) # common behaviour group parser.add_option_group(__common_behaviour_group(app, parser, 'mod_profile')) profile = OptionGroup(parser, styles.stylize(styles.ST_OPTION, "Modify profile options ")) profile.add_option("--group", "--name", action="store", type="string", dest="group", default = None, help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "required")) profile.add_option("--rename", action="store", type="string", dest="newname", default = None, help="specify profile's name") profile.add_option("--rename-group", action="store", type="string", dest="newgroup", default = None, help="Rename primary group.") profile.add_option("--description", action="store", type="string", dest="description", default = None, help="Change profile's description.") profile.add_option("--shell", action="store", type="string", dest="newshell", default = None, help="Change profile shell (defaults to %s if you specify --shell without argument)" % styles.stylize(styles.ST_DEFAULT, configuration.users.default_shell)) profile.add_option("--quota", action="store", type="int", dest="newquota", default = None, help="Change profile's user quota (in Mb, defaults to %s if you specify --quota without argument)." % styles.stylize(styles.ST_DEFAULT, "1024")) profile.add_option("--skel", action="store", type="string", dest="newskel", default = None, help="Change profile skel (specify a skel dir as an absolute pathname, defaults to %s if you give --skel without argument)." % styles.stylize(styles.ST_DEFAULT, configuration.users.default_skel)) profile.add_option("--add-groups", action="store", type="string", dest="groups_to_add", default = None, help="Add one or more group(s) to default memberships of profile (separate groups with commas without spaces).") profile.add_option("--del-groups", action="store", type="string", dest="groups_to_del", default = None, help="Delete one or more group(s) from default memberships of profile (separate groups with commas without spaces).") profile.add_option("--apply-groups", action="store_true", dest="apply_groups", default = False, help="Re-apply only the default group memberships of the profile.") profile.add_option("--apply-skel", action="store_true", dest="apply_skel", default = False, help="Re-apply only the skel of the profile.") profile.add_option("--apply-all", action="store_true", dest="apply_all_attributes", default = False, help="Re-apply all the profile's attributes (groups and skel).") profile.add_option("--to-users", action="store", type="string", dest="apply_to_users", default = None, help="Re-apply to specific users accounts (separate them with commas without spaces).") profile.add_option("--to-groups", action="store", type="string", dest="apply_to_groups", default = None, help="Re-apply to all members of one or more groups (separate groups with commas without spaces). You can mix --to-users and --to-groups.") profile.add_option("--to-members", action="store_true", dest="apply_to_members", default = False, help="Re-apply to all users members of the profile.") profile.add_option("--to-all", action="store_true", dest="apply_to_all_accounts", default = None, help="Re-apply to all user accounts on the system (LENGHTY operation !).") profile.add_option("--no-instant-apply", action="store_false", dest="instant_apply", default = True, help="Don't apply group addition/deletion instantly to all members of the modified profile (%s; use this only if you know what you're doing)." % styles.stylize(styles.ST_IMPORTANT, "this is not recommended")) profile.add_option("--no-sync", action="store_true", dest="no_sync", default = False, help="Commit changes only after all modifications.") parser.add_option_group(profile) return (parser.parse_args())
4559cb68c55d791cc4138a382ba8a46485ca1efd /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/4559cb68c55d791cc4138a382ba8a46485ca1efd/argparser.py
help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "required"))
help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "one of --name or --group is required"))
def mod_profile_parse_arguments(app): usage_text = "\n\t%s profile --group=<nom> [--name=<nouveau_nom>] [--rename-group=<nouveau_nom>]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--comment=<nouveau_commentaire>] [--shell=<nouveau_shell>] [--skel=<nouveau_skel>]\n" \ + "\t\t[--quota=<nouveau_quota>] [--add-groups=<groupes>] [--del-groups=<groupes>]\n" \ + "\t%s profile <--apply-groups|--apply-skel|--apply-all> [--force]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--to-users=<user1[[,user2][,...]]>] [--to-groups=<group1[[,group2][,...]]>]\n" \ + "\t\t[--to-all] [--to-members] [--no-instant-apply] [--no-sync]" parser = OptionParser(usage = usage_text, version = __build_version_string(app)) # common behaviour group parser.add_option_group(__common_behaviour_group(app, parser, 'mod_profile')) profile = OptionGroup(parser, styles.stylize(styles.ST_OPTION, "Modify profile options ")) profile.add_option("--group", "--name", action="store", type="string", dest="group", default = None, help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "required")) profile.add_option("--rename", action="store", type="string", dest="newname", default = None, help="specify profile's name") profile.add_option("--rename-group", action="store", type="string", dest="newgroup", default = None, help="Rename primary group.") profile.add_option("--description", action="store", type="string", dest="description", default = None, help="Change profile's description.") profile.add_option("--shell", action="store", type="string", dest="newshell", default = None, help="Change profile shell (defaults to %s if you specify --shell without argument)" % styles.stylize(styles.ST_DEFAULT, configuration.users.default_shell)) profile.add_option("--quota", action="store", type="int", dest="newquota", default = None, help="Change profile's user quota (in Mb, defaults to %s if you specify --quota without argument)." % styles.stylize(styles.ST_DEFAULT, "1024")) profile.add_option("--skel", action="store", type="string", dest="newskel", default = None, help="Change profile skel (specify a skel dir as an absolute pathname, defaults to %s if you give --skel without argument)." % styles.stylize(styles.ST_DEFAULT, configuration.users.default_skel)) profile.add_option("--add-groups", action="store", type="string", dest="groups_to_add", default = None, help="Add one or more group(s) to default memberships of profile (separate groups with commas without spaces).") profile.add_option("--del-groups", action="store", type="string", dest="groups_to_del", default = None, help="Delete one or more group(s) from default memberships of profile (separate groups with commas without spaces).") profile.add_option("--apply-groups", action="store_true", dest="apply_groups", default = False, help="Re-apply only the default group memberships of the profile.") profile.add_option("--apply-skel", action="store_true", dest="apply_skel", default = False, help="Re-apply only the skel of the profile.") profile.add_option("--apply-all", action="store_true", dest="apply_all_attributes", default = False, help="Re-apply all the profile's attributes (groups and skel).") profile.add_option("--to-users", action="store", type="string", dest="apply_to_users", default = None, help="Re-apply to specific users accounts (separate them with commas without spaces).") profile.add_option("--to-groups", action="store", type="string", dest="apply_to_groups", default = None, help="Re-apply to all members of one or more groups (separate groups with commas without spaces). You can mix --to-users and --to-groups.") profile.add_option("--to-members", action="store_true", dest="apply_to_members", default = False, help="Re-apply to all users members of the profile.") profile.add_option("--to-all", action="store_true", dest="apply_to_all_accounts", default = None, help="Re-apply to all user accounts on the system (LENGHTY operation !).") profile.add_option("--no-instant-apply", action="store_false", dest="instant_apply", default = True, help="Don't apply group addition/deletion instantly to all members of the modified profile (%s; use this only if you know what you're doing)." % styles.stylize(styles.ST_IMPORTANT, "this is not recommended")) profile.add_option("--no-sync", action="store_true", dest="no_sync", default = False, help="Commit changes only after all modifications.") parser.add_option_group(profile) return (parser.parse_args())
4559cb68c55d791cc4138a382ba8a46485ca1efd /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/4559cb68c55d791cc4138a382ba8a46485ca1efd/argparser.py
if user['shadowExpire'] == '':
if 'shadowExpire' in user and user['shadowExpire'] == '':
def save_User(self, uid, mode): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """
1bcb0e3fee84acbc717132da1506e7084ebf8f9a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/1bcb0e3fee84acbc717132da1506e7084ebf8f9a/openldap.py
if user['shadowFlag'] == '':
if 'shadowFlag' in user and user['shadowFlag'] == '':
def save_User(self, uid, mode): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """
1bcb0e3fee84acbc717132da1506e7084ebf8f9a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/1bcb0e3fee84acbc717132da1506e7084ebf8f9a/openldap.py
if user['shadowInactive'] == '':
if 'shadowInactive' in user and user['shadowInactive'] == '':
def save_User(self, uid, mode): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """
1bcb0e3fee84acbc717132da1506e7084ebf8f9a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/1bcb0e3fee84acbc717132da1506e7084ebf8f9a/openldap.py
groups = GroupsController(self.configuration)
users = UsersController(self.configuration) groups = GroupsController(self.configuration, users)
def append(self, privilege): """ Set append like: no doubles.""" try: self.index(privilege) except ValueError: from licorn.core.groups import GroupsController groups = GroupsController(self.configuration) if groups.is_system_group(privilege): list.append(self, privilege) else: logging.warning("%s is not a privilege." % \ styles.stylize(styles.ST_NAME, privilege)) else: logging.info("privilege %s already whitelisted, skipped." % \ styles.stylize(styles.ST_NAME, privilege))
5e51e61aa801bd2b33915b561a0ea0c4b159a6c4 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5e51e61aa801bd2b33915b561a0ea0c4b159a6c4/privileges.py
return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox('''%s <div class="vspacer"></div>
return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox(''' <div style="line-height: 1.5em; padding-bottom:20px">%s</div>
def reboot(uri, http_user, sure = False): if sure: return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox('''<div class="vspacer"></div>%s''' % \ _('Rebooting…')))) else: return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox('''%s <div class="vspacer"></div> <table class="lbox-table"> <tr> <td> <form name="reboot_form" id="reboot_form" action="/server/reboot/sure" method="get"> <a href="/server/reboot/sure" params="lightwindow_form=reboot_form,''' '''lightwindow_width=320,lightwindow_height=140" class="lightwindow_action" rel="submitForm"> <button>%s</button> </a> </form> </td> <td> <a href="#" class="lightwindow_action" rel="deactivate"> <button>%s</button></a> </td> </tr> </table> ''' % ( _('Sure you want to reboot the %s server?') % configuration.app_name, _('YES'), _('NO')))))
006632e8b9a15157ad0ccff9a95da1fbb4ae85c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/006632e8b9a15157ad0ccff9a95da1fbb4ae85c2/server.py
from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers
from licorn.core.groups import GroupsController allgroups = GroupsController(allusers.configuration, allusers)
def check_dirs_and_contents_perms_and_acls(dirs_infos, batch = False, auto_answer = None, allgroups = None, allusers = None): """ Check if a dir exists, else create it and apply ACLs on it eventually. dirs_infos should be a n-tuple of dicts, composed like this: { 'path' : string, 'type' : stat.S_IF???, # what type the "path" should be 'user' : 'owner', # the name, not the uid 'group' : 'group', # the name too, 'exclude' : [ ... ], # dirs and files inside 'path' to be excluded from search) *and* 'mode' : chmod_mode (INT), # always use 00600 for example, not just 600, else it won't work. 'content_mode': another int, # mode for files inside 'path' *or* 'access_acl' : string, 'default_acl': string, 'content_acl': string, } if mode and content_mode are present, ACL will be deleted from path and its contents, *_acl will not be used and not be checked (Posix mode and posix1e ACLs are mutually exclusive). when content_mode is present, it will be applyed on regular files inside 'path'. 'mode' will be applyed on dirs inside 'path'. When checking ACLs, default_acl will be applyed on dirs as access *and* default acl. 'default_acl' will be applyed on dirs inside 'path', and 'content_acl' will be checked against files inside 'path'. TODO: 'default_acl' should be checked against files inside 'path', modulo the mask change from 'rwx' to 'rw-', which will should automagically imply "effective" ACLs computed on the fly. """ if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers def check_one_dir_and_acl(dir_info, batch = batch, auto_answer = auto_answer): all_went_ok = True #logging.debug('checking %s' % styles.stylize(styles.ST_PATH, dir_info['path'])) try: if dir_info.has_key('user') and dir_info['user'] != '': uid = allusers.login_to_uid(dir_info['user']) else: uid = -1 if dir_info.has_key('group') and dir_info['group'] != '': gid = allgroups.name_to_gid(dir_info['group']) else: gid = -1 except KeyError, e: raise exceptions.LicornRuntimeError("You just encountered a programmer bug. Get in touch with [email protected] (was: %s)." % e) except exceptions.LicornRuntimeException, e: raise exceptions.LicornRuntimeError("The uid/gid you want to check against does not exist on this system ! This shouldn't happen and is probably a programmer/packager bug. Get in touch with [email protected] (was: %s)." % e) try: logging.progress("Checking dir %s..." % styles.stylize(styles.ST_PATH, dir_info['path'])) dirstat = os.lstat(dir_info['path']) except OSError, e: if e.errno == 13: raise exceptions.InsufficientPermissionsError(str(e)) elif e.errno == 2: warn_message = "Directory %s does not exist." % styles.stylize(styles.ST_PATH, dir_info['path']) if batch or logging.ask_for_repair(warn_message, auto_answer): os.mkdir(dir_info['path']) dirstat = os.lstat(dir_info['path']) batch = True logging.info("Created dir %s." % styles.stylize(styles.ST_PATH, dir_info['path'])) else: # we cannot continue if dir does not exist. raise exceptions.LicornCheckError("Can't continue checks for directory %s (was: %s)." % (dir_info['path'], e) ) else: # FIXME: do more things to recover from more system errors... raise e if ( dirstat.st_mode & 0170000 ) != S_IFDIR: warn_message = logging.SWKN_DIR_IS_NOT_A_DIR % styles.stylize(styles.ST_PATH, dir_info['path']) if batch or logging.ask_for_repair(warn_message, auto_answer): os.unlink(dir_info['path']) os.mkdir(dir_info['path']) dirstat = os.lstat(dir_info['path']) batch = True logging.info("Created dir %s." % styles.stylize(styles.ST_PATH, dir_info['path'])) else: raise exceptions.LicornCheckError("Can't continue checks for directory %s (was: %s)." % (dir_info['path'], e) ) if dir_info.has_key('mode'): logging.progress("Checking %s's posix perms..." % styles.stylize(styles.ST_PATH, dir_info['path'])) all_went_ok &= check_posix_ugid_and_perms(dir_info['path'], uid, gid, dir_info['mode'], batch, auto_answer, allgroups, allusers) if dir_info.has_key('content_mode'): # check the contents of the dir (existing files and directories, except the ones which # are excluded), only if the content_acl is set, else skip content check. all_went_ok &= check_posix_dir_contents(dir_info, uid, gid, batch, auto_answer) else: logging.progress("Checking %s's ACLs..." % styles.stylize(styles.ST_PATH, dir_info['path'])) # check uid/gid, but don't check the perms (thus -1) because ACLs overrride them. all_went_ok &= check_posix_ugid_and_perms(dir_info['path'], uid, gid, -1, batch, auto_answer, allgroups, allusers) all_went_ok &= check_posix1e_acl(dir_info['path'], False, dir_info['access_acl'], dir_info['default_acl'], batch, auto_answer) if dir_info.has_key('content_acl'): # this hack is needed to use check_posix_dir_contents() to check only uid/gid (not perms) dir_info['mode'] = -1 dir_info['content_mode' ] = -1 # check the contents of the dir (existing files and directories, except the ones which # are excluded), only if "content_acl" is set, else skip content check. all_went_ok &= check_posix_dir_contents(dir_info, uid, gid, batch, auto_answer, allgroups, allusers) all_went_ok &= check_posix1e_dir_contents(dir_info, batch, auto_answer) return all_went_ok if dirs_infos: if reduce(pyutils.keep_false, map(check_one_dir_and_acl, dirs_infos)) is False: return False else: return True else: raise exceptions.BadArgumentError("You must pass some dirs (through dirs_infos) to check as arguments !")
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers
from licorn.core.groups import GroupsController allgroups = GroupsController(allusers.configuration, allusers)
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
desired_login = allusers.users[ uid ]['login']
desired_login = allusers[uid]['login']
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
desired_login = allusers.users[ uid ]['login']
desired_login = allusers[uid]['login']
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
desired_group = allgroups.groups[ gid ]['name']
desired_group = allgroups[gid]['name']
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
desired_group = allgroups.groups[ gid ]['name']
desired_group = allgroups[gid]['name']
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
current_login = allusers.users[ pathstat.st_uid ]['login']
current_login = allusers[pathstat.st_uid]['login']
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
current_group = allgroups.groups[ pathstat.st_gid ]['name']
current_group = allgroups[pathstat.st_gid]['name']
def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok
09be11c609797e29cd65819ebd1b1b664074d86b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/09be11c609797e29cd65819ebd1b1b664074d86b/fsapi.py
to_remove.append(member)
to_remove.add(member)
def load_groups(self): """ Load groups from /etc/{group,gshadow} and /etc/licorn/group. """
353f19b3b5ec055d3d58174646dc5e75a96491cb /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/353f19b3b5ec055d3d58174646dc5e75a96491cb/unix_backend.py
except (OSError, IOerror), e:
except (OSError, IOError), e:
def CleanUp(self): """This is a sort of destructor. Clean-up before being deleted..."""
31a1d5a2c76235131c71593a3c9219a20464cd4b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/31a1d5a2c76235131c71593a3c9219a20464cd4b/configuration.py
def AddGroup(self, name, gid=None, description="", groupSkel="", system=False, permissive=False, batch=False, force=False):
def AddGroup(self, name, gid=None, description="", groupSkel="", system=False, permissive=False, batch=False, force=False):
def AddGroup(self, name, gid=None, description="", groupSkel="", system=False, permissive=False, batch=False, force=False): """ Add an Licorn group (the group + the responsible group + the shared dir + permissions). """
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
self.CheckGroups([ name ], minimal = True, batch = True)
self.CheckGroups([ name ], minimal=True, batch=True)
def AddGroup(self, name, gid=None, description="", groupSkel="", system=False, permissive=False, batch=False, force=False): """ Add an Licorn group (the group + the responsible group + the shared dir + permissions). """
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
logging.info(logging.SYSG_CREATED_GROUP % styles.stylize(styles.ST_NAME, name))
logging.info(logging.SYSG_CREATED_GROUP % \ styles.stylize(styles.ST_NAME, name))
def AddGroup(self, name, gid=None, description="", groupSkel="", system=False, permissive=False, batch=False, force=False): """ Add an Licorn group (the group + the responsible group + the shared dir + permissions). """
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
self.CheckGroupSymlinks(gid = gid, group = name, delete = True, batch = True)
self.CheckGroupSymlinks(gid = gid, group = name, delete=True, batch=True)
def DeleteGroup(self, name, del_users, no_archive, bygid = None, batch=False): """ Delete an Licorn group """ if name is None and bygid is None: raise exceptions.BadArgumentError, "You must specify a name or a GID."
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
self.CheckGroups( [ new_name ], batch = True)
self.CheckGroups( [ new_name ], batch=True)
def RenameGroup(self, profilelist, name, new_name): """ Modify the name of a group."""
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
self.CheckGroupSymlinks(gid, oldname = name, batch = True)
self.CheckGroupSymlinks(gid, oldname=name, batch=True)
def RenameGroup(self, profilelist, name, new_name): """ Modify the name of a group."""
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
all_went_ok &= self.CheckGroupSymlinks(prefix_gid, strip_prefix = prefix, batch = batch, auto_answer = auto_answer)
all_went_ok &= self.CheckGroupSymlinks(prefix_gid, strip_prefix=prefix, batch=batch, auto_answer=auto_answer)
def CheckAssociatedSystemGroups(self, group, minimal = True, batch = False, auto_answer = None): """Check the system groups that a standard group need to fuction flawlessly. For example, a group "toto" need 2 system groups "resp-toto" and "guest-toto" for its ACLs. """
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
all_went_ok &= self.CheckGroupSymlinks(gid, batch = batch, auto_answer = auto_answer)
all_went_ok &= self.CheckGroupSymlinks(gid, batch=batch, auto_answer=auto_answer)
def __check_group(self, group, minimal = True, batch = False, auto_answer = None):
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
def CheckGroups(self, groups_to_check = [], minimal = True, batch = False, auto_answer = None):
def CheckGroups(self, groups_to_check = [], minimal=True, batch=False, auto_answer=None):
def CheckGroups(self, groups_to_check = [], minimal = True, batch = False, auto_answer = None): """Check the groups, the cache. If not system, check the shared dir, the resps/guests, the members symlinks."""
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
def CheckGroupSymlinks(self, gid = None, group = None, oldname = None, delete = False, strip_prefix = None, batch = False, auto_answer = None):
def CheckGroupSymlinks(self, gid=None, group=None, oldname=None, delete=False, strip_prefix=None, batch=False, auto_answer=None):
def CheckGroupSymlinks(self, gid = None, group = None, oldname = None, delete = False, strip_prefix = None, batch = False, auto_answer = None): """For each member of a group, verify member has a symlink to the shared group dir inside his home (or under level 2 directory). If not, create the link. Eventually delete links pointing to the old group name if it is set."""
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
self.CheckGroups( [ name ], batch = True)
self.CheckGroups( [ name ], batch=True)
def SetSharedDirPermissiveness(self, name = None, permissive = True): """ Set permissive or not permissive the shared directory of the group 'name'. """ if name is None: raise exceptions.BadArgumentError, "You must specify a group name."
f37209229adf6c038cbf9bb8cdfd028d8ffe04c2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/f37209229adf6c038cbf9bb8cdfd028d8ffe04c2/groups.py
dir_info.dirs_perm = "%s,g:%s:rw-,%s,%s" % \
dir_info.dirs_perm = ("%s,g:%s:rw-,%s,%s" % \
def generate_dir_info(self, user_info=None, dir_info_base=None): """ generate a FsapiObject from the rule. This object will be understandable by fsapi """ acl=self.acl
570ec50971fe77441815f76a64ffc26f24c253ff /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/570ec50971fe77441815f76a64ffc26f24c253ff/classes.py
LMC.configuration.acls.file_acl_mask)
LMC.configuration.acls.file_acl_mask)).replace( '@UX','x').replace('@GX','x')
def generate_dir_info(self, user_info=None, dir_info_base=None): """ generate a FsapiObject from the rule. This object will be understandable by fsapi """ acl=self.acl
570ec50971fe77441815f76a64ffc26f24c253ff /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/570ec50971fe77441815f76a64ffc26f24c253ff/classes.py
def shutdown(uri, http_user, hostname=None, sure=False, warn_users=True, yes=None):
def shutdown(uri, http_user, hostname=None, sure=False, warn_users=True, yes=None, configuration=None, machines=None, **kwargs):
def shutdown(uri, http_user, hostname=None, sure=False, warn_users=True, yes=None): """ Export machine list.""" # submit button; forget it. del yes title = _("Shutdown machine %s") % hostname data = w.page_body_start(uri, http_user, ctxtnav, title) if not sure: description = _('''Are you sure you want to remotely shutdown ''' '''machine %s?''') % hostname form_options = w.checkbox("warn_users", "True", '<strong>' + _("Warn connected user(s) before shuting system down.") + '</strong>', True) data += w.question(_("Please confirm operation"), description, yes_values = [ _("Shutdown") + ' >>', "/machines/shutdown/%s/sure" % hostname, "S" ], no_values = [ '<< ' + _("Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: # we are sure, do it ! command = [ 'sudo', 'mod', 'machines', '--shutdown', '--no-colors' ] if warn_users: command.extend([ '--warn-users' ]) else: command.extend([ '--dont-warn-users' ]) command.extend([ '--hostname', hostname ]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to shutdown machine %s!''' % hostname))
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
active=None, warn_users=None, admin=None, yes=None):
active=None, warn_users=None, admin=None, yes=None, configuration=None, machines=None, **kwargs):
def massshutdown(uri, http_user, sure=False, asleep=None, idle=None, active=None, warn_users=None, admin=None, yes=None): """ Export machine list.""" # submit button; forget it. del yes title = _("Massive shutdown") data = w.page_body_start(uri, http_user, ctxtnav, title) if not sure: description = _('''You can shutdown all currently running and/or idle''' ''' machines. This is a quite dangerous operation, because users''' ''' will be disconnected, and there is a potential to loose ''' '''unsaved work on idle machines (users are not in front of''' ''' them, they won't notice the system is shuting down.<br />''' '''<br />Systems will be shut down <strong>ONE minute</strong> ''' '''after validation.''') form_options = '%s<br />%s<br />%s<br />%s<br /><br />%s' % ( w.checkbox("active", "True", _("Shutdown <strong>active</strong> machines"), True), w.checkbox("idle", "True", _("Shutdown <strong>idle</strong> machines"), True), w.checkbox("asleep", "True", _("Shutdown <strong>asleep</strong> machines"), True), w.checkbox("admin", "True", _("Shutdown the <strong>administrator</strong> machine too<br/>(the one currently connected to the WMI)."), False), w.checkbox("warn_users", "True", '<strong>' + _("Warn connected users before shuting systems down.") + '</strong>', True) ) data += w.question(_("Choose machines to shutdown"), description, yes_values = [ _("Shutdown") + ' >>', "/machines/massshutdown/sure", "S" ], no_values = [ '<< ' + _("Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: # we are sure, do it ! command = [ 'sudo', 'mod', 'machines', '--shutdown', '--no-colors' ] for option, argument in ( (asleep, '--asleep'), (idle, '--idle'), (active, '--active'), # not implemented yet #(no_admin, '--admin'), (warn_users, '--warn-users') ): if option: command.extend([argument]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to shutdown one or more machines!'''))
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
def energyprefs(uri, http_user):
def energyprefs(uri, http_user, configuration=None, machines=None, **kwargs):
def energyprefs(uri, http_user): """ Export machine list.""" # submit button; forget it. del yes title = _("Energy saving policies") if type == "": description = _('''CSV file-format is used by spreadsheets and most ''' '''systems which offer import functionnalities. XML file-format is a ''' '''modern exchange format, used in soma applications which respect ''' '''interoperability constraints.<br /><br />When you submit this ''' '''form, your web browser will automatically offer you to download ''' '''and save the export-file (it won't be displayed). When you're ''' '''done, please click the “back” button of your browser.''') form_options = \ _("Which file format do you want the machines list to be exported to? %s") \ % w.select("type", [ "CSV", "XML"]) data += w.question(_("Please choose file format for export list"), description, yes_values = [ _("Export >>"), "/machines/export", "E" ], no_values = [ _("<< Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: machines.Select(machines.FILTER_STANDARD) if type == "CSV": data = machines.ExportCSV() else: data = machines.ExportXML() return w.HTTP_TYPE_DOWNLOAD, (type, data)
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
def export(uri, http_user, type = "", yes = None):
def export(uri, http_user, type = "", yes=None, configuration=None, machines=None, **kwargs):
def export(uri, http_user, type = "", yes = None): """ Export machine list.""" # submit button; forget it. del yes return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Export machines list") data = '''<div id="banner"> %s %s</div> %s <div id="main"> %s <div id="content"> <h1>%s</h1>''' % ( w.backto(), w.metanav(http_user), w.menu(uri), ctxtnav(), title) if type == "": description = _('''CSV file-format is used by spreadsheets and most ''' '''systems which offer import functionnalities. XML file-format is a ''' '''modern exchange format, used in soma applications which respect ''' '''interoperability constraints.<br /><br />When you submit this ''' '''form, your web browser will automatically offer you to download ''' '''and save the export-file (it won't be displayed). When you're ''' '''done, please click the “back” button of your browser.''') form_options = \ _("Which file format do you want the machines list to be exported to? %s") \ % w.select("type", [ "CSV", "XML"]) data += w.question(_("Please choose file format for export list"), description, yes_values = [ _("Export >>"), "/machines/export", "E" ], no_values = [ _("<< Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: machines.Select(machines.FILTER_STANDARD) if type == "CSV": data = machines.ExportCSV() else: data = machines.ExportXML() return w.HTTP_TYPE_DOWNLOAD, (type, data)
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
def forget(uri, http_user, hostname, sure=False, yes=None):
def forget(uri, http_user, hostname, sure=False, yes=None, configuration=None, machines=None, **kwargs):
def forget(uri, http_user, hostname, sure=False, yes=None): """remove machine account.""" # form submit button, forget it. del yes return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Remove machine %s's record") % hostname if protected_user(hostname): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title) if not sure: data += w.question( _("Are you sure you want to remove record for machine <strong>%s</strong>?") \ % hostname, _('''User's <strong>personnal data</strong> (his/her HOME dir) ''' '''will be <strong>archived</strong> in directory <code>%s</code>''' ''' and members of group <strong>%s</strong> will be able to ''' ''' access it to operate an eventual recover.<br />However, you ''' '''can decide to permanently remove it.''') % ( configuration.home_archive_dir, configuration.defaults.admin_group), yes_values = \ [ _("Remove >>"), "/machines/delete/%s/sure" % hostname, _("R") ], no_values = \ [ _("<< Cancel"), "/machines/list", _("C") ], form_options = w.checkbox("no_archive", "True", _("Definitely remove record data (no archiving)."), checked = False) ) return (w.HTTP_TYPE_TEXT, w.page(title, data + w.page_body_end())) else: # we are sure, do it ! command = [ 'sudo', 'del', 'machine', '--quiet', '--no-colors', '--hostname', hostname ] if no_archive: command.extend(['--no-archive']) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to remove record <strong>%s</strong>!''') % hostname)
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
def new(uri, http_user):
def new(uri, http_user, configuration=None, machines=None, **kwargs):
def new(uri, http_user): """Generate a form to create a new machine on the system.""" return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("New machine record") data = w.page_body_start(uri, http_user, ctxtnav, title, False) def profile_input(): #TODO: To be rewritten ? return """ <tr> <td><strong>%s</strong></td> <td class="right">
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
create = None ):
create=None, configuration=None, machines=None, **kwargs):
def create(uri, http_user, loginShell, password, password_confirm, profile=None, hostname="", gecos="", firstname="", lastname="", standard_groups_dest=[], privileged_groups_dest=[], responsible_groups_dest=[], guest_groups_dest=[], standard_groups_source=[], privileged_groups_source=[], responsible_groups_source=[], guest_groups_source=[], create = None ): # forget it; useless del create return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("New machine record %s") % hostname data = w.page_body_start(uri, http_user, ctxtnav, title, False) if password != password_confirm: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error(_("Passwords do not match!%s") % rewind))) if len(password) < configuration.users.min_passwd_size: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error(_("Password must be at least %d characters long!%s")\ % (configuration.users.min_passwd_size, rewind)))) command = [ "sudo", "add", "machine", '--quiet', '--no-colors', '--password', password ] if firstname != '' and lastname != '': command.extend(['--firstname', firstname, '--lastname', lastname]) if gecos != '': command.extend(['--gecos', gecos]) # TODO: set a default profile (see issue #6) if profile != None: command.extend([ "--profile", profile ]) if hostname != "": command.extend([ "--hostname", hostname ]) else: # TODO: Idem, "gecos" should be tested against emptyness command.extend([ '--hostname', hlstr.validate_name(gecos).replace('_', '.').rstrip('.') ]) (rettype, retdata) = w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to create record <strong>%s</strong>!''') % hostname) if rettype == w.HTTP_TYPE_TEXT: return (rettype, retdata) # else: continue the creation by adding groups… command = [ "sudo", "mod", "machine", '--quiet', "--no-colors", "--hostname", hostname, "--shell", loginShell ] add_groups = ','.join(__merge_multi_select( standard_groups_dest, privileged_groups_dest, responsible_groups_dest, guest_groups_dest)) if add_groups != "": command.extend([ '--add-groups', add_groups ]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to add machine <strong>%s</strong> to requested groups/privileges/responsibilities/invitations!''') % hostname)
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
def edit(uri, http_user, hostname):
def edit(uri, http_user, hostname, configuration=None, machines=None, **kwargs):
def edit(uri, http_user, hostname): """Edit an machine record, based on hostname.""" return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Edit %s's record") % hostname if protected_user(hostname): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: machine = machines.machines[machines.hostname_to_mid(hostname)] try: profile = \ profiles.profiles[ groups.groups[machine['gidNumber']]['name'] ]['name'] except KeyError: profile = _("Standard account") dbl_lists = {} for filter, titles, id in groups_filters_lists_ids: dest = list(machine['groups'].copy()) source = [ groups.groups[gid]['name'] \ for gid in groups.Select(filter) ] for current in dest[:]: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[filter] = w.doubleListBox(titles, id, source, dest) form_name = "user_edit_form" data += '''<div id="edit_form">
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
record = None):
record=None, configuration=None, machines=None, **kwargs):
def record(uri, http_user, hostname, loginShell=None, password = "", password_confirm = "", firstname = "", lastname = "", gecos = "", standard_groups_source = [], standard_groups_dest = [], privileged_groups_source = [], privileged_groups_dest = [], responsible_groups_source = [], responsible_groups_dest = [], guest_groups_source = [], guest_groups_dest = [], record = None): """Record machine changes.""" # submit button. forget it. del record return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Modification of %s's record") % hostname if protected_user(hostname): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title, False) command = [ "sudo", "mod", "machine", '--quiet', "--no-colors", "--hostname", hostname, "--shell", loginShell ] if password != "": if password != password_confirm: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error(_("Passwords do not match!%s") % rewind))) if len(password) < configuration.users.min_passwd_size: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error( _("The password --%s-- must be at least %d characters long!%s")\ % (password, configuration.users.min_passwd_size, rewind)))) command.extend([ '--password', password ]) command.extend( [ "--gecos", gecos ] ) add_groups = ','.join(__merge_multi_select( standard_groups_dest, privileged_groups_dest, responsible_groups_dest, guest_groups_dest)) del_groups = ','.join(__merge_multi_select( standard_groups_source, privileged_groups_source, responsible_groups_source, guest_groups_source)) if add_groups != "": command.extend([ '--add-groups', add_groups ]) if del_groups != "": command.extend(['--del-groups', del_groups ]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to modify one or more parameters of record <strong>%s</strong>!''') % hostname)
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
def main(uri, http_user, sort = "hostname", order = "asc"):
def main(uri, http_user, sort="hostname", order="asc", configuration=None, machines=None, **kwargs):
def main(uri, http_user, sort = "hostname", order = "asc"): """ display all machines in a nice HTML page. """ start = time.time() m = machines.machines accounts = {} ordered = {} totals = { _('managed'): 0, _('floating'): 0 } title = _("Machines") data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>' for (sortcolumn, sortname) in ( ("status", _("Status")), ("hostname", _("Host name")), ("ip", _("IP address")), ("ether", _("Hardware address")), ("expiry", _("Expiry")), ("managed", _("Managed")) ): if sortcolumn == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s order image" />&#160; <a href="/machines/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, order, sortcolumn, reverseorder, _("Click to sort in reverse order."), sortname) else: data += ''' <th> <a href="/machines/list/%s/asc" title="%s">%s</a> </th>\n''' % (sortcolumn, _("Click to sort on this column."), sortname) data += ' </tr>\n' def html_build_compact(index, accounts = accounts): mid = ordered[index] hostname = m[mid]['hostname'] edit = 'machine %s (IP %s)' % (hostname, m[mid]['ip']) if m[mid]['managed']: totals[_('managed')] += 1 else: totals[_('floating')] += 1 power_statuses = { host_status.UNKNOWN: (None, 'unknown', _('''Host %s is in an unknown state. Nothing is possible. ''' '''Please wait for a reconnection.''')), host_status.OFFLINE: (None, 'offline', _('''Host %s is offline, and cannot be powered on from here,''' '''Only from the machine itself.''')), host_status.ASLEEP: ('shutdown', 'asleep', _('Shutdown the machine %s')), host_status.IDLE: ('shutdown', 'idle', _('Shutdown the machine %s')), host_status.ACTIVE: ('shutdown', 'active', _('Shutdown the machine %s')), } status = m[mid]['status'] if power_statuses[status][0]: html_data = ''' <tr class="userdata"> <!-- STATUS --> <td class="user_action_center"> <a href="/machines/%s/%s" title="%s" class="%s"> <span class="delete-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span></a> </td>''' % ( power_statuses[status][0], hostname, power_statuses[status][2] % hostname, power_statuses[status][1] ) else: html_data = ''' <tr class="userdata"> <!-- STATUS --> <td class="user_action_center"> <span class="%s" title="%s">&nbsp;&nbsp;&nbsp;&nbsp;</span> </td>''' % ( power_statuses[status][1], power_statuses[status][2] % hostname) html_data += ''' <!-- HOSTNAME --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s%s</a> </td> <!-- IP --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s</a> </td> <!-- ETHER --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s</a> </td> <!-- EXPIRY --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s</a> </td> ''' % ( hostname, edit, hostname, '''&nbsp;<img src='/images/16x16/alt.png' alt='%s' />''' % _('This machine is an ALT® client.') if machines.is_alt(mid) else '', hostname, edit, m[mid]['ip'], hostname, edit, m[mid]['ether'], hostname, edit, format_time_delta( float(m[mid]['expiry']) - time.time(), use_neg=True) \ if m[mid]['expiry'] else '-' ) if m[mid]['managed']: html_data += ''' <!-- MANAGED --> <td class="user_action_center"> <a href="/machines/unmanage/%s" title="%s" class="managed"> <span class="delete-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span></a> </td> ''' % (hostname, _("""Unmanage machine (remove it from """ """configuration, in order to allow it to be managed by """ """another server.""")) else: html_data += ''' <!-- UNMANAGED --> <td class="user_action_center"> <a href="/machines/manage/%s" title="%s" class="floating"> <span class="delete-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span></a> </td> ''' % (hostname, _("""Manage machine (fix its IP address and """ """configure various aspects of the client).""")) return html_data for mid in machines.keys(): machine = m[mid] hostname = machine['hostname'] # we add the hostname to gecosValue and lockedValue to be sure to obtain # unique values. This prevents problems with empty or non-unique GECOS # and when sorting on locked status (accounts would be overwritten and # lost because sorting must be done on unique values). accounts[mid] = { 'status' : str(machine['status']) + hostname, 'hostname': hostname, 'ip' : machine['ip'], 'ether' : machine['ether'], 'expiry' : machine['expiry'], 'managed' : str(machine['managed']) + hostname } # index on the column choosen for sorting, and keep trace of the mid # to find account data back after ordering. ordered[hlstr.validate_name(accounts[mid][sort])] = mid memberkeys = ordered.keys() memberkeys.sort() if order == "desc": memberkeys.reverse() data += ''.join(map(html_build_compact, memberkeys)) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="5" class="total_left">%s</td> <td class="total_right">%d</td> </tr> ''' % (_("number of <strong>%s</strong> machines:") % total, totals[total]) return output data += ''' <tr> <td colspan="5">&#160;</td></tr> %s <tr class="list_total"> <td colspan="5" class="total_left">%s</td> <td class="total_right">%d</td> </tr>
5c6e0536d2363f635c0b43a50e8af7ca9d102236 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/5c6e0536d2363f635c0b43a50e8af7ca9d102236/machines.py
groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, '& (configuration.groups.guest_prefix + name, None, '& )
groups_filters_lists_ids = [ (name, [ _('Manage members'), _('Users not yet members'), _('Current members') ], 'members' ) ]
def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, '&#160;' ), (configuration.groups.guest_prefix + name, None, '&#160;' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form">
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
(name, [_('Manage members'),
(name, [_('Manage members'),
def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, '&#160;' ), (configuration.groups.guest_prefix + name, None, '&#160;' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form">
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
dest = list(g[groups.name_to_gid(gname)]['memberUid'])
dest = list(group['memberUid'])
def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, '&#160;' ), (configuration.groups.guest_prefix + name, None, '&#160;' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form">
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current)
for current in group['memberUid']: try: source.remove(current) except ValueError: dest.remove(current)
def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, '&#160;' ), (configuration.groups.guest_prefix + name, None, '&#160;' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form">
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
if system: return '' else: return '''
return '' if system else \ '''
def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename))
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
if system: return '' else: return '''
return '' if system else \ '''
def permissive(perm, system):
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
<h2 class="accordion_toggle">≫&nbsp;%s</h2> <div class="accordion_content">%s</div> <h2 class="accordion_toggle">≫&nbsp;%s</h2> <div class="accordion_content">%s</div>
%s
def permissive(perm, system):
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
_('Group responsibles'), dbl_lists[configuration.groups.resp_prefix+name], _('Group guests'), dbl_lists[configuration.groups.guest_prefix+name],
data_rsp_gst,
def permissive(perm, system):
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
for member in groups.groups[gid]['memberUid']:
for member in group['memberUid']:
def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />&#160; <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['groupSkel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: if not users.is_system_login(member): tgroups[gid]['memberUid'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['memberUid']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['groupSkel']) if groups.is_system_gid(gid): html_data += '<td>&#160;</td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong>&#160;<img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td>&#160;</td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1">&#160;</td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6">&#160;</td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr>
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
tgroups[gid][prefix + 'members'] = []
tgroups[gid][prefix + 'memberUid'] = []
def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />&#160; <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['groupSkel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: if not users.is_system_login(member): tgroups[gid]['memberUid'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['memberUid']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['groupSkel']) if groups.is_system_gid(gid): html_data += '<td>&#160;</td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong>&#160;<img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td>&#160;</td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1">&#160;</td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6">&#160;</td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr>
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
tgroups[gid][prefix + 'members'].append(
tgroups[gid][prefix + 'memberUid'].append(
def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />&#160; <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['groupSkel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: if not users.is_system_login(member): tgroups[gid]['memberUid'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['memberUid']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['groupSkel']) if groups.is_system_gid(gid): html_data += '<td>&#160;</td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong>&#160;<img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td>&#160;</td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1">&#160;</td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry">&nbsp;&nbsp;&nbsp;&nbsp;</span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6">&#160;</td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr>
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ):
('memberUid', _('Current members')), ('rsp-memberUid', _('Current responsibles')), ('gst-memberUid', _('Current guests')) ):
def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = '''
b115301aa7a3230e2ebf55808ae6e08d4c08f2cc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/b115301aa7a3230e2ebf55808ae6e08d4c08f2cc/groups.py
if prim_memb != []:
if prim_memb != set():
def DeleteGroup(self, name, del_users, no_archive, bygid = None, batch=False): """ Delete an Licorn group """ if name is None and bygid is None: raise exceptions.BadArgumentError, "You must specify a name or a GID."
c27b6e04ed14edea434836815f36e1d3d68ed523 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/c27b6e04ed14edea434836815f36e1d3d68ed523/groups.py
return GroupsController.is_standard_gid(gid) and GroupsController.groups[gid]['memberUid'] == []
return GroupsController.is_standard_gid(gid) and GroupsController.groups[gid]['memberUid'] == set()
def is_empty_gid(gid): return GroupsController.is_standard_gid(gid) and GroupsController.groups[gid]['memberUid'] == []
c27b6e04ed14edea434836815f36e1d3d68ed523 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/c27b6e04ed14edea434836815f36e1d3d68ed523/groups.py
def get_groups(self, opts, args): """ Get the list of POSIX LMC.groups (can be LDAP). """
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.warning("can't automatically detect the file encoding, assuming iso-8859-15 !")
logging.warning("can't automatically detect the file encoding, assuming iso-8859-15!")
def clean_csv_field(field): return field.replace("'","").replace('"','')
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
def clean_csv_field(field): return field.replace("'","").replace('"','')
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
def clean_csv_field(field): return field.replace("'","").replace('"','')
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
def clean_csv_field(field): return field.replace("'","").replace('"','')
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
def clean_csv_field(field): return field.replace("'","").replace('"','')
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
def clean_csv_field(field): return field.replace("'","").replace('"','')
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
def desimport_groups(self, opts, args): """ Delete the groups (and theyr members) present in a import file. """
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to delete all users ?',
'Are you sure you want to delete all users?',
def del_user(self, opts, args): """ delete a user account. """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid), ([os.getuid()], LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_del = self.select(LMC.users, 'user', args=args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid)
(LMC.users.Select(filters.STD), lambda x: x), (LMC.users.Select(filters.SYSUNRSTR), lambda x: x)
def del_user(self, opts, args): """ delete a user account. """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid), ([os.getuid()], LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_del = self.select(LMC.users, 'user', args=args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Delete user %s ?''' % stylize(
logging.ask_for_repair('''Delete user %s?''' % stylize(
def del_user(self, opts, args): """ delete a user account. """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid), ([os.getuid()], LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_del = self.select(LMC.users, 'user', args=args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to delete all groups ?',
'Are you sure you want to delete all groups?',
def del_group(self, opts, args): """ delete an Licorn group. """ selection = filters.NONE if opts.empty: selection = filters.EMPTY include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid), ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_del = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists = exclude_id_lists, default_selection=selection) for gid in gids_to_del: if opts.non_interactive or opts.batch or opts.force or \ logging.ask_for_repair('''Delete group %s ?''' % stylize( ST_LOGIN,LMC.groups.gid_to_name(gid)), auto_answer=opts.auto_answer): LMC.groups.DeleteGroup(gid=gid, del_users=opts.del_users, no_archive=opts.no_archive) #logging.notice("Deleting group : %s" % LMC.groups.gid_to_name(gid))
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid)
(LMC.groups.Select(filters.STD), lambda x: x), (LMC.groups.Select(filters.SYSUNRSTR), lambda x: x)
def del_group(self, opts, args): """ delete an Licorn group. """ selection = filters.NONE if opts.empty: selection = filters.EMPTY include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid), ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_del = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists = exclude_id_lists, default_selection=selection) for gid in gids_to_del: if opts.non_interactive or opts.batch or opts.force or \ logging.ask_for_repair('''Delete group %s ?''' % stylize( ST_LOGIN,LMC.groups.gid_to_name(gid)), auto_answer=opts.auto_answer): LMC.groups.DeleteGroup(gid=gid, del_users=opts.del_users, no_archive=opts.no_archive) #logging.notice("Deleting group : %s" % LMC.groups.gid_to_name(gid))
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Delete group %s ?''' % stylize(
logging.ask_for_repair('''Delete group %s?''' % stylize(
def del_group(self, opts, args): """ delete an Licorn group. """ selection = filters.NONE if opts.empty: selection = filters.EMPTY include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid), ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_del = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists = exclude_id_lists, default_selection=selection) for gid in gids_to_del: if opts.non_interactive or opts.batch or opts.force or \ logging.ask_for_repair('''Delete group %s ?''' % stylize( ST_LOGIN,LMC.groups.gid_to_name(gid)), auto_answer=opts.auto_answer): LMC.groups.DeleteGroup(gid=gid, del_users=opts.del_users, no_archive=opts.no_archive) #logging.notice("Deleting group : %s" % LMC.groups.gid_to_name(gid))
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to delete all profiles ?',
'Are you sure you want to delete all profiles?',
def del_profile(self, opts, args): """ Delete a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ])
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier)
(LMC.profiles.Select(filters.ALL), lambda x: x)
def del_profile(self, opts, args): """ Delete a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ])
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Delete profile %s ?''' %
logging.ask_for_repair('''Delete profile %s?''' %
def del_profile(self, opts, args): """ Delete a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ])
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to delete all users ?',
'Are you sure you want to delete all privileges?',
def del_privilege(self, opts, args): if opts.privileges_to_remove is None and len(args) == 2: opts.privileges_to_remove = args[1] include_priv_lists=[ (opts.privileges_to_remove, LMC.privileges.confirm_privilege), ] exclude_priv_lists=[ (opts.exclude, LMC.privileges.confirm_privilege), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_priv_lists.extend([ (LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege), ]) privs_to_del = self.select(LMC.privileges, 'privilege',args=args, include_id_lists=include_priv_lists, exclude_id_lists=exclude_priv_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege),
(LMC.privileges.Select(filters.ALL), lambda x: x),
def del_privilege(self, opts, args): if opts.privileges_to_remove is None and len(args) == 2: opts.privileges_to_remove = args[1] include_priv_lists=[ (opts.privileges_to_remove, LMC.privileges.confirm_privilege), ] exclude_priv_lists=[ (opts.exclude, LMC.privileges.confirm_privilege), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_priv_lists.extend([ (LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege), ]) privs_to_del = self.select(LMC.privileges, 'privilege',args=args, include_id_lists=include_priv_lists, exclude_id_lists=exclude_priv_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Delete privilege %s ?''' %
logging.ask_for_repair('''Delete privilege %s?''' %
def del_privilege(self, opts, args): if opts.privileges_to_remove is None and len(args) == 2: opts.privileges_to_remove = args[1] include_priv_lists=[ (opts.privileges_to_remove, LMC.privileges.confirm_privilege), ] exclude_priv_lists=[ (opts.exclude, LMC.privileges.confirm_privilege), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_priv_lists.extend([ (LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege), ]) privs_to_del = self.select(LMC.privileges, 'privilege',args=args, include_id_lists=include_priv_lists, exclude_id_lists=exclude_priv_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to modify all users ?',
'Are you sure you want to modify all users?',
def mod_user(self, opts, args): """ Modify a POSIX user account (Samba / LDAP included). """
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Modify user %s ?''' % stylize(
logging.ask_for_repair('''Modify user %s?''' % stylize(
def mod_user(self, opts, args): """ Modify a POSIX user account (Samba / LDAP included). """
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'''about user(s) ? Use --help to know !''')
'''about user(s)? Use --help to know!''')
def mod_user(self, opts, args): """ Modify a POSIX user account (Samba / LDAP included). """
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to modify all groups ?',
'Are you sure you want to modify all groups?',
def mod_group(self, opts, args): """ Modify a group. """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_mod = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid)
(LMC.groups.Select(filters.STD), lambda x: x), (LMC.groups.Select(filters.SYSUNRSTR), lambda x: x)
def mod_group(self, opts, args): """ Modify a group. """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_mod = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Modify group %s ?''' % stylize(
logging.ask_for_repair('''Modify group %s?''' % stylize(
def mod_group(self, opts, args): """ Modify a group. """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_mod = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to modify all profiles ?',
'Are you sure you want to modify all profiles?',
def mod_profile(self, opts, args): """ Modify a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ]), profiles_to_mod = self.select(LMC.profiles, 'profile', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier)
(LMC.profiles.Select(filters.ALL), lambda x: x)
def mod_profile(self, opts, args): """ Modify a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ]), profiles_to_mod = self.select(LMC.profiles, 'profile', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Modify profile %s ?''' % stylize(
logging.ask_for_repair('''Modify profile %s?''' % stylize(
def mod_profile(self, opts, args): """ Modify a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ]), profiles_to_mod = self.select(LMC.profiles, 'profile', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
"what do you want to modify ? use --help to know !")
"what do you want to modify? use --help to know!")
def mod_configuration(self, opts, args): """ Modify some aspects or abstract directives of the system configuration (use with caution)."""
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to check all users ?',
'Are you sure you want to check all users?',
def chk_user(self, opts, args): """ Check one or more user account(s). """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to check all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_chk = self.select(LMC.users, 'user', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid)
(LMC.users.Select(filters.STD), lambda x: x), (LMC.users.Select(filters.SYSUNRSTR), lambda x: x)
def chk_user(self, opts, args): """ Check one or more user account(s). """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to check all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_chk = self.select(LMC.users, 'user', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
if logging.ask_for_repair('''Check user %s ?''' %
if logging.ask_for_repair('''Check user %s?''' %
def chk_user(self, opts, args): """ Check one or more user account(s). """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to check all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_chk = self.select(LMC.users, 'user', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to check all groups ?',
'Are you sure you want to check all groups?',
def chk_group(self, opts, args): """ Check one or more group(s). """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to check all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_chk = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists, default_selection=filters.STD, all=opts.all)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid)
(LMC.groups.Select(filters.STD), lambda x: x), (LMC.groups.Select(filters.SYSUNRSTR), lambda x: x)
def chk_group(self, opts, args): """ Check one or more group(s). """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to check all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_chk = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists, default_selection=filters.STD, all=opts.all)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
if logging.ask_for_repair('''Check group %s ?''' %
if logging.ask_for_repair('''Check group %s?''' %
def chk_group(self, opts, args): """ Check one or more group(s). """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to check all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_chk = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists, default_selection=filters.STD, all=opts.all)
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
'Are you sure you want to delete all profiles ?',
'Are you sure you want to delete all profiles?',
def chk_profile(self, opts, args): """ TODO: to be implemented. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ])
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
(LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier)
(LMC.profiles.Select(filters.ALL), lambda x: x)
def chk_profile(self, opts, args): """ TODO: to be implemented. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ])
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
logging.ask_for_repair('''Delete profile %s ?''' % stylize(
logging.ask_for_repair('''Delete profile %s?''' % stylize(
def chk_profile(self, opts, args): """ TODO: to be implemented. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ])
a1acd345c6b587c46acec53d660359e9c2c78c73 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a1acd345c6b587c46acec53d660359e9c2c78c73/rwi.py
""" Display a styles.stylized error message and exit badly. """
""" Display a stylized error message and exit badly. """
def error(mesg, returncode=1, full=False, tb=None, listener=None): """ Display a styles.stylized error message and exit badly. """ if full: if tb: sys.stderr.write(tb + '\n') else: import traceback sys.stderr.write ('''>>> %s: ''' % (styles.stylize(styles.ST_OK, "Call trace"))) traceback.print_tb( sys.exc_info()[2] ) sys.stderr.write("\n") sys.stderr.write('%s %s %s\n' % ( styles.stylize(styles.ST_BAD, 'ERROR:'), mytime(), mesg)) raise SystemExit(returncode)
a4712f82b2f0d14c0f1c465fc523b05667dfb57d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a4712f82b2f0d14c0f1c465fc523b05667dfb57d/logging.py
''' % (styles.stylize(styles.ST_OK, "Call trace")))
''' % (stylize(ST_OK, "Call trace")))
def error(mesg, returncode=1, full=False, tb=None, listener=None): """ Display a styles.stylized error message and exit badly. """ if full: if tb: sys.stderr.write(tb + '\n') else: import traceback sys.stderr.write ('''>>> %s: ''' % (styles.stylize(styles.ST_OK, "Call trace"))) traceback.print_tb( sys.exc_info()[2] ) sys.stderr.write("\n") sys.stderr.write('%s %s %s\n' % ( styles.stylize(styles.ST_BAD, 'ERROR:'), mytime(), mesg)) raise SystemExit(returncode)
a4712f82b2f0d14c0f1c465fc523b05667dfb57d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a4712f82b2f0d14c0f1c465fc523b05667dfb57d/logging.py
styles.stylize(styles.ST_BAD, 'ERROR:'),
stylize(ST_BAD, 'ERROR:'),
def error(mesg, returncode=1, full=False, tb=None, listener=None): """ Display a styles.stylized error message and exit badly. """ if full: if tb: sys.stderr.write(tb + '\n') else: import traceback sys.stderr.write ('''>>> %s: ''' % (styles.stylize(styles.ST_OK, "Call trace"))) traceback.print_tb( sys.exc_info()[2] ) sys.stderr.write("\n") sys.stderr.write('%s %s %s\n' % ( styles.stylize(styles.ST_BAD, 'ERROR:'), mytime(), mesg)) raise SystemExit(returncode)
a4712f82b2f0d14c0f1c465fc523b05667dfb57d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a4712f82b2f0d14c0f1c465fc523b05667dfb57d/logging.py
"""Display a styles.stylized warning message on stderr."""
"""Display a stylized warning message on stderr."""
def warning(mesg, once=False, listener=None): """Display a styles.stylized warning message on stderr.""" if once: try: already_displayed = __warningsdb[mesg] return except KeyError, e: __warningsdb[mesg] = True text_message = "%s%s %s\n" % ( styles.stylize(styles.ST_WARNING, '/!\\'), mytime(), mesg) if listener: listener.process( LicornMessage(data=text_message), options.msgproc.getProxy()) sys.stderr.write(text_message)
a4712f82b2f0d14c0f1c465fc523b05667dfb57d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a4712f82b2f0d14c0f1c465fc523b05667dfb57d/logging.py
styles.stylize(styles.ST_WARNING, '/!\\'), mytime(), mesg)
stylize(ST_WARNING, '/!\\'), mytime(), mesg)
def warning(mesg, once=False, listener=None): """Display a styles.stylized warning message on stderr.""" if once: try: already_displayed = __warningsdb[mesg] return except KeyError, e: __warningsdb[mesg] = True text_message = "%s%s %s\n" % ( styles.stylize(styles.ST_WARNING, '/!\\'), mytime(), mesg) if listener: listener.process( LicornMessage(data=text_message), options.msgproc.getProxy()) sys.stderr.write(text_message)
a4712f82b2f0d14c0f1c465fc523b05667dfb57d /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/7650/a4712f82b2f0d14c0f1c465fc523b05667dfb57d/logging.py