Revert "use parser.parse_known_args() instead of parser.parse_args()"

This reverts commit 029e779c468ba1a6bfd893679cfaae7f418f45dd.
(and a bit more!)

This wasn't needed anymore because we did a "rest" capture and passed
that over to the reprocess run command.

Conflicts:
	mediagoblin/gmg_commands/assetlink.py
	mediagoblin/gmg_commands/dbupdate.py
	mediagoblin/gmg_commands/import_export.py
	mediagoblin/gmg_commands/users.py
This commit is contained in:
Christopher Allan Webber 2013-08-12 11:13:00 -05:00 committed by Rodney Ewing
parent 98d1fa3bed
commit ff12ecef34
6 changed files with 30 additions and 45 deletions

View File

@ -138,8 +138,7 @@ def assetlink(args):
""" """
Link the asset directory of the currently installed theme and plugins Link the asset directory of the currently installed theme and plugins
""" """
commands_util.check_unrecognized_args(args) mgoblin_app = commands_util.setup_app(args)
mgoblin_app = commands_util.setup_app(args[0])
app_config = mg_globals.app_config app_config = mg_globals.app_config
# link theme # link theme

View File

@ -20,7 +20,6 @@ from sqlalchemy.orm import sessionmaker
from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.db.open import setup_connection_and_db_from_config
from mediagoblin.db.migration_tools import MigrationManager from mediagoblin.db.migration_tools import MigrationManager
from mediagoblin.gmg_commands import util as commands_util
from mediagoblin.init import setup_global_and_app_config from mediagoblin.init import setup_global_and_app_config
from mediagoblin.tools.common import import_component from mediagoblin.tools.common import import_component
@ -148,6 +147,5 @@ def run_all_migrations(db, app_config, global_config):
def dbupdate(args): def dbupdate(args):
commands_util.check_unrecognized_args(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) run_dbupdate(app_config, global_config)

View File

@ -97,28 +97,27 @@ def env_import(args):
''' '''
Restore mongo database and media files from a tar archive Restore mongo database and media files from a tar archive
''' '''
commands_util.check_unrecognized_args(args) if not args.cache_path:
if not args[0].cache_path: args.cache_path = tempfile.mkdtemp()
args[0].cache_path = tempfile.mkdtemp()
setup_global_and_app_config(args[0].conf_file) setup_global_and_app_config(args.conf_file)
# Creates mg_globals.public_store and mg_globals.queue_store # Creates mg_globals.public_store and mg_globals.queue_store
setup_storage() setup_storage()
global_config, app_config = setup_global_and_app_config(args[0].conf_file) global_config, app_config = setup_global_and_app_config(args.conf_file)
db = setup_connection_and_db_from_config( db = setup_connection_and_db_from_config(
app_config) app_config)
tf = tarfile.open( tf = tarfile.open(
args[0].tar_file, args.tar_file,
mode='r|gz') mode='r|gz')
tf.extractall(args[0].cache_path) tf.extractall(args.cache_path)
args[0].cache_path = os.path.join( args.cache_path = os.path.join(
args[0].cache_path, 'mediagoblin-data') args.cache_path, 'mediagoblin-data')
args = _setup_paths(args[0]) args = _setup_paths(args)
# Import database from extracted data # Import database from extracted data
_import_database(db, args) _import_database(db, args)
@ -227,16 +226,16 @@ def env_export(args):
''' '''
commands_util.check_unrecognized_args(args) commands_util.check_unrecognized_args(args)
if args.cache_path: if args.cache_path:
if os.path.exists(args[0].cache_path): if os.path.exists(args.cache_path):
_log.error('The cache directory must not exist ' _log.error('The cache directory must not exist '
'before you run this script') 'before you run this script')
_log.error('Cache directory: {0}'.format(args[0].cache_path)) _log.error('Cache directory: {0}'.format(args.cache_path))
return False return False
else: else:
args[0].cache_path = tempfile.mkdtemp() args.cache_path = tempfile.mkdtemp()
args = _setup_paths(args[0]) args = _setup_paths(args)
if not _export_check(args): if not _export_check(args):
_log.error('Checks did not pass, exiting') _log.error('Checks did not pass, exiting')

