A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals, print_function, absolute_import
  3. import os
  4. import datetime
  5. from yamlsettings import YamlSettings
  6. from rophako.plugin import load_plugin
  7. # Get the base directory of the git root.
  8. basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
  9. class ConfigHandler(object):
  10. settings = None
  11. def load_settings(self):
  12. """Load the settings and make them available in the global config."""
  13. settings_file = os.environ.get("ROPHAKO_SETTINGS", "settings.yml")
  14. project_settings = YamlSettings("defaults.yml", settings_file,
  15. default_section="rophako")
  16. self.settings = project_settings.get_settings()
  17. # Extrapolate {basedir} in certain keys.
  18. # TODO: find a better way...
  19. self.site.site_root = self.site.site_root.format(basedir=basedir)
  20. self.emoticons.root_private = self.emoticons.root_private.format(
  21. basedir=basedir
  22. )
  23. self.photo.root_private = self.photo.root_private.format(basedir=basedir)
  24. self.blog.copyright = self.blog.copyright.format(
  25. year=datetime.datetime.utcnow().strftime("%Y")
  26. )
  27. def print_settings(self):
  28. """Pretty-print the contents of the configuration."""
  29. print(self.settings)
  30. def load_plugins(self):
  31. """Load all the plugins specified by the config file."""
  32. for plugin in self.blueprints:
  33. plugin = plugin.strip()
  34. if not plugin: continue
  35. load_plugin(plugin)
  36. for custom in self.custom:
  37. custom = custom.strip()
  38. if not custom: continue
  39. load_plugin(custom, as_blueprint=False)
  40. def __getattr__(self, section):
  41. """Attribute accessor for the config object. Acts as a simple pass-thru
  42. to YamlSettings."""
  43. return getattr(self.settings, section)
  44. Config = ConfigHandler()