Beispiel #1
0
def move(path):
    '''
    Demotes given file to draft.
    '''
    # get dirname and filename
    dirname, filename = os.path.split(path)

    # get docname without extension
    docname = os.path.splitext(filename)[0]

    draft = os.path.join(utils.get_path(paths.root, "drafts"), filename)

    # move file
    target_dir = utils.get_path(paths.root, "drafts")
    utils.move(path, target_dir)

    # check if file is a post or a page
    if os.path.basename(dirname) == "pages":
        docname = "pages/" + docname
    else:
        match = re.match(r".*(?P<y>\d{4}).(?P<m>\d{2}).(?P<d>\d{2})$", dirname)
        if not match:
            return draft
        g = match.group
        docname = "/".join([g("y"), g("m"), g("d"), docname])

    # remove file from TOC
    master.remove_doc(docname)

    return draft
Beispiel #2
0
    def __init__(self, title=None, path=None, date=None):
        '''
        Initializes a new post and creates path to it if it doesn't already
        exist.
        '''
        self.title = title

        # get year, month and day from date
        self.year, self.month, self.day = utils.split_date(date)

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create post directory if it doesn't exist and get post path
        self.path = os.path.join(
            utils.get_path(
                paths.root,
                self.year,
                self.month,
                self.day),
            self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "/".join([self.year, self.month, self.day, self.name])
Beispiel #3
0
    def __init__(self, title=None, path=None, date=None):
        '''
        Initializes a new post and creates path to it if it doesn't already
        exist.
        '''
        self.title = title

        # get year, month and day from date
        self.year, self.month, self.day = utils.split_date(date)

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create post directory if it doesn't exist and get post path
        self.path = os.path.join(
            utils.get_path(
                paths.root,
                self.year,
                self.month,
                self.day),
            self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "/".join([self.year, self.month, self.day, self.name])
Beispiel #4
0
def move(path):
    '''
    Demotes given file to draft.
    '''
    # get dirname and filename
    dirname, filename = os.path.split(path)

    # get docname without extension
    docname = os.path.splitext(filename)[0]

    draft = os.path.join(utils.get_path(paths.root, "drafts"), filename)

    # move file
    shutil.move(path, draft)

    # check if file is a post or a page
    if os.path.basename(dirname) == "pages":
        docname = "pages/" + docname
    else:
        match = re.match(r".*(?P<y>\d{4}).(?P<m>\d{2}).(?P<d>\d{2})$", dirname)
        if not match:
            return draft
        g = match.group
        docname = "/".join([g("y"), g("m"), g("d"), docname])

    # remove file from TOC
    master.remove_doc(docname)

    return draft
Beispiel #5
0
def create(title, template=None):
    '''
    Creates a new post draft.
    '''
    name = utils.name_from_title(title)
    template = template or paths.post_template

    path = os.path.join(
        utils.get_path(paths.root, "drafts"),
        name + tinkerer.source_suffix,
    )

    if os.path.exists(path):
        raise Exception("Draft '%s' already exists at '%s" % (title, path))

    writer.render(
        template, path, {
            "title": title,
            "content": "",
            "author": "default",
            "categories": "none",
            "tags": "none"
        })

    return path
Beispiel #6
0
def create(title, template=None):
    '''
    Creates a new post draft.
    '''
    name = utils.name_from_title(title)
    template = template or paths.post_template

    path = os.path.join(
                    utils.get_path(
                        paths.root, 
                        "drafts"), 
                    name + tinkerer.source_suffix)

    if os.path.exists(path):
        raise Exception("Draft '%s' already exists at '%s" %
                        (title, path))

    writer.render(template, path,
            { "title"     : title,
              "content"   : "",
              "author"    : "default",
              "categories": "none",
              "tags"      : "none"})

    return path
Beispiel #7
0
def setup_blog():
    '''
    Sets up a new blog.
    '''
    utils.get_path(paths.root, "_static")
    utils.get_path(paths.root, "_templates")
    utils.get_path(paths.root, "drafts")
    copy_templates()
    write_master_file()
    write_index_file()
    return write_conf_file()
Beispiel #8
0
def setup_blog():
    '''
    Sets up a new blog.
    '''
    utils.get_path(paths.root, "_static")
    utils.get_path(paths.root, "_templates")
    utils.get_path(paths.root, "drafts")
    copy_templates()
    write_master_file()
    write_index_file()
    return write_conf_file()
Beispiel #9
0
    def __init__(self, title=None, path=None):
        '''
        Determines page filename based on title or given path and creates the
        path to the page if it doesn't already exist.
        '''
        self.title = title

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create page directory if it doesn't exist and get page path
        self.path = os.path.join(utils.get_path(paths.root, "pages"),
                                 self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "pages/" + self.name
Beispiel #10
0
    def __init__(self, title=None, path=None):
        '''
        Determines page filename based on title or given path and creates the
        path to the page if it doesn't already exist.
        '''
        self.title = title

        # get name from path if specified, otherwise from title
        if path:
            self.name = utils.name_from_path(path)
        else:
            self.name = utils.name_from_title(title)

        # create page directory if it doesn't exist and get page path
        self.path = os.path.join(
            utils.get_path(paths.root, "pages"),
            self.name) + tinkerer.source_suffix

        # docname as it should appear in TOC
        self.docname = "pages/" + self.name
Beispiel #11
0
def create(title):
    '''
    Creates a new post draft.
    '''
    name = utils.name_from_title(title)

    path = os.path.join(
                    utils.get_path(
                        paths.root, 
                        "drafts"), 
                    name + tinkerer.source_suffix)

    writer.render(paths.post_template, path,
            { "title"     : title,
              "content"   : "",
              "author"    : "default",
              "categories": "none",
              "tags"      : "none"})

    return path