Merge remote-tracking branch 'remotes/manolinux/645_gmg_adduser_prompt'
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 4 Dec 2011 03:43:15 +0000 (21:43 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 4 Dec 2011 03:43:15 +0000 (21:43 -0600)
mediagoblin/gmg_commands/users.py
mediagoblin/gmg_commands/util.py

index 4c4b0c1b2ce45e1652c66fb0be796ffd301a1657..b437e83944653a137308c95cc2146c9b7148d662 100644 (file)
@@ -18,23 +18,26 @@ 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',
+        '--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):
     #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({
index 168a076082b4fdef79b7a5a46a40b04cce19bb60..af1721056cbc9330e9f8439450f043ee20c096fd 100644 (file)
@@ -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