1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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/>.
21 from paste
.deploy
.loadwsgi
import NicerConfigParser
23 from mediagoblin
.celery_setup
import setup_celery_from_config
24 from mediagoblin
import app
, util
25 from mediagoblin
import globals as mgoblin_globals
30 'setup': 'mediagoblin.gmg_commands:shell_parser_setup',
31 'func': 'mediagoblin.gmg_commands:shell',
32 'help': 'Run a shell with some tools pre-setup'},
36 def shell_parser_setup(subparser
):
37 subparser
.add_argument(
38 '-cf', '--conf_file', default
='mediagoblin.ini',
39 help="Config file used to set up environment")
40 subparser
.add_argument(
41 '-cs', '--app_section', default
='app:mediagoblin',
42 help="Section of the config file where the app config is stored.")
46 GNU MediaGoblin shell!
47 ----------------------
49 - mgoblin_app: instantiated mediagoblin application
50 - mgoblin_globals: mediagoblin.globals
51 - db: database instance
58 # Duplicated from from_celery.py, remove when we have the generic util
59 parser
= NicerConfigParser(args
.conf_file
)
60 parser
.read(args
.conf_file
)
61 parser
._defaults
.setdefault(
62 'here', os
.path
.dirname(os
.path
.abspath(args
.conf_file
)))
63 parser
._defaults
.setdefault(
64 '__file__', os
.path
.abspath(args
.conf_file
))
66 mgoblin_section
= dict(parser
.items(args
.app_section
))
68 [(section_name
, dict(parser
.items(section_name
)))
69 for section_name
in parser
.sections()])
71 mgoblin_app
= app
.paste_app_factory(
72 mgoblin_conf
, **mgoblin_section
)
77 'mgoblin_app': mgoblin_app
,
78 'mgoblin_globals': mgoblin_globals
,
79 'db': mgoblin_globals
.database
})
83 parser
= argparse
.ArgumentParser(
84 description
='GNU MediaGoblin utilities.')
86 subparsers
= parser
.add_subparsers(help='sub-command help')
87 for command_name
, command_struct
in SUBCOMMAND_MAP
.iteritems():
88 if command_struct
.has_key('help'):
89 subparser
= subparsers
.add_parser(
90 command_name
, help=command_struct
['help'])
92 subparser
= subparsers
.add_parser(command_name
)
94 setup_func
= util
.import_component(command_struct
['setup'])
95 exec_func
= util
.import_component(command_struct
['func'])
99 subparser
.set_defaults(func
=exec_func
)
101 args
= parser
.parse_args()
105 if __name__
== '__main__':