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/>.
19 from paste
.deploy
.loadwsgi
import NicerConfigParser
20 from paste
.deploy
.converters
import asbool
22 from mediagoblin
import storage
23 from mediagoblin
.db
.open import setup_connection_and_db_from_config
24 from mediagoblin
.celery_setup
import setup_celery_from_config
25 from mediagoblin
.globals import setup_globals
26 from mediagoblin
import globals as mgoblin_globals
29 OUR_MODULENAME
= 'mediagoblin.celery_setup.from_celery'
32 def setup_self(setup_globals_func
=setup_globals
):
34 Transform this module into a celery config module by reading the
35 mediagoblin config file. Set the environment variable
36 MEDIAGOBLIN_CONFIG to specify where this config file is at and
39 By default it defaults to 'mediagoblin.ini:app:mediagoblin'.
41 The first colon ":" is a delimiter between the filename and the
42 config section, so in this case the filename is 'mediagoblin.ini'
43 and the section where mediagoblin is defined is 'app:mediagoblin'.
46 - 'setup_globals_func': this is for testing purposes only. Don't
49 mgoblin_conf_file
, mgoblin_section
= os
.environ
.get(
50 'MEDIAGOBLIN_CONFIG', 'mediagoblin.ini:app:mediagoblin').split(':', 1)
51 if not os
.path
.exists(mgoblin_conf_file
):
53 "MEDIAGOBLIN_CONFIG not set or file does not exist")
55 parser
= NicerConfigParser(mgoblin_conf_file
)
56 parser
.read(mgoblin_conf_file
)
57 parser
._defaults
.setdefault(
58 'here', os
.path
.dirname(os
.path
.abspath(mgoblin_conf_file
)))
59 parser
._defaults
.setdefault(
60 '__file__', os
.path
.abspath(mgoblin_conf_file
))
62 mgoblin_section
= dict(parser
.items(mgoblin_section
))
64 [(section_name
, dict(parser
.items(section_name
)))
65 for section_name
in parser
.sections()])
66 setup_celery_from_config(
67 mgoblin_section
, mgoblin_conf
,
68 settings_module
=OUR_MODULENAME
,
71 connection
, db
= setup_connection_and_db_from_config(mgoblin_section
)
73 # Set up the storage systems.
74 public_store
= storage
.storage_system_from_paste_config(
75 mgoblin_section
, 'publicstore')
76 queue_store
= storage
.storage_system_from_paste_config(
77 mgoblin_section
, 'queuestore')
80 db_connection
=connection
,
82 public_store
=public_store
,
83 email_debug_mode
=asbool(mgoblin_section
.get('email_debug_mode')),
84 email_sender_address
=mgoblin_section
.get(
85 'email_sender_address',
86 'notice@mediagoblin.example.org'),
87 queue_store
=queue_store
)
90 if os
.environ
['CELERY_CONFIG_MODULE'] == OUR_MODULENAME
: