aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands/shell.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2012-03-18 12:12:41 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2012-03-18 12:12:41 -0500
commit94e605237512daa518bcab9b59edbc1107840006 (patch)
treeeb1aa0b714c536f68474f0853c251ed4c5d683cf /mediagoblin/gmg_commands/shell.py
parentbf0f67ad6547e2073770942ddf66f23d3181831a (diff)
parent54477b4d76ca983e2e884fea9c0975c7e63fdc1d (diff)
downloadmediagoblin-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/shell.py')
-rw-r--r--mediagoblin/gmg_commands/shell.py44
1 files changed, 36 insertions, 8 deletions
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)