From aa387fc57ec1c176a739df8c5f4cedaf70ae9af1 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Thu, 1 Aug 2013 10:23:37 -0700 Subject: [PATCH] use parser.parse_known_args() instead of parser.parse_args() --- mediagoblin/gmg_commands/__init__.py | 12 +++++------ mediagoblin/gmg_commands/assetlink.py | 2 +- mediagoblin/gmg_commands/dbupdate.py | 2 +- mediagoblin/gmg_commands/import_export.py | 26 +++++++++++------------ mediagoblin/gmg_commands/shell.py | 4 ++-- mediagoblin/gmg_commands/users.py | 26 +++++++++++------------ 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index d8156126..dc3409f9 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -92,16 +92,16 @@ def main_cli(): subparser.set_defaults(func=exec_func) - args = parser.parse_args() - args.orig_conf_file = args.conf_file - if args.conf_file is None: + args = parser.parse_known_args() + args[0].orig_conf_file = args[0].conf_file + if args[0].conf_file is None: if os.path.exists('mediagoblin_local.ini') \ and os.access('mediagoblin_local.ini', os.R_OK): - args.conf_file = 'mediagoblin_local.ini' + args[0].conf_file = 'mediagoblin_local.ini' else: - args.conf_file = 'mediagoblin.ini' + args[0].conf_file = 'mediagoblin.ini' - args.func(args) + args[0].func(args) if __name__ == '__main__': diff --git a/mediagoblin/gmg_commands/assetlink.py b/mediagoblin/gmg_commands/assetlink.py index 148ebe9e..49e27e33 100644 --- a/mediagoblin/gmg_commands/assetlink.py +++ b/mediagoblin/gmg_commands/assetlink.py @@ -138,7 +138,7 @@ def assetlink(args): """ Link the asset directory of the currently installed theme and plugins """ - mgoblin_app = commands_util.setup_app(args) + mgoblin_app = commands_util.setup_app(args[0]) app_config = mg_globals.app_config # link theme diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 961752f6..fb533d0a 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -147,5 +147,5 @@ def run_all_migrations(db, app_config, global_config): def dbupdate(args): - global_config, app_config = setup_global_and_app_config(args.conf_file) + global_config, app_config = setup_global_and_app_config(args[0].conf_file) run_dbupdate(app_config, global_config) diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index 98ec617d..2a624b96 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -96,27 +96,27 @@ def env_import(args): ''' Restore mongo database and media files from a tar archive ''' - if not args.cache_path: - args.cache_path = tempfile.mkdtemp() + if not args[0].cache_path: + args[0].cache_path = tempfile.mkdtemp() - setup_global_and_app_config(args.conf_file) + setup_global_and_app_config(args[0].conf_file) # Creates mg_globals.public_store and mg_globals.queue_store setup_storage() - global_config, app_config = setup_global_and_app_config(args.conf_file) + global_config, app_config = setup_global_and_app_config(args[0].conf_file) db = setup_connection_and_db_from_config( app_config) tf = tarfile.open( - args.tar_file, + args[0].tar_file, mode='r|gz') - tf.extractall(args.cache_path) + tf.extractall(args[0].cache_path) - args.cache_path = os.path.join( - args.cache_path, 'mediagoblin-data') - args = _setup_paths(args) + args[0].cache_path = os.path.join( + args[0].cache_path, 'mediagoblin-data') + args = _setup_paths(args[0]) # Import database from extracted data _import_database(db, args) @@ -224,16 +224,16 @@ def env_export(args): Export database and media files to a tar archive ''' if args.cache_path: - if os.path.exists(args.cache_path): + if os.path.exists(args[0].cache_path): _log.error('The cache directory must not exist ' 'before you run this script') - _log.error('Cache directory: {0}'.format(args.cache_path)) + _log.error('Cache directory: {0}'.format(args[0].cache_path)) return False else: - args.cache_path = tempfile.mkdtemp() + args[0].cache_path = tempfile.mkdtemp() - args = _setup_paths(args) + args = _setup_paths(args[0]) if not _export_check(args): _log.error('Checks did not pass, exiting') diff --git a/mediagoblin/gmg_commands/shell.py b/mediagoblin/gmg_commands/shell.py index 4998acd7..b19af837 100644 --- a/mediagoblin/gmg_commands/shell.py +++ b/mediagoblin/gmg_commands/shell.py @@ -65,10 +65,10 @@ def shell(args): """ user_namespace = { 'mg_globals': mg_globals, - 'mgoblin_app': commands_util.setup_app(args), + 'mgoblin_app': commands_util.setup_app(args[0]), 'db': mg_globals.database} - if args.ipython: + if args[0].ipython: ipython_shell(**user_namespace) else: # Try ipython_shell first and fall back if not available diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index e44b0aa9..c2a4dddb 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -32,16 +32,16 @@ def adduser_parser_setup(subparser): def adduser(args): #TODO: Lets trust admins this do not validate Emails :) - commands_util.setup_app(args) + commands_util.setup_app(args[0]) - 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:") + args[0].username = commands_util.prompt_if_not_set(args[0].username, "Username:") + args[0].password = commands_util.prompt_if_not_set(args[0].password, "Password:",True) + args[0].email = commands_util.prompt_if_not_set(args[0].email, "Email:") db = mg_globals.database users_with_username = \ db.User.query.filter_by( - username=args.username.lower() + username=args[0].username.lower() ).count() if users_with_username: @@ -50,9 +50,9 @@ def adduser(args): else: # Create the user entry = db.User() - entry.username = unicode(args.username.lower()) - entry.email = unicode(args.email) - entry.pw_hash = auth.gen_password_hash(args.password) + entry.username = unicode(args[0].username.lower()) + entry.email = unicode(args[0].email) + entry.pw_hash = auth.gen_password_hash(args[0].password) entry.status = u'active' entry.email_verified = True entry.save() @@ -67,12 +67,12 @@ def makeadmin_parser_setup(subparser): def makeadmin(args): - commands_util.setup_app(args) + commands_util.setup_app(args[0]) db = mg_globals.database user = db.User.query.filter_by( - username=unicode(args.username.lower())).one() + username=unicode(args[0].username.lower())).one() if user: user.is_admin = True user.save() @@ -91,14 +91,14 @@ def changepw_parser_setup(subparser): def changepw(args): - commands_util.setup_app(args) + commands_util.setup_app(args[0]) db = mg_globals.database user = db.User.query.filter_by( - username=unicode(args.username.lower())).one() + username=unicode(args[0].username.lower())).one() if user: - user.pw_hash = auth.gen_password_hash(args.password) + user.pw_hash = auth.gen_password_hash(args[0].password) user.save() print 'Password successfully changed' else: -- 2.25.1