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.

53 lines
1.8 KiB

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import datetime
from attrdict import AttrDict
from ConfigParser import ConfigParser
from yamlsettings import YamlSettings
from rophako.plugin import load_plugin
# Get the base directory of the git root.
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
class ConfigHandler(object):
settings = None
def load_settings(self):
"""Load the settings and make them available in the global config."""
settings_file = os.environ.get("ROPHAKO_SETTINGS", "settings.yml")
project_settings = YamlSettings("defaults.yml", settings_file,
self.settings = project_settings.get_settings()
# Extrapolate {basedir} in certain keys.
# TODO: find a better way...
self.site.site_root = self.site.site_root.format(basedir=basedir)
self.emoticons.root_private = self.emoticons.root_private.format(
self.photo.root_private = self.photo.root_private.format(basedir=basedir)
def print_settings(self):
"""Pretty-print the contents of the configuration."""
print self.settings
def load_plugins(self):
"""Load all the plugins specified by the config file."""
for plugin in self.blueprints:
plugin = plugin.strip()
if not plugin: continue
for custom in self.custom:
custom = custom.strip()
if not custom: continue
load_plugin(custom, as_blueprint=False)
def __getattr__(self, section):
"""Attribute accessor for the config object. Acts as a simple pass-thru
to YamlSettings."""
return getattr(self.settings, section)
Config = ConfigHandler()