Merge branch 'master' of github.com:ametaireau/pelican

This commit is contained in:
Alexis Metaireau 2012-02-28 19:00:15 +01:00
commit f31d588839
11 changed files with 95 additions and 91 deletions

View file

@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from pelican.utils import slugify, truncate_html_words
from pelican.log import *
from pelican.settings import _DEFAULT_CONFIG
from datetime import datetime
import datetime
from os import getenv
from sys import platform, stdin
import locale
from pelican.log import *
from pelican.settings import _DEFAULT_CONFIG
from pelican.utils import slugify, truncate_html_words
class Page(object):
"""Represents a page
Given a content, and metadata, create an adequate object.
@ -90,7 +91,7 @@ class Page(object):
if isinstance(self.date_format, tuple):
locale.setlocale(locale.LC_ALL, self.date_format[0])
self.date_format = self.date_format[1]
if hasattr(self, 'date'):
if platform == 'win32':
self.locale_date = self.date.strftime(self.date_format.encode('ascii','xmlcharrefreplace')).decode(stdin.encoding)
@ -101,7 +102,7 @@ class Page(object):
if not hasattr(self, 'status'):
self.status = settings['DEFAULT_STATUS']
if not settings['WITH_FUTURE_DATES']:
if hasattr(self, 'date') and self.date > datetime.now():
if hasattr(self, 'date') and self.date > datetime.datetime.now():
self.status = 'draft'
# set summary
@ -130,11 +131,10 @@ class Page(object):
"""Dummy function"""
pass
summary = property(_get_summary, _set_summary, \
summary = property(_get_summary, _set_summary,
"Summary of the article. Based on the content. Can't be set")
class Article(Page):
mandatory_properties = ('title', 'date', 'category')

19
pelican/generators.py Executable file → Normal file
View file

@ -1,22 +1,23 @@
# -*- coding: utf-8 -*-
from operator import attrgetter, itemgetter
from itertools import chain
from functools import partial
from datetime import datetime
from collections import defaultdict
import os
import datetime
import math
import random
import urlparse
from collections import defaultdict
from functools import partial
from itertools import chain
from operator import attrgetter, itemgetter
from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader
from jinja2.exceptions import TemplateNotFound
from pelican.utils import copy, get_relative_path, process_translations, open
from pelican.utils import slugify
from pelican.contents import Article, Page, is_valid_content
from pelican.readers import read_file
from pelican.log import *
from pelican.readers import read_file
from pelican.utils import copy, process_translations, open
from pelican.utils import slugify
class Generator(object):
@ -231,7 +232,7 @@ class ArticlesGenerator(Generator):
if 'date' not in metadata.keys()\
and self.settings['FALLBACK_ON_FS_DATE']:
metadata['date'] = datetime.fromtimestamp(os.stat(f).st_ctime)
metadata['date'] = datetime.datetime.fromtimestamp(os.stat(f).st_ctime)
article = Article(content, metadata, settings=self.settings,
filename=f)

View file

@ -1,8 +1,8 @@
import os
import sys
from logging import CRITICAL, ERROR, WARN, INFO, DEBUG
from logging import critical, error, info, warning, warn, debug
from logging import Formatter, getLogger, StreamHandler
import sys
import os
global ANSI
ANSI = {
@ -62,20 +62,18 @@ class TextFormatter(Formatter):
class DummyFormatter(object):
"""
A dummy class.
Return an instance of the appropriate formatter (ANSIFormatter if sys.stdout.isatty() is True, else TextFormatter)
Return an instance of the appropriate formatter (ANSIFormatter if
sys.stdout.isatty() is True, else TextFormatter)
"""
def __new__(cls, *args, **kwargs):
if os.isatty(sys.stdout.fileno())\
and not sys.platform.startswith('win'):
and not sys.platform.startswith('win'):
return ANSIFormatter(*args, **kwargs)
else:
return TextFormatter( *args, **kwargs)
def init(level=None, logger=getLogger(), handler=StreamHandler()):
fmt = DummyFormatter()
handler.setFormatter(fmt)
@ -94,15 +92,15 @@ if __name__ == '__main__':
__all__ = [
"debug",
"info",
"warn",
"debug",
"info",
"warn",
"warning",
"error",
"critical",
"DEBUG",
"INFO",
"WARN",
"ERROR",
"error",
"critical",
"DEBUG",
"INFO",
"WARN",
"ERROR",
"CRITICAL"
]
]

View file

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import re
import os
import shutil
import time
import calendar
import pytz
from datetime import datetime
import re
import shutil
from codecs import open as _open
from datetime import datetime
from itertools import groupby
from operator import attrgetter
from pelican.log import warning, info
@ -18,10 +17,10 @@ def get_date(string):
If no format matches the given date, raise a ValuEerror
"""
string = re.sub(' +', ' ', string)
formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M',
formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M',
'%Y-%m-%d', '%Y/%m/%d',
'%d-%m-%Y', '%Y-%d-%m', # Weird ones
'%d/%m/%Y', '%d.%m.%Y',
'%d/%m/%Y', '%d.%m.%Y',
'%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S']
for date_format in formats:
try:
@ -66,7 +65,7 @@ def copy(path, source, destination, destination_path=None, overwrite=False):
source_ = os.path.abspath(os.path.expanduser(os.path.join(source, path)))
destination_ = os.path.abspath(
os.path.expanduser(os.path.join(destination, destination_path)))
os.path.expanduser(os.path.join(destination, destination_path)))
if os.path.isdir(source_):
try:
@ -82,6 +81,7 @@ def copy(path, source, destination, destination_path=None, overwrite=False):
shutil.copy(source_, destination_)
info('copying %s to %s' % (source_, destination_))
def clean_output_dir(path):
"""Remove all the files from the output directory"""
@ -230,6 +230,7 @@ def files_changed(path, extensions):
return True
return False
def set_date_tzinfo(d, tz_name=None):
""" Date without tzinfo shoudbe utc.
This function set the right tz to date that aren't utc and don't have tzinfo

View file

@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
import os
import re
from codecs import open
from functools import partial
import locale
import re
from feedgenerator import Atom1Feed, Rss201rev2Feed
from pelican.utils import get_relative_path, set_date_tzinfo
from pelican.paginator import Paginator
from pelican.log import *
from pelican.utils import get_relative_path, set_date_tzinfo
class Writer(object):
@ -38,8 +38,8 @@ class Writer(object):
description=item.content,
categories=item.tags if hasattr(item, 'tags') else None,
author_name=getattr(item, 'author', 'John Doe'),
pubdate=set_date_tzinfo(item.date,
self.settings.get('TIMEZONE', None)))
pubdate=set_date_tzinfo(item.date,
self.settings.get('TIMEZONE', None)))
def write_feed(self, elements, context, filename=None, feed_type='atom'):
"""Generate a feed with the list of articles provided
@ -90,7 +90,7 @@ class Writer(object):
:param context: dict to pass to the templates.
:param relative_urls: use relative urls or absolutes ones
:param paginated: dict of article list to paginate - must have the
same length (same list in different orders)
same length (same list in different orders)
:param **kwargs: additional variables to pass to the templates
"""
@ -142,14 +142,14 @@ class Writer(object):
paginator = paginators[key]
page = paginator.page(page_num+1)
paginated_localcontext.update({'%s_paginator' % key: paginator,
'%s_page' % key: page})
'%s_page' % key: page})
if page_num > 0:
ext = '.' + paginated_name.rsplit('.')[-1]
paginated_name = paginated_name.replace(ext,
'%s%s' % (page_num + 1, ext))
'%s%s' % (page_num + 1, ext))
_write_file(template, paginated_localcontext, self.output_path,
paginated_name)
paginated_name)
else:
# no pagination
_write_file(template, localcontext, self.output_path, name)
@ -161,7 +161,7 @@ class Writer(object):
:param name: name of the file to output.
:param context: dict that will be passed to the templates, which need to
be updated.
be updated.
"""
def _update_content(name, input):
"""Change all the relatives paths of the input content to relatives
@ -185,11 +185,11 @@ class Writer(object):
def replacer(m):
relative_path = m.group('path')
dest_path = os.path.normpath( os.sep.join( (get_relative_path(name),
"static", relative_path) ) )
"static", relative_path) ) )
return m.group('markup') + m.group('quote') + dest_path + m.group('quote')
return hrefs.sub(replacer, content)
if context is None:
return
if hasattr(context, 'values'):
@ -208,4 +208,4 @@ class Writer(object):
if relative_path not in paths:
paths.append(relative_path)
setattr(item, "_get_content",
partial(_update_content, name, item))
partial(_update_content, name, item))