diff options
Diffstat (limited to 'mediagoblin/gmg_commands')
-rw-r--r-- | mediagoblin/gmg_commands/migrate.py | 9 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/mongosql.py | 7 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/shell.py | 44 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/wipealldata.py | 8 |
4 files changed, 54 insertions, 14 deletions
diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py index cacf5d19..af541786 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -17,7 +17,7 @@ import sys from mediagoblin.db.mongo import util as db_util -from mediagoblin.db.open import setup_connection_and_db_from_config +from mediagoblin.db.mongo.open import setup_connection_and_db_from_config from mediagoblin.init import setup_global_and_app_config # This MUST be imported so as to set up the appropriate migrations! @@ -41,7 +41,12 @@ def _print_finished_migration(migration_number, migration_func): def migrate(args): - global_config, app_config = setup_global_and_app_config(args.conf_file) + run_migrate(args.conf_file) + + +def run_migrate(conf_file): + global_config, app_config = setup_global_and_app_config(conf_file) + connection, db = setup_connection_and_db_from_config( app_config, use_pymongo=True) migration_manager = db_util.MigrationManager(db) diff --git a/mediagoblin/gmg_commands/mongosql.py b/mediagoblin/gmg_commands/mongosql.py index a25263e2..dd53f575 100644 --- a/mediagoblin/gmg_commands/mongosql.py +++ b/mediagoblin/gmg_commands/mongosql.py @@ -14,12 +14,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from mediagoblin.db.sql.convert import run_conversion - def mongosql_parser_setup(subparser): pass def mongosql(args): + # First, make sure our mongo migrations are up to date... + from mediagoblin.gmg_commands.migrate import run_migrate + run_migrate(args.conf_file) + + from mediagoblin.db.sql.convert import run_conversion run_conversion(args.conf_file) diff --git a/mediagoblin/gmg_commands/shell.py b/mediagoblin/gmg_commands/shell.py index fe15e9f7..ec1ab535 100644 --- a/mediagoblin/gmg_commands/shell.py +++ b/mediagoblin/gmg_commands/shell.py @@ -22,7 +22,9 @@ from mediagoblin.gmg_commands import util as commands_util def shell_parser_setup(subparser): - pass + subparser.add_argument( + '--ipython', help='Use ipython', + action="store_true") SHELL_BANNER = """\ @@ -34,16 +36,42 @@ Available vars: - db: database instance """ +def py_shell(**user_namespace): + """ + Run a shell using normal python shell. + """ + code.interact( + banner=SHELL_BANNER, + local=user_namespace) + + +def ipython_shell(**user_namespace): + """ + Run a shell for the user using ipython. + """ + try: + from IPython import embed + except: + print "IPython not available... exiting!" + return + + embed( + banner1=SHELL_BANNER, + user_ns=user_namespace) + def shell(args): """ Setup a shell for the user + either a normal Python shell + or an IPython one """ - mgoblin_app = commands_util.setup_app(args) + user_namespace = { + 'mg_globals': mg_globals, + 'mgoblin_app': commands_util.setup_app(args), + 'db': mg_globals.database} - code.interact( - banner=SHELL_BANNER, - local={ - 'mgoblin_app': mgoblin_app, - 'mg_globals': mg_globals, - 'db': mg_globals.database}) + if args.ipython: + ipython_shell(**user_namespace) + else: + py_shell(**user_namespace) diff --git a/mediagoblin/gmg_commands/wipealldata.py b/mediagoblin/gmg_commands/wipealldata.py index 3081bbc0..37217fd1 100644 --- a/mediagoblin/gmg_commands/wipealldata.py +++ b/mediagoblin/gmg_commands/wipealldata.py @@ -20,12 +20,16 @@ import sys import os import shutil +from mediagoblin.init import setup_global_and_app_config + def wipe_parser_setup(subparser): pass def wipe(args): + global_config, app_config = setup_global_and_app_config(args.conf_file) + print "*** WARNING! ***" print "" print "Running this will destroy your mediagoblin database," @@ -39,12 +43,12 @@ def wipe(args): 'Are you **SURE** you want to destroy your environment? ' '(if so, type "yes")> ') - if not drop_it == 'yes': + if drop_it != 'yes': return print "nixing data in mongodb...." conn = pymongo.Connection() - conn.drop_database('mediagoblin') + conn.drop_database(app_config["db_name"]) for directory in [os.path.join(os.getcwd(), "user_dev", "media"), os.path.join(os.getcwd(), "user_dev", "beaker")]: |