示例#1
0
文件: users.py 项目: kdart/routerapp
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)
示例#2
0
文件: users.py 项目: kdart/routerapp
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)