mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #110 from kmike/master
Python 2.5 compatibility, executable setup.py and up-to-date docstrings. (thanks kmike)
This commit is contained in:
commit
1baca77f3a
4 changed files with 24 additions and 18 deletions
|
|
@ -6,8 +6,7 @@ class Page(object):
|
||||||
"""Represents a page
|
"""Represents a page
|
||||||
Given a content, and metadatas, create an adequate object.
|
Given a content, and metadatas, create an adequate object.
|
||||||
|
|
||||||
:param string: the string to parse, containing the original content.
|
:param content: the string to parse, containing the original content.
|
||||||
:param markup: the markup language to use while parsing.
|
|
||||||
"""
|
"""
|
||||||
mandatory_properties = ('title',)
|
mandatory_properties = ('title',)
|
||||||
|
|
||||||
|
|
@ -90,6 +89,6 @@ def is_valid_content(content, f):
|
||||||
try:
|
try:
|
||||||
content.check_properties()
|
content.check_properties()
|
||||||
return True
|
return True
|
||||||
except NameError as e:
|
except NameError, e:
|
||||||
error(u"Skipping %s: impossible to find informations about '%s'" % (f, e))
|
error(u"Skipping %s: impossible to find informations about '%s'" % (f, e))
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class Generator(object):
|
||||||
loader=FileSystemLoader(self._templates_path),
|
loader=FileSystemLoader(self._templates_path),
|
||||||
extensions=self.settings.get('JINJA_EXTENSIONS', []),
|
extensions=self.settings.get('JINJA_EXTENSIONS', []),
|
||||||
)
|
)
|
||||||
|
|
||||||
# get custom Jinja filters from user settings
|
# get custom Jinja filters from user settings
|
||||||
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
||||||
self._env.filters.update(custom_filters)
|
self._env.filters.update(custom_filters)
|
||||||
|
|
@ -63,7 +63,13 @@ class Generator(object):
|
||||||
extensions = self.markup
|
extensions = self.markup
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
for root, dirs, temp_files in os.walk(path, followlinks=True):
|
|
||||||
|
try:
|
||||||
|
iter = os.walk(path, followlinks=True)
|
||||||
|
except TypeError: # python 2.5 does not support followlinks
|
||||||
|
iter = os.walk(path)
|
||||||
|
|
||||||
|
for root, dirs, temp_files in iter:
|
||||||
for e in exclude:
|
for e in exclude:
|
||||||
if e in dirs:
|
if e in dirs:
|
||||||
dirs.remove(e)
|
dirs.remove(e)
|
||||||
|
|
@ -116,11 +122,11 @@ class ArticlesGenerator(Generator):
|
||||||
if 'TAG_FEED' in self.settings:
|
if 'TAG_FEED' in self.settings:
|
||||||
for tag, arts in self.tags.items():
|
for tag, arts in self.tags.items():
|
||||||
arts.sort(key=attrgetter('date'), reverse=True)
|
arts.sort(key=attrgetter('date'), reverse=True)
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['TAG_FEED'] % tag)
|
self.settings['TAG_FEED'] % tag)
|
||||||
|
|
||||||
if 'TAG_FEED_RSS' in self.settings:
|
if 'TAG_FEED_RSS' in self.settings:
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['TAG_FEED_RSS'] % tag, feed_type='rss')
|
self.settings['TAG_FEED_RSS'] % tag, feed_type='rss')
|
||||||
|
|
||||||
translations_feeds = defaultdict(list)
|
translations_feeds = defaultdict(list)
|
||||||
|
|
@ -142,7 +148,7 @@ class ArticlesGenerator(Generator):
|
||||||
relative_urls = self.settings.get('RELATIVE_URLS')
|
relative_urls = self.settings.get('RELATIVE_URLS')
|
||||||
)
|
)
|
||||||
|
|
||||||
# to minimize the number of relative path stuff modification
|
# to minimize the number of relative path stuff modification
|
||||||
# in writer, articles pass first
|
# in writer, articles pass first
|
||||||
article_template = self.get_template('article')
|
article_template = self.get_template('article')
|
||||||
for article in chain(self.translations, self.articles):
|
for article in chain(self.translations, self.articles):
|
||||||
|
|
@ -220,7 +226,7 @@ class ArticlesGenerator(Generator):
|
||||||
# sort the articles by date
|
# sort the articles by date
|
||||||
self.articles.sort(key=attrgetter('date'), reverse=True)
|
self.articles.sort(key=attrgetter('date'), reverse=True)
|
||||||
self.dates = list(self.articles)
|
self.dates = list(self.articles)
|
||||||
self.dates.sort(key=attrgetter('date'),
|
self.dates.sort(key=attrgetter('date'),
|
||||||
reverse=self.context['REVERSE_ARCHIVE_ORDER'])
|
reverse=self.context['REVERSE_ARCHIVE_ORDER'])
|
||||||
|
|
||||||
# create tag cloud
|
# create tag cloud
|
||||||
|
|
@ -236,7 +242,7 @@ class ArticlesGenerator(Generator):
|
||||||
if tags:
|
if tags:
|
||||||
max_count = max(tags)
|
max_count = max(tags)
|
||||||
steps = self.settings.get('TAG_CLOUD_STEPS')
|
steps = self.settings.get('TAG_CLOUD_STEPS')
|
||||||
|
|
||||||
# calculate word sizes
|
# calculate word sizes
|
||||||
self.tag_cloud = [
|
self.tag_cloud = [
|
||||||
(
|
(
|
||||||
|
|
@ -327,7 +333,7 @@ class PdfGenerator(Generator):
|
||||||
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
||||||
self.pdfcreator.createPdf(text=open(obj.filename), output=output_pdf)
|
self.pdfcreator.createPdf(text=open(obj.filename), output=output_pdf)
|
||||||
info(u' [ok] writing %s' % output_pdf)
|
info(u' [ok] writing %s' % output_pdf)
|
||||||
|
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import with_statement
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from codecs import open
|
from codecs import open
|
||||||
|
|
@ -44,9 +45,8 @@ class Writer(object):
|
||||||
Return the feed. If no output_path or filename is specified, just return
|
Return the feed. If no output_path or filename is specified, just return
|
||||||
the feed object.
|
the feed object.
|
||||||
|
|
||||||
:param articles: the articles to put on the feed.
|
:param elements: the articles to put on the feed.
|
||||||
:param context: the context to get the feed metadata.
|
:param context: the context to get the feed metadata.
|
||||||
:param output_path: where to output the file.
|
|
||||||
:param filename: the filename to output.
|
:param filename: the filename to output.
|
||||||
:param feed_type: the feed type to use (atom or rss)
|
:param feed_type: the feed type to use (atom or rss)
|
||||||
"""
|
"""
|
||||||
|
|
@ -139,7 +139,7 @@ class Writer(object):
|
||||||
'%s_page' % key: page})
|
'%s_page' % key: page})
|
||||||
if page_num > 0:
|
if page_num > 0:
|
||||||
ext = '.' + paginated_name.rsplit('.')[-1]
|
ext = '.' + paginated_name.rsplit('.')[-1]
|
||||||
paginated_name = paginated_name.replace(ext,
|
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,
|
_write_file(template, paginated_localcontext, self.output_path,
|
||||||
|
|
@ -149,7 +149,7 @@ class Writer(object):
|
||||||
_write_file(template, localcontext, self.output_path, name)
|
_write_file(template, localcontext, self.output_path, name)
|
||||||
|
|
||||||
def update_context_contents(self, name, context):
|
def update_context_contents(self, name, context):
|
||||||
"""Recursively run the context to find elements (articles, pages, etc)
|
"""Recursively run the context to find elements (articles, pages, etc)
|
||||||
whose content getter needs to
|
whose content getter needs to
|
||||||
be modified in order to deal with relative paths.
|
be modified in order to deal with relative paths.
|
||||||
|
|
||||||
|
|
@ -188,12 +188,12 @@ class Writer(object):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def inject_update_method(self, name, item):
|
def inject_update_method(self, name, item):
|
||||||
"""Replace the content attribute getter of an element by a function
|
"""Replace the content attribute getter of an element by a function
|
||||||
that will deals with its relatives paths.
|
that will deals with its relatives paths.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _update_object_content(name, input):
|
def _update_object_content(name, input):
|
||||||
"""Change all the relatives paths of the input content to relatives
|
"""Change all the relatives paths of the input content to relatives
|
||||||
paths suitable fot the ouput content
|
paths suitable fot the ouput content
|
||||||
|
|
||||||
:param name: path of the output.
|
:param name: path of the output.
|
||||||
|
|
|
||||||
3
setup.py
Normal file → Executable file
3
setup.py
Normal file → Executable file
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -17,7 +18,7 @@ setup(
|
||||||
long_description=open('README.rst').read(),
|
long_description=open('README.rst').read(),
|
||||||
packages = ['pelican'],
|
packages = ['pelican'],
|
||||||
include_package_data = True,
|
include_package_data = True,
|
||||||
install_requires = requires,
|
install_requires = requires,
|
||||||
scripts = ['bin/pelican'],
|
scripts = ['bin/pelican'],
|
||||||
classifiers = ['Development Status :: 5 - Production/Stable',
|
classifiers = ['Development Status :: 5 - Production/Stable',
|
||||||
'Environment :: Console',
|
'Environment :: Console',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue