diff options
Diffstat (limited to 'mediagoblin/gmg_commands')
-rw-r--r-- | mediagoblin/gmg_commands/__init__.py | 25 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/import_export.py | 13 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/migrate.py | 8 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/shell.py | 4 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/users.py | 16 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/wipealldata.py | 6 |
6 files changed, 36 insertions, 36 deletions
diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 0071c65b..04187ff2 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -15,8 +15,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import argparse +import os -from mediagoblin import util as mg_util +from mediagoblin.tools.common import import_component SUBCOMMAND_MAP = { @@ -28,7 +29,7 @@ SUBCOMMAND_MAP = { 'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup', 'func': 'mediagoblin.gmg_commands.migrate:migrate', 'help': 'Apply all unapplied bulk migrations to the database'}, - 'adduser':{ + 'adduser': { 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup', 'func': 'mediagoblin.gmg_commands.users:adduser', 'help': 'Creates an user'}, @@ -58,26 +59,38 @@ SUBCOMMAND_MAP = { def main_cli(): parser = argparse.ArgumentParser( description='GNU MediaGoblin utilities.') + parser.add_argument( + '-cf', '--conf_file', default=None, + help=( + "Config file used to set up environment. " + "Default to mediagoblin_local.ini if readable, " + "otherwise mediagoblin.ini")) subparsers = parser.add_subparsers(help='sub-command help') for command_name, command_struct in SUBCOMMAND_MAP.iteritems(): - if command_struct.has_key('help'): + if 'help' in command_struct: subparser = subparsers.add_parser( command_name, help=command_struct['help']) else: subparser = subparsers.add_parser(command_name) - setup_func = mg_util.import_component(command_struct['setup']) - exec_func = mg_util.import_component(command_struct['func']) + setup_func = import_component(command_struct['setup']) + exec_func = import_component(command_struct['func']) setup_func(subparser) subparser.set_defaults(func=exec_func) args = parser.parse_args() + if args.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' + else: + args.conf_file = 'mediagoblin.ini' + args.func(args) if __name__ == '__main__': main_cli() - diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index fefbdb4e..4ec17d47 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -16,7 +16,6 @@ from mediagoblin import mg_globals from mediagoblin.db.open import setup_connection_and_db_from_config -from mediagoblin.init.config import read_mediagoblin_config from mediagoblin.storage.filestorage import BasicFileStorage from mediagoblin.init import setup_storage, setup_global_and_app_config @@ -40,9 +39,6 @@ def import_export_parse_setup(subparser): subparser.add_argument( 'tar_file') subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help='Config file used to set up environment') - subparser.add_argument( '--mongodump_path', default='mongodump', help='mongodump binary') subparser.add_argument( @@ -91,7 +87,7 @@ def _import_database(db, args): args.mongorestore_path, '-d', db.name, os.path.join(args._cache_path['database'], db.name)]) - + p.wait() _log.info('...Database imported') @@ -212,7 +208,7 @@ def _export_media(db, args): for entry in db.media_entries.find(): for name, path in entry['media_files'].items(): - _log.info('Exporting {0} - {1}'.format( + _log.info(u'Exporting {0} - {1}'.format( entry['title'], name)) try: @@ -231,7 +227,8 @@ def env_export(args): ''' if args.cache_path: if os.path.exists(args.cache_path): - _log.error('The cache directory must not exist before you run this script') + _log.error('The cache directory must not exist ' + 'before you run this script') _log.error('Cache directory: {0}'.format(args.cache_path)) return False @@ -247,7 +244,7 @@ def env_export(args): globa_config, app_config = setup_global_and_app_config(args.conf_file) setup_storage() - + connection, db = setup_connection_and_db_from_config( app_config, use_pymongo=True) diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py index 1a597188..beea109d 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -25,9 +25,7 @@ from mediagoblin.db import migrations def migrate_parser_setup(subparser): - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") + pass def _print_started_migration(migration_number, migration_func): @@ -55,13 +53,13 @@ def migrate(args): for collection, index_name in removed_indexes: print "Removed index '%s' in collection '%s'" % ( index_name, collection) - + # Migrate print "\n== Applying migrations... ==" migration_manager.migrate_new( pre_callback=_print_started_migration, post_callback=_print_finished_migration) - + # Add new indexes print "\n== Adding new indexes... ==" new_indexes = db_util.add_new_indexes(db) diff --git a/mediagoblin/gmg_commands/shell.py b/mediagoblin/gmg_commands/shell.py index 2a380c7b..910560a0 100644 --- a/mediagoblin/gmg_commands/shell.py +++ b/mediagoblin/gmg_commands/shell.py @@ -22,9 +22,7 @@ from mediagoblin.gmg_commands import util as commands_util def shell_parser_setup(subparser): - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") + pass SHELL_BANNER = """\ diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 5421907d..4c4b0c1b 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -29,9 +29,6 @@ def adduser_parser_setup(subparser): subparser.add_argument( 'email', help="Email to recieve notifications") - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") def adduser(args): @@ -41,7 +38,7 @@ def adduser(args): db = mg_globals.database users_with_username = \ db.User.find({ - 'username': args.username.lower() + 'username': args.username.lower(), }).count() if users_with_username: @@ -64,9 +61,6 @@ def makeadmin_parser_setup(subparser): subparser.add_argument( 'username', help="Username to give admin level") - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") def makeadmin(args): @@ -74,7 +68,7 @@ def makeadmin(args): db = mg_globals.database - user = db.User.one({'username':unicode(args.username.lower())}) + user = db.User.one({'username': unicode(args.username.lower())}) if user: user['is_admin'] = True user.save() @@ -90,9 +84,6 @@ def changepw_parser_setup(subparser): subparser.add_argument( 'password', help="Your NEW supersecret word to login") - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") def changepw(args): @@ -100,11 +91,10 @@ def changepw(args): db = mg_globals.database - user = db.User.one({'username':unicode(args.username.lower())}) + user = db.User.one({'username': unicode(args.username.lower())}) if user: user['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) user.save() print 'Password successfully changed' else: print 'The user doesn\'t exist' - diff --git a/mediagoblin/gmg_commands/wipealldata.py b/mediagoblin/gmg_commands/wipealldata.py index dc5d6cf7..cddbab38 100644 --- a/mediagoblin/gmg_commands/wipealldata.py +++ b/mediagoblin/gmg_commands/wipealldata.py @@ -30,6 +30,10 @@ def wipe(args): print "" print "Running this will destroy your mediagoblin database," print "remove all your media files in user_dev/, etc." + print "" + print "ALSO: This command is currently a hack and will only remove" + print " things properly on the default setup! If you've customized" + print " your mediagoblin configs, it won't work (for now)." drop_it = raw_input( 'Are you **SURE** you want to destroy your environment? ' @@ -48,4 +52,4 @@ def wipe(args): print "nixing %s...." % directory shutil.rmtree(directory) - print "removed all your stuff! okay, now re-run ./bin/buildout" + print "removed all your stuff!" |