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 mediagoblin
import app
, mg_globals
20 from mediagoblin
.init
.celery
import setup_celery_from_config
23 OUR_MODULENAME
= __name__
26 def setup_self(check_environ_for_conf
=True, module_name
=OUR_MODULENAME
,
27 default_conf_file
='mediagoblin.ini'):
29 Transform this module into a celery config module by reading the
30 mediagoblin config file. Set the environment variable
31 MEDIAGOBLIN_CONFIG to specify where this config file is.
33 By default it defaults to 'mediagoblin.ini'.
35 Note that if celery_setup_elsewhere is set in your config file,
36 this simply won't work.
38 if check_environ_for_conf
:
39 mgoblin_conf_file
= os
.path
.abspath(
40 os
.environ
.get('MEDIAGOBLIN_CONFIG', default_conf_file
))
42 mgoblin_conf_file
= default_conf_file
44 if not os
.path
.exists(mgoblin_conf_file
):
46 "MEDIAGOBLIN_CONFIG not set or file does not exist")
48 # By setting the environment variable here we should ensure that
49 # this is the module that gets set up.
50 os
.environ
['CELERY_CONFIG_MODULE'] = module_name
51 app
.MediaGoblinApp(mgoblin_conf_file
, setup_celery
=False)
53 setup_celery_from_config(
54 mg_globals
.app_config
, mg_globals
.global_config
,
55 settings_module
=module_name
,
59 if os
.environ
['CELERY_CONFIG_MODULE'] == OUR_MODULENAME
: