aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2014-11-30 15:09:12 -0600
committerChristopher Allan Webber <cwebber@dustycloud.org>2014-12-03 15:40:57 -0600
commitf08e31522d2d57a4474181bda6457464777b059a (patch)
treec3c5421ba4d0a0aea497adeab154ea3dcd5da8f9
parentf7521cac34dc573bdf426da02b5c5b7f224c7f8e (diff)
downloadmediagoblin-f08e31522d2d57a4474181bda6457464777b059a.tar.lz
mediagoblin-f08e31522d2d57a4474181bda6457464777b059a.tar.xz
mediagoblin-f08e31522d2d57a4474181bda6457464777b059a.zip
Make "gmg shell" work with the new globals-less setup
-rw-r--r--mediagoblin/gmg_commands/shell.py53
1 files changed, 36 insertions, 17 deletions
diff --git a/mediagoblin/gmg_commands/shell.py b/mediagoblin/gmg_commands/shell.py
index 4998acd7..70e11404 100644
--- a/mediagoblin/gmg_commands/shell.py
+++ b/mediagoblin/gmg_commands/shell.py
@@ -20,6 +20,8 @@ import code
from mediagoblin import mg_globals
from mediagoblin.gmg_commands import util as commands_util
+from mediagoblin.tools.transition import DISABLE_GLOBALS
+
def shell_parser_setup(subparser):
subparser.add_argument(
@@ -27,14 +29,21 @@ def shell_parser_setup(subparser):
action="store_true")
-SHELL_BANNER = """\
-GNU MediaGoblin shell!
-----------------------
-Available vars:
- - mgoblin_app: instantiated mediagoblin application
- - mg_globals: mediagoblin.globals
- - db: database instance
-"""
+if DISABLE_GLOBALS:
+ SHELL_BANNER = (
+ "GNU MediaGoblin shell!\n"
+ "----------------------\n"
+ "Available vars:\n"
+ " - app: instantiated mediagoblin application\n"
+ " - db: database session\n")
+else:
+ SHELL_BANNER = (
+ "GNU MediaGoblin shell!\n"
+ "----------------------\n"
+ "Available vars:\n"
+ " - app: instantiated mediagoblin application\n"
+ " - mg_globals: mediagoblin.globals\n"
+ " - db: database instance\n")
def py_shell(**user_namespace):
"""
@@ -59,18 +68,28 @@ def ipython_shell(**user_namespace):
user_ns=user_namespace)
return True
+
def shell(args):
"""
Setup a shell for the user either a normal Python shell or an IPython one
"""
- user_namespace = {
- 'mg_globals': mg_globals,
- 'mgoblin_app': commands_util.setup_app(args),
- 'db': mg_globals.database}
+ app = commands_util.setup_app(args)
+
+ def run_shell(db):
+ user_namespace = {
+ 'mg_globals': mg_globals,
+ 'app': app,
+ 'db': db}
+
+ if args.ipython:
+ ipython_shell(**user_namespace)
+ else:
+ # Try ipython_shell first and fall back if not available
+ if not ipython_shell(**user_namespace):
+ py_shell(**user_namespace)
- if args.ipython:
- ipython_shell(**user_namespace)
+ if DISABLE_GLOBALS:
+ with app.db_manager.session_scope() as db:
+ run_shell(db)
else:
- # Try ipython_shell first and fall back if not available
- if not ipython_shell(**user_namespace):
- py_shell(**user_namespace)
+ run_shell(mg_globals.database)