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.
 
 
 
 
 

57 lines
1.9 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. self.blog.copyright = self.blog.copyright.format(
  27. year=datetime.datetime.utcnow().strftime("%Y")
  28. )
  29. def print_settings(self):
  30. """Pretty-print the contents of the configuration."""
  31. print self.settings
  32. def load_plugins(self):
  33. """Load all the plugins specified by the config file."""
  34. for plugin in self.blueprints:
  35. plugin = plugin.strip()
  36. if not plugin: continue
  37. load_plugin(plugin)
  38. for custom in self.custom:
  39. custom = custom.strip()
  40. if not custom: continue
  41. load_plugin(custom, as_blueprint=False)
  42. def __getattr__(self, section):
  43. """Attribute accessor for the config object. Acts as a simple pass-thru
  44. to YamlSettings."""
  45. return getattr(self.settings, section)
  46. Config = ConfigHandler()