def _get_layout_folder(root, layout_name='basic'): """ Finds the layout folder from the given root folder. If it does not exist, return None """ layouts_folder = Folder(str(root)).child_folder(LAYOUTS) layout_folder = layouts_folder.child_folder(layout_name) return layout_folder if layout_folder.exists else None
class Config(Expando): """ Represents the hyde configuration file """ def __init__(self, sitepath, config_file=None, config_dict=None): self.default_config = dict( mode='production', simple_copy = [], content_root='content', deploy_root='deploy', media_root='media', layout_root='layout', media_url='/media', base_url="/", not_found='404.html', plugins = [], ignore = [ "*~", "*.bak", ".hg", ".git", ".svn"], meta = { "nodemeta": 'meta.yaml' } ) self.config_file = config_file self.config_dict = config_dict self.load_time = datetime.min self.config_files = [] self.sitepath = Folder(sitepath) super(Config, self).__init__(self.load()) @property def last_modified(self): return max((conf.last_modified for conf in self.config_files)) def needs_refresh(self): if not self.config_files: return True return any((conf.has_changed_since(self.load_time) for conf in self.config_files)) def load(self): conf = dict(**self.default_config) conf.update(self.read_config(self.config_file)) if self.config_dict: conf.update(self.config_dict) return conf def reload(self): if not self.config_file: return self.update(self.load()) def read_config(self, config_file): """ Reads the configuration file and updates this object while allowing for inherited configurations. """ conf_file = self.sitepath.child( config_file if config_file else 'site.yaml') conf = {} if File(conf_file).exists: self.config_files.append(File(conf_file)) logger.info("Reading site configuration from [%s]", conf_file) with codecs.open(conf_file, 'r', 'utf-8') as stream: conf = yaml.load(stream) if 'extends' in conf: parent = self.read_config(conf['extends']) parent.update(conf) conf = parent self.load_time = datetime.now() return conf @property def deploy_root_path(self): """ Derives the deploy root path from the site path """ return self.sitepath.child_folder(self.deploy_root) @property def content_root_path(self): """ Derives the content root path from the site path """ return self.sitepath.child_folder(self.content_root) @property def media_root_path(self): """ Derives the media root path from the content path """ return self.content_root_path.child_folder(self.media_root) @property def layout_root_path(self): """ Derives the layout root path from the site path """ return self.sitepath.child_folder(self.layout_root)
class Config(Expando): """ Represents the hyde configuration file """ def __init__(self, sitepath, config_file=None, config_dict=None): default_config = dict( content_root='content', deploy_root='deploy', media_root='media', layout_root='layout', media_url='/media', site_url='/', not_found='404.html', plugins = [] ) conf = dict(**default_config) self.sitepath = Folder(sitepath) conf.update(self.read_config(config_file)) if config_dict: conf.update(config_dict) super(Config, self).__init__(conf) def read_config(self, config_file): """ Reads the configuration file and updates this object while allowing for inherited configurations. """ conf_file = self.sitepath.child( config_file if config_file else 'site.yaml') conf = {} if File(conf_file).exists: logger.info("Reading site configuration from [%s]", conf_file) with codecs.open(conf_file, 'r', 'utf-8') as stream: conf = yaml.load(stream) if 'extends' in conf: parent = self.read_config(conf['extends']) parent.update(conf) conf = parent return conf @property def deploy_root_path(self): """ Derives the deploy root path from the site path """ return self.sitepath.child_folder(self.deploy_root) @property def content_root_path(self): """ Derives the content root path from the site path """ return self.sitepath.child_folder(self.content_root) @property def media_root_path(self): """ Derives the media root path from the site path """ return self.sitepath.child_folder(self.media_root) @property def layout_root_path(self): """ Derives the layout root path from the site path """ return self.sitepath.child_folder(self.layout_root)
class Config(Expando): """ Represents the hyde configuration file """ def __init__(self, sitepath, config_file=None, config_dict=None): default_config = dict(mode='production', content_root='content', deploy_root='deploy', media_root='media', layout_root='layout', media_url='/media', base_url="/", not_found='404.html', plugins=[], ignore=["*~", "*.bak"]) conf = dict(**default_config) self.sitepath = Folder(sitepath) conf.update(self.read_config(config_file)) if config_dict: conf.update(config_dict) super(Config, self).__init__(conf) def read_config(self, config_file): """ Reads the configuration file and updates this object while allowing for inherited configurations. """ conf_file = self.sitepath.child( config_file if config_file else 'site.yaml') conf = {} if File(conf_file).exists: logger.info("Reading site configuration from [%s]", conf_file) with codecs.open(conf_file, 'r', 'utf-8') as stream: conf = yaml.load(stream) if 'extends' in conf: parent = self.read_config(conf['extends']) parent.update(conf) conf = parent return conf @property def deploy_root_path(self): """ Derives the deploy root path from the site path """ return self.sitepath.child_folder(self.deploy_root) @property def content_root_path(self): """ Derives the content root path from the site path """ return self.sitepath.child_folder(self.content_root) @property def media_root_path(self): """ Derives the media root path from the content path """ return self.content_root_path.child_folder(self.media_root) @property def layout_root_path(self): """ Derives the layout root path from the site path """ return self.sitepath.child_folder(self.layout_root)