Committing extracted and compiled translations
[mediagoblin.git] / mediagoblin / mg_globals.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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 In some places, we need to access the database, public_store, queue_store
18 """
19
20 import gettext
21 import pkg_resources
22 import threading
23
24
25 #############################
26 # General mediagoblin globals
27 #############################
28
29 # mongokit.Connection
30 db_connection = None
31
32 # mongokit.Connection
33 database = None
34
35 # beaker's cache manager
36 cache = None
37
38 # should be the same as the
39 public_store = None
40 queue_store = None
41
42 # A WorkBenchManager
43 workbench_manager = None
44
45 # A thread-local scope
46 thread_scope = threading.local()
47
48 # gettext
49 thread_scope.translations = gettext.find(
50 'mediagoblin',
51 pkg_resources.resource_filename(
52 'mediagoblin', 'translations'), ['en'])
53
54 # app and global config objects
55 app_config = None
56 global_config = None
57
58 # The actual app object
59 app = None
60
61
62 def setup_globals(**kwargs):
63 """
64 Sets up a bunch of globals in this module.
65
66 Takes the globals to setup as keyword arguments. If globals are
67 specified that aren't set as variables above, then throw an error.
68 """
69 from mediagoblin import mg_globals
70
71 for key, value in kwargs.iteritems():
72 if not hasattr(mg_globals, key):
73 raise AssertionError("Global %s not known" % key)
74 setattr(mg_globals, key, value)