Move the general applicaiton setup commands to a utility module
[mediagoblin.git] / mediagoblin / gmg_commands / util.py
CommitLineData
8820121a
CAW
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011 Free Software Foundation, Inc
3#
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.
8#
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.
13#
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/>.
16
17
18import os
19
20from paste.deploy.loadwsgi import NicerConfigParser
21
22from mediagoblin import app
23
24
25def setup_app(args):
26 """
27 Setup the application after reading the mediagoblin config files
28 """
29 # Duplicated from from_celery.py, remove when we have the generic util
30 parser = NicerConfigParser(args.conf_file)
31 parser.read(args.conf_file)
32 parser._defaults.setdefault(
33 'here', os.path.dirname(os.path.abspath(args.conf_file)))
34 parser._defaults.setdefault(
35 '__file__', os.path.abspath(args.conf_file))
36
37 mgoblin_section = dict(parser.items(args.app_section))
38 mgoblin_conf = dict(
39 [(section_name, dict(parser.items(section_name)))
40 for section_name in parser.sections()])
41
42 mgoblin_app = app.paste_app_factory(
43 mgoblin_conf, **mgoblin_section)
44
45 return mgoblin_app