def adduser(argv): import auth parser = argparse.ArgumentParser( description="Critic administration interface: adduser", prog="criticctl [options] adduser") parser.add_argument("--name", help="user name") parser.add_argument("--email", "-e", help="email address") parser.add_argument("--fullname", "-f", help="full name") parser.add_argument("--password", "-p", help="password") arguments = parser.parse_args(argv) name = use_argument_or_ask(arguments.name, "Username:"******"Full name:") email = use_argument_or_ask(arguments.email, "Email address:") if arguments.password is None: password = inpututils.password("Password:"******"%s: user added" % name
def adduser(argv): class NoEmail: pass class NoPassword: pass parser = argparse.ArgumentParser( description="Critic administration interface: adduser", prog="criticctl [options] adduser") parser.add_argument("--name", help="user name") parser.add_argument("--email", "-e", help="email address") parser.add_argument("--no-email", dest="email", action="store_const", const=NoEmail, help="create user without email address") parser.add_argument("--fullname", "-f", help="full name") parser.add_argument("--password", "-p", help="password") parser.add_argument("--no-password", dest="password", action="store_const", const=NoPassword, help="create user without password") arguments = parser.parse_args(argv) name = use_argument_or_ask(arguments.name, "Username:"******"Full name:") if arguments.email is NoEmail: email = None else: email = use_argument_or_ask(arguments.email, "Email address:") if not email.strip(): email = None if arguments.password is NoPassword: hashed_password = None else: if arguments.password is None: password = inpututils.password("Password:"******"%s: user added" % name
def password(prompt, default=None, twice=True): if headless: if default is None: print """ ERROR: password input requested in headless mode! Prompt: %s """ % prompt sys.exit(1) else: print "%s %s" % (prompt, "****") return default return inpututils.password(prompt, default, twice)
def passwd(argv): parser = argparse.ArgumentParser( description="Critic administration interface: passwd", prog="criticctl [options] passwd") class NoPassword: pass parser.add_argument("--name", help="user name") parser.add_argument("--password", help="password") parser.add_argument("--no-password", dest="password", action="store_const", const=NoPassword, help="delete the user's password") arguments = parser.parse_args(argv) name = use_argument_or_ask(arguments.name, "Username:"******"Password:"******"""UPDATE users SET password=%s WHERE name=%s""", (hashed_password, name)) db.commit() if hashed_password: print "%s: password changed" % name else: print "%s: password deleted" % name