Beispiel #1
0
def loaddir(directory, clear=False):
    if clear:
        Book.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.':
            continue
        if next in ('categories', 'template'):
            continue
        next = path.join(directory, next)
        if path.isdir(next):
            queue.extend([path.join(next, f) for f in os.listdir(next)])
            continue

        filecontent = file(next).read()
        header, content = filecontent.split('\n---\n')
        header = yaml.load(header)
        content = preprocess_rst_content(content)
        review_date = parsedate(header['review_date'])
        review_date = time.strftime('%Y-%m-%d', review_date)
        btags = []
        for c in header.get('tags', '').split():
            btags.append(tag_for(c))
        B = Book(slug=header['slug'],
                 title=header['title'],
                 booktitle=header['booktitle'],
                 author=header['author'],
                 content=content,
                 review_date=review_date)
        B.save()
        for t in btags:
            B.tags.add(t)
Beispiel #2
0
def loaddir(directory, clear=False):
    if clear:
        Book.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.': continue
        if next in ('categories', 'template'): continue
        next = path.join(directory, next)
        if path.isdir(next):
            queue.extend([
                path.join(next,f) for f in os.listdir(next)
                ])
            continue

        filecontent = file(next).read()
        header, content = filecontent.split('\n---\n')
        header = yaml.load(header)
        content = preprocess_rst_content(content)
        review_date = parsedate(header['review_date'])
        review_date = time.strftime('%Y-%m-%d', review_date)
        B = Book(slug=header['slug'], title=header['title'], booktitle=header['booktitle'], author=header['author'], content=content, review_date=review_date)
        B.save()
        for c in header.get('tags','').split():
            B.tags.add(tag_for(c))
Beispiel #3
0
def loaddir(directory, clear=False):
    if clear:
        BlogPost.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.': continue
        if next in ('template.rst', 'template'): continue
        next = path.join(directory, next)
        if path.isdir(next):
            queue.extend([
                path.join(next,f) for f in os.listdir(next)
                ])
            continue

        filecontent = file(next).read()
        parts = filecontent.split('\n---\n', 1)
        fields, content = parts
        if len(parts) != 2:
            raise IOError('gitcms.blog.load: expected "---" separator in file %s' % next)
        fields = yaml.load(fields)
        fields['timestamp'] = parsedatetime(fields['timestamp'])
        fields['year_month_slug'] = time.strftime('%%Y/%%B/%s' % fields['slug'], fields['timestamp'])
        fields['timestamp'] = time.strftime('%Y-%m-%d %H:%M', fields['timestamp'])
        fields['content'] = preprocess_rst_content(content)
        categories = fields.get('categories', '')
        if 'categories' in fields: del fields['categories']
        ptags = []
        if categories:
            for c in categories.split():
                ptags.append(tag_for(c))
        # if we arrived here and no errors, then it is safe
        # to add our post.
        #
        P = BlogPost(**fields)
        P.save()
        for t in ptags:
            P.tags.add(t)
Beispiel #4
0
def loaddir(directory, clear=False):
    if clear:
        BlogPost.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.':
            continue

        if next in ('template.rst', 'template'):
            continue

        next = os.path.join(directory, next)
        if os.path.isdir(next):
            queue.extend([os.path.join(next, f) for f in os.listdir(next)])
            continue

        filecontent = file(next).read()
        parts = filecontent.split('\n---\n', 1)
        fields, content = parts
        if len(parts) != 2:
            err_msg = 'gitcms.blog.load: expected "---" separator in file %s'
            raise IOError(err_msg % next)
        fields = yaml.load(fields)
        fields['content'] = preprocess_rst_content(content)
        categories = fields.get('categories', '')
        if 'categories' in fields:
            del fields['categories']
        ptags = []
        if categories:
            for c in categories.split():
                ptags.append(tag_for(c))
        P = BlogPost(**fields)
        P.save()
        for t in ptags:
            P.tags.add(t)
Beispiel #5
0
def loaddir(directory, clear=False):
    if clear:
        BlogPost.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.':
            continue

        if next in ('template.rst', 'template'):
            continue

        next = os.path.join(directory, next)
        if os.path.isdir(next):
            queue.extend([os.path.join(next, f) for f in os.listdir(next)])
            continue

        filecontent = file(next).read()
        parts = filecontent.split('\n---\n', 1)
        fields, content = parts
        if len(parts) != 2:
            err_msg = 'gitcms.blog.load: expected "---" separator in file %s'
            raise IOError(err_msg % next)
        fields = yaml.load(fields)
        fields['content'] = preprocess_rst_content(content)
        categories = fields.get('categories', '')
        if 'categories' in fields:
            del fields['categories']
        ptags = []
        if categories:
            for c in categories.split():
                ptags.append(tag_for(c))
        P = BlogPost(**fields)
        P.save()
        for t in ptags:
            P.tags.add(t)