def project_user_add(pid, uid, role): if is_user_member(pid, uid): project_user_remove(pid, uid) proot = path.join(storage_facade.USERS_ROOT_DIR, user_facade.nels_id_to_username(uid), "Projects") plink = project_link_path(pid, uid) run_utils.launch_cmd( "/usr/sbin/pw groupmod -n %s -m %s" % (role_to_group(pid, role), user_facade.nels_id_to_username(uid))) run_utils.launch_cmd("/bin/chflags -h nosimmutable,nosunlink %s" % proot) run_utils.launch_cmd("/bin/ln -s -f -h %s %s " % (path.join( storage_facade.PROJECTS_ROOT_DIR, project_id_to_name(pid)), plink)) run_utils.launch_cmd("/bin/chflags -h simmutable,sunlink %s" % proot)
def project_user_remove(pid, uid): if not is_user_member(pid, uid): run_utils.exit_fail("User is not a member of the project") proot = path.join(storage_facade.USERS_ROOT_DIR, user_facade.nels_id_to_username(uid), "Projects") plink = project_link_path(pid, uid) for role in ["member", "poweruser", "admin"]: run_utils.launch_cmd( "/usr/sbin/pw groupmod -n %s -d %s " % (role_to_group(pid, role), user_facade.nels_id_to_username(uid))) if path.exists(plink): run_utils.launch_cmd("/bin/chflags -h nosimmutable,nosunlink %s" % proot) run_utils.launch_cmd("/bin/rm -f %s " % plink) run_utils.launch_cmd("/bin/chflags -h simmutable,sunlink %s" % proot)
(options, args) = parser.parse_args() feed_utils.VERBOSE = options.verbose args_utils.require_args_length(parser, args, 1) args_utils.require_arg_number(parser, args, 0, "project_id") pid = args[0] config.init() feed_utils.heading("project info") if not project_facade.project_exists(pid): run_utils.exit_fail("project not found") feed_utils.ok("project found\nname:\t%s\nhome folder:\t%s" % (project_facade.project_name_by_id(pid), project_facade.project_home(pid))) feed_utils.push_in() for role in [ project_facade.MembershipRoles.ADMIN, project_facade.MembershipRoles.POWERUSER, project_facade.MembershipRoles.MEMBER ]: feed_utils.push_in() members = project_facade.project_members(pid, role) feed_utils.info("role:\t%s (members count: %s)" % (role, len(members))) for uid in members: feed_utils.info("\tnels_id:\t%s\tusername:\t%s" % (uid, user_facade.nels_id_to_username(uid))) feed_utils.push_out()
from optparse import OptionParser import config from facades import user_facade from utils import feed_utils, args_utils, run_utils if __name__ == "__main__": usage = 'usage: %prog [options] nels_id' version = '%prog 1.0' parser = OptionParser(usage=usage, version=version) parser.add_option('-v', '--verbose', dest="verbose", action="store_true", help='turn verbosity on', default=False) # get options and arguments (options, args) = parser.parse_args() feed_utils.VERBOSE = options.verbose args_utils.require_args_length(parser, args, 1) args_utils.require_arg_number(parser, args, 0, "nels_id") nels_id = args[0] config.init() feed_utils.heading("user info") if not user_facade.user_exists(nels_id): run_utils.exit_fail("user not found") feed_utils.ok("user found\nnels-id:\t%s\nusername:\t%s\nhome folder:\t%s" % ( nels_id, user_facade.nels_id_to_username(nels_id), user_facade.user_home(nels_id)))
if __name__ == "__main__": usage = 'usage: %prog [options] nels_id link_to_clean' version = '%prog 1.0' parser = OptionParser(usage=usage, version=version) parser.add_option('-v', '--verbose', dest="verbose", action="store_true", help='turn verbosity on', default=False) # get options and arguments (options, args) = parser.parse_args() feed_utils.VERBOSE = options.verbose args_utils.require_args_length(parser, args, 2) args_utils.require_arg_number(parser, args, 0, "nels_id") config.init() proot = path.join(storage_facade.USERS_ROOT_DIR, user_facade.nels_id_to_username(int(args[0])), "Projects") plink = path.join(proot, args[1]) if not path.exists(plink): run_utils.exit_fail("symbolic link not found") # unlock folder, remove link and lock folder again run_utils.launch_cmd("/bin/chflags -h nosimmutable,nosunlink %s" % proot) run_utils.launch_cmd("/bin/rm -f %s " % plink) run_utils.launch_cmd("/bin/chflags -h simmutable,sunlink %s" % proot) #verify if path.exists(plink): feed_utils.failed("link still exists") else: feed_utils.ok("link removed successfully")
def project_link_path(pid, uid): return path.join(storage_facade.USERS_ROOT_DIR, user_facade.nels_id_to_username(uid), "Projects", project_name_by_id(pid))