Beispiel #1
0
    def create(name, force=False):
        """Creates page file.

        Arguments:
            name -- page name (will be used for file name and URL).
            force -- True to overwrite existing file;
                False to throw exception."""
        page_name = urlify(name, ext_map={ord(u"\\"): u"/"}) + ".md"
        file_name = os.path.join(pathes.pages(), page_name)
        if os.path.exists(file_name) and not force:
            raise PageExistsException(path=file_name)
        created = datetime.now().strftime(conf.get("time_format")[0])
        text = const.PROTO_PAGE
        helpers.newfile(file_name, text.format(title=name, created=created))
        return page_name
Beispiel #2
0
    def __init__(self):
        """Populate cache with source files."""
        self._cache = []

        proc_queue = [
            (source.AssetSource, pathes.theme_assets()),
            (source.AssetSource, pathes.assets()),
            (source.PageSource, pathes.pages()),
            (source.PostSource, pathes.posts()),
        ]

        self._errors = []
        for src_type, dir_path in proc_queue:
            def add_source(root, rel):
                try:
                    file_name = os.path.join(root, rel)
                    self._cache.append(src_type(file_name, root))
                except Exception as e:
                    self._errors.append((rel, e))

            helpers.walk(dir_path, add_source)