Ejemplo n.º 1
0
Archivo: core.py Proyecto: sjl/jilcrow
    def __init__(self, site_path, config_file=DEFAULT_CONFIG_FILE):
        try: os.chdir(site_path)
        except OSError: util.die('invalid path:', site_path)
        if not path.exists(config_file):
            util.die('%s not found' % config_file)

        dict.__init__(self, DEFAULT_CONFIG)
        self.update(locale.localeconv())
        with open(config_file) as f:
            for k, v in yaml.load(f).items():
                k = util.norm_key(k)
                if type(v) is dict:
                    self[k] = dict(self.get(k, {}), **v)
                else:
                    self[k] = v
Ejemplo n.º 2
0
    def add(self, page):
        if page.id in self.pages:
            util.die('duplicate page id: %s' % page.id)
        self.pages[page.id] = page

        if type(page) is pages.Tag:
            self.tags[page.name] = page
        elif 'tags' in page:
            page_tags = {}
            for tag_name in page.get('tags', []):
                if tag_name in self.tags:
                    tag = self.tags[tag_name]
                else:
                    tag = pages.Tag(self._site, tag_name)
                    self.add(tag)
                tag.add(page)
                page_tags[tag_name] = tag
            page['tags'] = page_tags
Ejemplo n.º 3
0
    def __init__(self, site_path, config_file=DEFAULT_CONFIG_FILE):
        try: os.chdir(site_path)
        except OSError: util.die('invalid path:', site_path)
        if not path.exists(config_file):
            util.die('%s not found' % config_file)

        self.update(locale.localeconv())
        cp = RawConfigParser()
        cp.optionxform = str
        cp.readfp(StringIO(DEFAULT_CONFIG))
        cp.read(config_file)
        self.update(self.normalize(cp.items("MAIN")))
        self['dirs'] = self.normalize(cp.items("DIRS"))
        self['files_rename'] = self.normalize(cp.items("RENAME"))
        self['sidebars'] = self.normalize(cp.items("SIDEBARS"))
        self['menu'] = dict(cp.items("MENU"))
        self['links'] = cp.items("LINKS")
        self['content_extensions'] = [x.strip() for x in self['content_extensions'].split(",")]
        if 'tags' in self:
            self['tags'] = [x.strip() for x in self['tags'].split(",")]