View File

@ -63,13 +63,12 @@ def shell(args):
""" """
Setup a shell for the user either a normal Python shell or an IPython one Setup a shell for the user either a normal Python shell or an IPython one
""" """
commands_util.check_unrecognized_args(args)
user_namespace = { user_namespace = {
'mg_globals': mg_globals, 'mg_globals': mg_globals,
'mgoblin_app': commands_util.setup_app(args[0]), 'mgoblin_app': commands_util.setup_app(args),
'db': mg_globals.database} 'db': mg_globals.database}
if args[0].ipython: if args.ipython:
ipython_shell(**user_namespace) ipython_shell(**user_namespace)
else: else:
# Try ipython_shell first and fall back if not available # Try ipython_shell first and fall back if not available

View File

@ -32,17 +32,16 @@ def adduser_parser_setup(subparser):
def adduser(args): def adduser(args):
#TODO: Lets trust admins this do not validate Emails :) #TODO: Lets trust admins this do not validate Emails :)
commands_util.check_unrecognized_args(args) commands_util.setup_app(args)
commands_util.setup_app(args[0])
args[0].username = commands_util.prompt_if_not_set(args[0].username, "Username:") args.username = commands_util.prompt_if_not_set(args.username, "Username:")
args[0].password = commands_util.prompt_if_not_set(args[0].password, "Password:",True) args.password = commands_util.prompt_if_not_set(args.password, "Password:",True)
args[0].email = commands_util.prompt_if_not_set(args[0].email, "Email:") args.email = commands_util.prompt_if_not_set(args.email, "Email:")
db = mg_globals.database db = mg_globals.database
users_with_username = \ users_with_username = \
db.User.query.filter_by( db.User.query.filter_by(
username=args[0].username.lower() username=args.username.lower()
).count() ).count()
if users_with_username: if users_with_username:
@ -51,9 +50,9 @@ def adduser(args):
else: else:
# Create the user # Create the user
entry = db.User() entry = db.User()
entry.username = unicode(args[0].username.lower()) entry.username = unicode(args.username.lower())
entry.email = unicode(args[0].email) entry.email = unicode(args.email)
entry.pw_hash = auth.gen_password_hash(args[0].password) entry.pw_hash = auth.gen_password_hash(args.password)
entry.status = u'active' entry.status = u'active'
entry.email_verified = True entry.email_verified = True
entry.save() entry.save()
@ -68,13 +67,12 @@ def makeadmin_parser_setup(subparser):
def makeadmin(args): def makeadmin(args):
commands_util.check_unrecognized_args(args) commands_util.setup_app(args)
commands_util.setup_app(args[0])
db = mg_globals.database db = mg_globals.database
user = db.User.query.filter_by( user = db.User.query.filter_by(
username=unicode(args[0].username.lower())).one() username=unicode(args.username.lower())).one()
if user: if user:
user.is_admin = True user.is_admin = True
user.save() user.save()
@ -93,15 +91,14 @@ def changepw_parser_setup(subparser):
def changepw(args): def changepw(args):
commands_util.check_unrecognized_args(args) commands_util.setup_app(args)
commands_util.setup_app(args[0])
db = mg_globals.database db = mg_globals.database
user = db.User.query.filter_by( user = db.User.query.filter_by(
username=unicode(args[0].username.lower())).one() username=unicode(args.username.lower())).one()
if user: if user:
user.pw_hash = auth.gen_password_hash(args[0].password) user.pw_hash = auth.gen_password_hash(args.password)
user.save() user.save()
print 'Password successfully changed' print 'Password successfully changed'
else: else:

View File

@ -17,7 +17,6 @@
from mediagoblin import app from mediagoblin import app
import getpass import getpass
import argparse
def setup_app(args): def setup_app(args):
@ -39,9 +38,3 @@ def prompt_if_not_set(variable, text, password=False):
variable=getpass.getpass(text + u' ') variable=getpass.getpass(text + u' ')
return variable return variable
def check_unrecognized_args(args):
if args[1]:
parser = argparse.ArgumentParser()
parser.error('unrecognized arguments: {}'.format(args[1]))