Make "gmg shell" work with the new globals-less setup
This commit is contained in:
parent
f7521cac34
commit
f08e31522d
@ -20,6 +20,8 @@ import code
|
|||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.gmg_commands import util as commands_util
|
from mediagoblin.gmg_commands import util as commands_util
|
||||||
|
|
||||||
|
from mediagoblin.tools.transition import DISABLE_GLOBALS
|
||||||
|
|
||||||
|
|
||||||
def shell_parser_setup(subparser):
|
def shell_parser_setup(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
@ -27,14 +29,21 @@ def shell_parser_setup(subparser):
|
|||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
|
|
||||||
SHELL_BANNER = """\
|
if DISABLE_GLOBALS:
|
||||||
GNU MediaGoblin shell!
|
SHELL_BANNER = (
|
||||||
----------------------
|
"GNU MediaGoblin shell!\n"
|
||||||
Available vars:
|
"----------------------\n"
|
||||||
- mgoblin_app: instantiated mediagoblin application
|
"Available vars:\n"
|
||||||
- mg_globals: mediagoblin.globals
|
" - app: instantiated mediagoblin application\n"
|
||||||
- db: database instance
|
" - 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):
|
def py_shell(**user_namespace):
|
||||||
"""
|
"""
|
||||||
@ -59,14 +68,18 @@ def ipython_shell(**user_namespace):
|
|||||||
user_ns=user_namespace)
|
user_ns=user_namespace)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def shell(args):
|
def shell(args):
|
||||||
"""
|
"""
|
||||||
Setup a shell for the user either a normal Python shell or an IPython one
|
Setup a shell for the user either a normal Python shell or an IPython one
|
||||||
"""
|
"""
|
||||||
|
app = commands_util.setup_app(args)
|
||||||
|
|
||||||
|
def run_shell(db):
|
||||||
user_namespace = {
|
user_namespace = {
|
||||||
'mg_globals': mg_globals,
|
'mg_globals': mg_globals,
|
||||||
'mgoblin_app': commands_util.setup_app(args),
|
'app': app,
|
||||||
'db': mg_globals.database}
|
'db': db}
|
||||||
|
|
||||||
if args.ipython:
|
if args.ipython:
|
||||||
ipython_shell(**user_namespace)
|
ipython_shell(**user_namespace)
|
||||||
@ -74,3 +87,9 @@ def shell(args):
|
|||||||
# Try ipython_shell first and fall back if not available
|
# Try ipython_shell first and fall back if not available
|
||||||
if not ipython_shell(**user_namespace):
|
if not ipython_shell(**user_namespace):
|
||||||
py_shell(**user_namespace)
|
py_shell(**user_namespace)
|
||||||
|
|
||||||
|
if DISABLE_GLOBALS:
|
||||||
|
with app.db_manager.session_scope() as db:
|
||||||
|
run_shell(db)
|
||||||
|
else:
|
||||||
|
run_shell(mg_globals.database)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user