From d463055317e5518adf7c5a99b4724f4e66830b3c Mon Sep 17 00:00:00 2001 From: Manuel Urbano Santos Date: Sat, 3 Dec 2011 14:29:28 +0100 Subject: [PATCH 1/2] Change adduser arguments from positional to --keyword style. --- mediagoblin/gmg_commands/users.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 4c4b0c1b..a4d85aa4 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -21,14 +21,14 @@ from mediagoblin import mg_globals def adduser_parser_setup(subparser): subparser.add_argument( - 'username', + '--username','-u', help="Username used to login") subparser.add_argument( - 'password', - help="Your supersecret word to login") + '--password','-p', + help="Your supersecret word to login, beware of storing it in bash history") subparser.add_argument( - 'email', - help="Email to recieve notifications") + '--email','-e', + help="Email to receive notifications") def adduser(args): From 7d98005a6b2469134adcf84b7a7417a24968bd8d Mon Sep 17 00:00:00 2001 From: Manuel Urbano Santos Date: Sat, 3 Dec 2011 15:36:02 +0100 Subject: [PATCH 2/2] Prompt for arguments in adduser if not present (I created a function in util.py to check and prompt for arguments). --- mediagoblin/gmg_commands/users.py | 5 ++++- mediagoblin/gmg_commands/util.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index a4d85aa4..b437e839 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -18,7 +18,6 @@ from mediagoblin.gmg_commands import util as commands_util from mediagoblin.auth import lib as auth_lib from mediagoblin import mg_globals - def adduser_parser_setup(subparser): subparser.add_argument( '--username','-u', @@ -35,6 +34,10 @@ def adduser(args): #TODO: Lets trust admins this do not validate Emails :) commands_util.setup_app(args) + args.username = commands_util.prompt_if_not_set(args.username, "Username:") + args.password = commands_util.prompt_if_not_set(args.password, "Password:",True) + args.email = commands_util.prompt_if_not_set(args.email, "Email:") + db = mg_globals.database users_with_username = \ db.User.find({ diff --git a/mediagoblin/gmg_commands/util.py b/mediagoblin/gmg_commands/util.py index 168a0760..af172105 100644 --- a/mediagoblin/gmg_commands/util.py +++ b/mediagoblin/gmg_commands/util.py @@ -16,6 +16,7 @@ from mediagoblin import app +import getpass def setup_app(args): @@ -25,3 +26,15 @@ def setup_app(args): mgoblin_app = app.MediaGoblinApp(args.conf_file) return mgoblin_app + +def prompt_if_not_set(variable,text,password=False): + """ + Checks if the variable is None and prompt for a value if it is + """ + if (variable==None): + if not password: + variable=raw_input(text+' ') + else: + variable=getpass.getpass(text) + + return variable