diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2012-03-18 12:12:41 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2012-03-18 12:12:41 -0500 |
commit | 94e605237512daa518bcab9b59edbc1107840006 (patch) | |
tree | eb1aa0b714c536f68474f0853c251ed4c5d683cf /mediagoblin/gmg_commands | |
parent | bf0f67ad6547e2073770942ddf66f23d3181831a (diff) | |
parent | 54477b4d76ca983e2e884fea9c0975c7e63fdc1d (diff) | |
download | mediagoblin-94e605237512daa518bcab9b59edbc1107840006.tar.lz mediagoblin-94e605237512daa518bcab9b59edbc1107840006.tar.xz mediagoblin-94e605237512daa518bcab9b59edbc1107840006.zip |
Merge branch 'master' into derek-moore-bug405_email_notifications_for_comments
Conflicts:
mediagoblin/db/mongo/migrations.py
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 |
3 files changed, 48 insertions, 12 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) |