Example #1
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)
Example #2
0
    def create(name, force=False):
        """Create new post file placeholder with a unique name.

        Arguments:
            name -- post name.
            force -- True to overwrite existing file;
                False to raise an exception."""
        created = datetime.now()
        post_name = urlify(name) or const.UNTITLED_POST
        file_name = PostSource._ymd(POST_NAME_FORMAT, created, post_name)
        post_path = os.path.join(pathes.posts(), file_name)

        count = 0
        while True:
            file_name = helpers.suffix(post_path, count)
            if force or not os.path.exists(file_name):
                created = created.strftime(conf.get("time_format")[0])
                text = const.PROTO_POST
                text = text.format(title=name, created=created)
                helpers.newfile(file_name, text)
                break
            count += 1
        return os.path.basename(file_name)