1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from mediagoblin
import mg_globals
21 from mediagoblin
.gmg_commands
import util
as commands_util
23 from mediagoblin
.tools
.transition
import DISABLE_GLOBALS
26 def shell_parser_setup(subparser
):
27 subparser
.add_argument(
28 '--ipython', help='Use ipython',
34 "GNU MediaGoblin shell!\n"
35 "----------------------\n"
37 " - app: instantiated mediagoblin application\n"
38 " - db: database session\n"
39 " - ctx: context object\n")
42 "GNU MediaGoblin shell!\n"
43 "----------------------\n"
45 " - app: instantiated mediagoblin application\n"
46 " - mg_globals: mediagoblin.globals\n"
47 " - db: database instance\n"
48 " - ctx: context object\n")
50 def py_shell(**user_namespace
):
52 Run a shell using normal python shell.
59 def ipython_shell(**user_namespace
):
61 Run a shell for the user using ipython. Return False if there is no IPython
64 from IPython
import embed
70 user_ns
=user_namespace
)
76 Setup a shell for the user either a normal Python shell or an IPython one
78 app
= commands_util
.setup_app(args
)
80 def run_shell(db
, ctx
):
82 'mg_globals': mg_globals
,
88 ipython_shell(**user_namespace
)
90 # Try ipython_shell first and fall back if not available
91 if not ipython_shell(**user_namespace
):
92 py_shell(**user_namespace
)
94 with app
.gen_context() as ctx
: