mg_globals.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. import gettext
  20. import pkg_resources
  21. import threading
  22. import six
  23. #############################
  24. # General mediagoblin globals
  25. #############################
  26. # SQL database engine
  27. database = None
  28. # should be the same as the
  29. public_store = None
  30. queue_store = None
  31. # A WorkBenchManager
  32. workbench_manager = None
  33. # A thread-local scope
  34. thread_scope = threading.local()
  35. # gettext (this needs to default to English so it doesn't break
  36. # in case we're running a script without the app like
  37. # ./bin/gmg theme assetlink)
  38. thread_scope.translations = gettext.translation(
  39. 'mediagoblin',
  40. pkg_resources.resource_filename(
  41. 'mediagoblin', 'i18n'), ['en'], fallback=True)
  42. # app and global config objects
  43. app_config = None
  44. global_config = None
  45. # The actual app object
  46. app = None
  47. def setup_globals(**kwargs):
  48. """
  49. Sets up a bunch of globals in this module.
  50. Takes the globals to setup as keyword arguments. If globals are
  51. specified that aren't set as variables above, then throw an error.
  52. """
  53. from mediagoblin import mg_globals
  54. for key, value in six.iteritems(kwargs):
  55. if not hasattr(mg_globals, key):
  56. raise AssertionError("Global %s not known" % key)
  57. setattr(mg_globals, key, value)