From 243c3843bd574129caa7663e25d1a843b2d2dd30 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:02 -0700 Subject: Whitespace and formatting cleanup. * Removed trailing whitespace * Line length < 80 where possible * Honor conventions on number of blank lines * Honor conventions about spaces around :, = --- mediagoblin/gmg_commands/__init__.py | 3 +-- mediagoblin/gmg_commands/import_export.py | 7 ++++--- mediagoblin/gmg_commands/migrate.py | 4 ++-- mediagoblin/gmg_commands/users.py | 7 +++---- 4 files changed, 10 insertions(+), 11 deletions(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 0071c65b..b3f69ccc 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -28,7 +28,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'}, @@ -80,4 +80,3 @@ def main_cli(): if __name__ == '__main__': main_cli() - diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index 05edbfc8..962e545c 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -91,7 +91,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') @@ -229,7 +229,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 @@ -245,7 +246,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..e6dd6f78 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -55,13 +55,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/users.py b/mediagoblin/gmg_commands/users.py index 5421907d..3fda0e32 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -41,7 +41,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: @@ -74,7 +74,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() @@ -100,11 +100,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' - -- cgit v1.2.3 From 285ffeddf3542201b83072d3be544c85e9c487c2 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:41 -0700 Subject: has_key is deprecated, converting uses to use "in" operator. --- mediagoblin/gmg_commands/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index b3f69ccc..3250c246 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -61,7 +61,7 @@ def main_cli(): 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: -- cgit v1.2.3 From 9043e7a012c0b01a993e04831180005ff36730d6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 23 Oct 2011 12:47:25 +0200 Subject: Refactor gmg's cf option into a function Many (all?) gmg subcommands take a -cf option to change the used config file. This options used to be created in each subcommand's parse_setup. Add a helper function and use it around. --- mediagoblin/gmg_commands/import_export.py | 5 ++--- mediagoblin/gmg_commands/migrate.py | 5 ++--- mediagoblin/gmg_commands/shell.py | 5 ++--- mediagoblin/gmg_commands/users.py | 13 ++++--------- mediagoblin/gmg_commands/util.py | 9 +++++++++ 5 files changed, 19 insertions(+), 18 deletions(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index 05edbfc8..5d39304a 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -19,6 +19,7 @@ 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 +from mediagoblin.gmg_commands.util import option_add_conffile import shutil import tarfile @@ -39,9 +40,7 @@ def import_export_parse_setup(subparser): # TODO: Add default subparser.add_argument( 'tar_file') - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help='Config file used to set up environment') + option_add_conffile(subparser) subparser.add_argument( '--mongodump_path', default='mongodump', help='mongodump binary') diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py index 1a597188..0871a171 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -16,6 +16,7 @@ import sys +from mediagoblin.gmg_commands.util import option_add_conffile from mediagoblin.db import util as db_util from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.init.config import read_mediagoblin_config @@ -25,9 +26,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") + option_add_conffile(subparser) def _print_started_migration(migration_number, migration_func): diff --git a/mediagoblin/gmg_commands/shell.py b/mediagoblin/gmg_commands/shell.py index 2a380c7b..408028d0 100644 --- a/mediagoblin/gmg_commands/shell.py +++ b/mediagoblin/gmg_commands/shell.py @@ -19,12 +19,11 @@ import code from mediagoblin import mg_globals from mediagoblin.gmg_commands import util as commands_util +from mediagoblin.gmg_commands.util import option_add_conffile def shell_parser_setup(subparser): - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") + option_add_conffile(subparser) SHELL_BANNER = """\ diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 5421907d..f6b03bf1 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -15,6 +15,7 @@ # along with this program. If not, see . from mediagoblin.gmg_commands import util as commands_util +from mediagoblin.gmg_commands.util import option_add_conffile from mediagoblin.auth import lib as auth_lib from mediagoblin import mg_globals @@ -29,9 +30,7 @@ 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") + option_add_conffile(subparser) def adduser(args): @@ -64,9 +63,7 @@ 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") + option_add_conffile(subparser) def makeadmin(args): @@ -90,9 +87,7 @@ 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") + option_add_conffile(subparser) def changepw(args): diff --git a/mediagoblin/gmg_commands/util.py b/mediagoblin/gmg_commands/util.py index 168a0760..02febd2c 100644 --- a/mediagoblin/gmg_commands/util.py +++ b/mediagoblin/gmg_commands/util.py @@ -25,3 +25,12 @@ def setup_app(args): mgoblin_app = app.MediaGoblinApp(args.conf_file) return mgoblin_app + + +def option_add_conffile(subparser): + """ + Add the -cf option to a subparser + """ + subparser.add_argument( + '-cf', '--conf_file', default='mediagoblin.ini', + help="Config file used to set up environment") -- cgit v1.2.3 From 15ac1458edfe703688cfe1e5eb36a2e90f5194c6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 23 Oct 2011 21:33:52 +0200 Subject: Make gmg's -cf option a global option All gmg's subcommands used to have a -cf option to set the config file. Instead make this a gmg global option. This means: bin/gmg migrate -cf mediagoblin_2.ini gets bin/gmg -cf mediagoblin_2.ini migrate --- mediagoblin/gmg_commands/__init__.py | 3 +++ mediagoblin/gmg_commands/import_export.py | 2 -- mediagoblin/gmg_commands/migrate.py | 3 +-- mediagoblin/gmg_commands/shell.py | 3 +-- mediagoblin/gmg_commands/users.py | 4 ---- mediagoblin/gmg_commands/util.py | 9 --------- 6 files changed, 5 insertions(+), 19 deletions(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 92ae840e..6c7450cb 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -58,6 +58,9 @@ SUBCOMMAND_MAP = { def main_cli(): parser = argparse.ArgumentParser( description='GNU MediaGoblin utilities.') + parser.add_argument( + '-cf', '--conf_file', default='mediagoblin.ini', + help="Config file used to set up environment") subparsers = parser.add_subparsers(help='sub-command help') for command_name, command_struct in SUBCOMMAND_MAP.iteritems(): diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index 5d39304a..78d30713 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -19,7 +19,6 @@ 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 -from mediagoblin.gmg_commands.util import option_add_conffile import shutil import tarfile @@ -40,7 +39,6 @@ def import_export_parse_setup(subparser): # TODO: Add default subparser.add_argument( 'tar_file') - option_add_conffile(subparser) subparser.add_argument( '--mongodump_path', default='mongodump', help='mongodump binary') diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py index 0871a171..fad9b363 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -16,7 +16,6 @@ import sys -from mediagoblin.gmg_commands.util import option_add_conffile from mediagoblin.db import util as db_util from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.init.config import read_mediagoblin_config @@ -26,7 +25,7 @@ from mediagoblin.db import migrations def migrate_parser_setup(subparser): - option_add_conffile(subparser) + pass def _print_started_migration(migration_number, migration_func): diff --git a/mediagoblin/gmg_commands/shell.py b/mediagoblin/gmg_commands/shell.py index 408028d0..910560a0 100644 --- a/mediagoblin/gmg_commands/shell.py +++ b/mediagoblin/gmg_commands/shell.py @@ -19,11 +19,10 @@ import code from mediagoblin import mg_globals from mediagoblin.gmg_commands import util as commands_util -from mediagoblin.gmg_commands.util import option_add_conffile def shell_parser_setup(subparser): - option_add_conffile(subparser) + pass SHELL_BANNER = """\ diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index f6b03bf1..345c3e5c 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -15,7 +15,6 @@ # along with this program. If not, see . from mediagoblin.gmg_commands import util as commands_util -from mediagoblin.gmg_commands.util import option_add_conffile from mediagoblin.auth import lib as auth_lib from mediagoblin import mg_globals @@ -30,7 +29,6 @@ def adduser_parser_setup(subparser): subparser.add_argument( 'email', help="Email to recieve notifications") - option_add_conffile(subparser) def adduser(args): @@ -63,7 +61,6 @@ def makeadmin_parser_setup(subparser): subparser.add_argument( 'username', help="Username to give admin level") - option_add_conffile(subparser) def makeadmin(args): @@ -87,7 +84,6 @@ def changepw_parser_setup(subparser): subparser.add_argument( 'password', help="Your NEW supersecret word to login") - option_add_conffile(subparser) def changepw(args): diff --git a/mediagoblin/gmg_commands/util.py b/mediagoblin/gmg_commands/util.py index 02febd2c..168a0760 100644 --- a/mediagoblin/gmg_commands/util.py +++ b/mediagoblin/gmg_commands/util.py @@ -25,12 +25,3 @@ def setup_app(args): mgoblin_app = app.MediaGoblinApp(args.conf_file) return mgoblin_app - - -def option_add_conffile(subparser): - """ - Add the -cf option to a subparser - """ - subparser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") -- cgit v1.2.3 From 4a4035c8afc56994450cf318bea3c67524e1128b Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 26 Oct 2011 11:21:25 -0500 Subject: Added an extra warning about wipealldata being pretty inflexible. --- mediagoblin/gmg_commands/wipealldata.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/wipealldata.py b/mediagoblin/gmg_commands/wipealldata.py index dc5d6cf7..0cfb58d7 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? ' -- cgit v1.2.3 From c57b42a130a5e8f94054770dfc87337a42ef3c19 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 26 Oct 2011 11:24:39 -0500 Subject: Removed suggestion that the user run ./bin/buildout --- mediagoblin/gmg_commands/wipealldata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/wipealldata.py b/mediagoblin/gmg_commands/wipealldata.py index 0cfb58d7..cddbab38 100644 --- a/mediagoblin/gmg_commands/wipealldata.py +++ b/mediagoblin/gmg_commands/wipealldata.py @@ -52,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!" -- cgit v1.2.3 From 9d0a613be937b426b8137016f01bb43feed88341 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 29 Oct 2011 16:24:52 -0500 Subject: Default to mediagoblin_local.ini if available in ./bin/gmg commands --- mediagoblin/gmg_commands/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 6c7450cb..10c30385 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import argparse +import os from mediagoblin.tools.common import import_component @@ -59,8 +60,11 @@ def main_cli(): parser = argparse.ArgumentParser( description='GNU MediaGoblin utilities.') parser.add_argument( - '-cf', '--conf_file', default='mediagoblin.ini', - help="Config file used to set up environment") + '-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(): @@ -78,6 +82,13 @@ def main_cli(): 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) -- cgit v1.2.3 From a9c7af90408c3537f42763e63862a2ae44bcc368 Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 15 Nov 2011 11:21:15 +0100 Subject: export: Handle Unicode titles better in logging log("ascii %s" % unicode_string) tries to convert unicode to ascii, which might fail. Better use log(u"unicode format %s" % unicode_string) and let the logging framework handle the conversion. This works much better and the exceptions still happening aren't stopping the main app. Also remove one useless import. --- mediagoblin/gmg_commands/import_export.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/gmg_commands') diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index a46219a0..30112969 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 @@ -209,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)) -- cgit v1.2.3