def newpass(argv): """Change a users' password. newpass [--password=<newpass>] <username> """ try: opts, longopts, args = getopt.getopt(argv[1:], "h?") except getopt.GetoptError: print(newpass.__doc__) return for opt, optarg in opts: if opt in ("-?", "-h"): print(newpass.__doc__) return try: username = args[0] except IndexError: username = cliutils.get_input("Account name? ") password = longopts.get("password") if not password: password = ask_password() if not password: print("Passwords do not match, exiting.", file=sys.stderr) return user = models.query(models.User, username=username).one() user.password = password models.commit() update_shadow(username, password)
def deleteuser(argv): """Delete a user deleteuser <username> """ try: opts, longopts, args = getopt.getopt(argv[1:], "h?") except getopt.GetoptError: print(deleteuser.__doc__) return for opt, optarg in opts: if opt in ("-?", "-h"): print(deleteuser.__doc__) return try: username = args[0] except IndexError: username = cliutils.get_input("Account name? ") user = models.query(models.User, username=username).one() models.delete(user) models.close() delete_shadow(username) shutil.rmtree(user.home, ignore_errors=True)