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.
 
 
 
 
 

54 lines
1.8 KiB

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