def userdel(force, remove, config, login): user = None try: user = pwd.getpwnam(login) except KeyError: print(_("Error: User not found")) exit(1) conf = get_config(config) dbs = connect_db(conf) pm = UserManager(config=conf, dbs=dbs) try: pm.deluser(username=login) except KeyError: print(_("Error: User not in database")) exit(1) if remove: shutil.rmtree(str(user.pw_dir), ignore_errors=force) glm = GroupListManager(conf, dbs) glm.delallgroupuser(login) dbs.commit() gr = None try: gr = grp.getgrgid(user.pw_gid) if gr.gr_mem: exit(0) except KeyError: dbs.commit() dbs.close() exit(0) gm = GroupManager(config=conf, dbs=dbs) try: gm.delgroup(gid=str(gr.gr_gid)) except ValueError: print( _('Warning: Primary group "{group}" of user is empty but not in Database. Try "groupdel {group}"').format( group=gr.gr_gid ) ) exit(1) dbs.commit() dbs.close()
def userdel(force, remove, config, login): user = None try: user = pwd.getpwnam(login) except KeyError: print(_("Error: User not found")) exit(1) conf = get_config(config) dbs = connect_db(conf) pm = UserManager(config=conf, dbs=dbs) try: pm.deluser(username=login) except KeyError: print(_("Error: User not in database")) exit(1) if remove: shutil.rmtree(str(user.pw_dir), ignore_errors=force) glm = GroupListManager(conf, dbs) glm.delallgroupuser(login) dbs.commit() gr = None try: gr = grp.getgrgid(user.pw_gid) if gr.gr_mem: exit(0) except KeyError: dbs.commit() dbs.close() exit(0) gm = GroupManager(config=conf, dbs=dbs) try: gm.delgroup(gid=str(gr.gr_gid)) except ValueError: print( _('Warning: Primary group "{group}" of user is empty but not in Database. Try "groupdel {group}"' ).format(group=gr.gr_gid)) exit(1) dbs.commit() dbs.close()
def groupdel(config, group): try: gr = grp.getgrnam(group) except KeyError: print("Error: Group not found") exit(1) return conf = get_config(config) dbs = connect_db(conf) gm = GroupManager(config=conf, dbs=dbs) try: gm.delgroup(gid=str(gr.gr_gid)) except KeyError as e: print("Error: %s" % e) exit(1) dbs.commit() dbs.close()
def groupdel(config, group): try: gr = grp.getgrnam(group) except KeyError: print("Error: Group not found") exit(1) return conf = get_config(config) dbs = connect_db(conf) gm = GroupManager(config=conf, dbs=dbs) try: gm.delgroup(gid=str(gr.gr_gid)) except KeyError as e: print("Error: %s" % e) exit(1) dbs.commit() dbs.close()