From 08b40c7967cdf5ef0780f1f2b4d41d29b31d6578 Mon Sep 17 00:00:00 2001 From: draftcode Date: Mon, 12 Mar 2012 01:33:30 +0900 Subject: [PATCH 01/33] Make names of metadata lower. --- pelican/readers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index a581e458..632c72b9 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -36,8 +36,8 @@ class Reader(object): self.settings = settings def process_metadata(self, name, value): - if name.lower() in _METADATA_PROCESSORS: - return _METADATA_PROCESSORS[name.lower()](value, self.settings) + if name in _METADATA_PROCESSORS: + return _METADATA_PROCESSORS[name](value, self.settings) return value @@ -75,6 +75,7 @@ class RstReader(Reader): else: # standard fields (e.g. address) name = element.tagname value = element.astext() + name = name.lower() output[name] = self.process_metadata(name, value) return output From a4ce10d88e76e60a5da6579d3d04d79ba0d02b7a Mon Sep 17 00:00:00 2001 From: draftcode Date: Mon, 12 Mar 2012 02:24:26 +0900 Subject: [PATCH 02/33] Add a test for readers. --- tests/content/article_with_uppercase_metadata.rst | 6 ++++++ tests/test_readers.py | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/content/article_with_uppercase_metadata.rst diff --git a/tests/content/article_with_uppercase_metadata.rst b/tests/content/article_with_uppercase_metadata.rst new file mode 100644 index 00000000..e26cdd13 --- /dev/null +++ b/tests/content/article_with_uppercase_metadata.rst @@ -0,0 +1,6 @@ + +This is a super article ! +######################### + +:Category: Yeah + diff --git a/tests/test_readers.py b/tests/test_readers.py index d4f0aecf..4472d7fe 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -34,6 +34,14 @@ class RstReaderTest(unittest.TestCase): for key, value in expected.items(): self.assertEquals(value, metadata[key], key) + def test_article_metadata_key_lowercase(self): + """Keys of metadata should be lowercase.""" + reader = readers.RstReader({}) + content, metadata = reader.read(_filename('article_with_uppercase_metadata.rst')) + + self.assertIn('category', metadata, "Key should be lowercase.") + self.assertEquals('Yeah', metadata.get('category'), "Value keeps cases.") + def test_typogrify(self): # if nothing is specified in the settings, the content should be # unmodified From 89a481f8e77a96970e03dc0576cb4156fb53c4a1 Mon Sep 17 00:00:00 2001 From: Thanos Lefteris Date: Sun, 11 Mar 2012 21:00:38 +0200 Subject: [PATCH 03/33] Match closing tag --- pelican/themes/simple/templates/archives.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/themes/simple/templates/archives.html b/pelican/themes/simple/templates/archives.html index e6364efa..1ea9b58f 100644 --- a/pelican/themes/simple/templates/archives.html +++ b/pelican/themes/simple/templates/archives.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% block content %} -

Archives for {{ SITENAME }}

+

Archives for {{ SITENAME }}

{% for article in dates %} From acad3e864d6fc729ce08407e619b61da7846f792 Mon Sep 17 00:00:00 2001 From: Thanos Lefteris Date: Sun, 11 Mar 2012 21:08:18 +0200 Subject: [PATCH 04/33] Double-quote HTML attribute --- pelican/themes/notmyidea/templates/archives.html | 2 +- pelican/themes/simple/templates/archives.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pelican/themes/notmyidea/templates/archives.html b/pelican/themes/notmyidea/templates/archives.html index 5ba2c817..f7f1c400 100644 --- a/pelican/themes/notmyidea/templates/archives.html +++ b/pelican/themes/notmyidea/templates/archives.html @@ -6,7 +6,7 @@
{% for article in dates %}
{{ article.locale_date }}
-
{{ article.title }}
+
{{ article.title }}
{% endfor %}
diff --git a/pelican/themes/simple/templates/archives.html b/pelican/themes/simple/templates/archives.html index e6364efa..c1a9087e 100644 --- a/pelican/themes/simple/templates/archives.html +++ b/pelican/themes/simple/templates/archives.html @@ -5,7 +5,7 @@
{% for article in dates %}
{{ article.locale_date }}
-
{{ article.title }}
+
{{ article.title }}
{% endfor %}
{% endblock %} From e097175a77d94d41d8979c3fb4718b44c0e067b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:14:38 +0100 Subject: [PATCH 05/33] Import not used of BeautifulSoup --- tools/pelican_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index b883f7fc..c0d8bf1c 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -38,7 +38,7 @@ def wp2fields(xml): def dc2fields(file): """Opens a Dotclear export file, and yield pelican fields""" - from BeautifulSoup import BeautifulStoneSoup, BeautifulSoup + from BeautifulSoup import BeautifulStoneSoup in_cat = False in_post = False From c4f96b108f54a1968334767c93eb9d59dcb7f5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:16:11 +0100 Subject: [PATCH 06/33] Don't set unused fields of Dotclear post --- tools/pelican_import.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index c0d8bf1c..14f06138 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -85,10 +85,10 @@ def dc2fields(file): post_creadt = fields[6] # post_upddt = fields[7] # post_password = fields[8] - post_type = fields[9] + # post_type = fields[9] post_format = fields[10] - post_url = fields[11] - post_lang = fields[12] + # post_url = fields[11] + # post_lang = fields[12] post_title = fields[13] post_excerpt = fields[14] post_excerpt_xhtml = fields[15] From fec605b5775f0f9dba6e78a99f99dddcf09b8b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:17:06 +0100 Subject: [PATCH 07/33] Fix way to handle OSError (error doesn't exist) A better way would to use sys.stderr.write or PY3 print(file=sys.stderr) --- tools/pelican_import.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 14f06138..12c3597f 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -2,6 +2,7 @@ import argparse import os +import sys import time from codecs import open @@ -259,14 +260,14 @@ def main(): elif args.feed: input_type = 'feed' else: - print("you must provide either --wpfile, --dotclear or --feed options") + print("You must provide either --wpfile, --dotclear or --feed options") exit() if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: - error("Couldn't create the output folder: " + args.output) + print("Unable to create the output folder: " + args.output) exit() # TODO: refactor this long assignment From d7f0b1637e1f6ed4c0ea54f3e314981c72581292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:20:33 +0100 Subject: [PATCH 08/33] Cleanup awful line with TODO in pelican-import --- tools/pelican_import.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 12c3597f..8a425776 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -270,14 +270,11 @@ def main(): print("Unable to create the output folder: " + args.output) exit() - # TODO: refactor this long assignment - input_type, input, out_markup, output_path, dircat=False = input_type, args.input, args.markup, args.output, args.dircat - if input_type == 'wordpress': - fields = wp2fields(input) + fields = wp2fields(args.input) elif input_type == 'dotclear': - fields = dc2fields(input) + fields = dc2fields(args.input) elif input_type == 'feed': - fields = feed2fields(input) + fields = feed2fields(args.input) - fields2pelican(fields, out_markup, output_path, dircat=dircat) + fields2pelican(fields, args.markup, args.output, dircat=args.dircat or False) From 2f79d5f0526bb2fa6efd4755349d2673298ba608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 16:52:28 +0100 Subject: [PATCH 09/33] Improve error handling when pandoc is missing --- tools/pelican_import.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 8a425776..b89740df 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -2,6 +2,7 @@ import argparse import os +import subprocess import sys import time @@ -217,7 +218,20 @@ def fields2pelican(fields, out_markup, output_path, dircat=False): content = content.replace("\n", "
\n") fp.write(content) - os.system('pandoc --normalize --reference-links --from=html --to=%s -o "%s" "%s"' % (out_markup, out_filename, html_filename)) + cmd = 'pandoc --normalize --reference-links --from=html --to={0} -o "{1}" "{2}"'.format( + out_markup, out_filename, html_filename) + + try: + rc = subprocess.call(cmd, shell=True) + if rc < 0: + print("Child was terminated by signal %d" % -rc) + exit() + elif rc > 0: + print("Please, check your Pandoc installation.") + exit() + except OSError, e: + print("Pandoc execution failed: %s" % e) + exit() os.remove(html_filename) From ff2426c4ad9e24c52d9a1d02f9c841d4a6438d00 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 13 Mar 2012 17:10:20 +0100 Subject: [PATCH 10/33] Fix for #245: return the summary of an article based on the :summary: metadata if it is set, else troncate the content. --- pelican/contents.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 4f424461..d8ccf9f3 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -89,9 +89,9 @@ class Page(object): if hasattr(self, 'date') and self.date > datetime.now(): self.status = 'draft' - # set summary - if not hasattr(self, 'summary'): - self.summary = truncate_html_words(self.content, 50) + # store the :summary: metadata if it is set + if 'summary' in metadata: + self._summary = metadata['summary'] def check_properties(self): """test that each mandatory property is set.""" @@ -126,8 +126,12 @@ class Page(object): return content def _get_summary(self): - """Returns the summary of an article, based on to the content""" - return truncate_html_words(self.content, 50) + """Returns the summary of an article, based on the :summary: metadata + if it is set, else troncate the content.""" + if hasattr(self, '_summary'): + return self._summary + else: + return truncate_html_words(self.content, 50) def _set_summary(self, summary): """Dummy function""" From c4418555223315455be8178c86aab1a980335a8a Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 13 Mar 2012 17:15:25 +0100 Subject: [PATCH 11/33] add a test for the summary metadata --- tests/test_contents.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/test_contents.py b/tests/test_contents.py index ed9885b6..8e1407dc 100644 --- a/tests/test_contents.py +++ b/tests/test_contents.py @@ -8,14 +8,20 @@ except ImportError, e: from pelican.contents import Page from pelican.settings import _DEFAULT_CONFIG +from jinja2.utils import generate_lorem_ipsum + +# generate one paragraph, enclosed with

+TEST_CONTENT = str(generate_lorem_ipsum(n=1)) +TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False) class TestPage(TestCase): def setUp(self): super(TestPage, self).setUp() self.page_kwargs = { - 'content': 'content', + 'content': TEST_CONTENT, 'metadata': { + 'summary': TEST_SUMMARY, 'title': 'foo bar', 'author': 'Blogger', }, @@ -27,11 +33,11 @@ class TestPage(TestCase): """ metadata = {'foo': 'bar', 'foobar': 'baz', 'title': 'foobar', } - page = Page('content', metadata=metadata) + page = Page(TEST_CONTENT, metadata=metadata) for key, value in metadata.items(): self.assertTrue(hasattr(page, key)) self.assertEqual(value, getattr(page, key)) - self.assertEqual(page.content, 'content') + self.assertEqual(page.content, TEST_CONTENT) def test_mandatory_properties(self): """If the title is not set, must throw an exception.""" @@ -39,6 +45,11 @@ class TestPage(TestCase): page = Page(**self.page_kwargs) page.check_properties() + def test_summary_from_metadata(self): + """If a :summary: metadata is given, it should be used.""" + page = Page(**self.page_kwargs) + self.assertEqual(page.summary, TEST_SUMMARY) + def test_slug(self): """If a title is given, it should be used to generate the slug.""" page = Page(**self.page_kwargs) From 4f95b9f05c9cf2d5f48786fb6831318e37a1f762 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 14 Mar 2012 09:38:36 +0100 Subject: [PATCH 12/33] remove useless .keys() for key in dict expressions --- pelican/generators.py | 5 ++--- pelican/readers.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index 2987dcfe..71208430 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -227,7 +227,7 @@ class ArticlesGenerator(Generator): continue # if no category is set, use the name of the path as a category - if 'category' not in metadata.keys(): + if 'category' not in metadata: if os.path.dirname(f) == self.path: category = self.settings['DEFAULT_CATEGORY'] @@ -238,8 +238,7 @@ class ArticlesGenerator(Generator): if category != '': metadata['category'] = Category(category, self.settings) - if 'date' not in metadata.keys()\ - and self.settings['FALLBACK_ON_FS_DATE']: + if 'date' not in metadata and self.settings['FALLBACK_ON_FS_DATE']: metadata['date'] = datetime.datetime.fromtimestamp( os.stat(f).st_ctime) diff --git a/pelican/readers.py b/pelican/readers.py index 632c72b9..d4e13b4d 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -145,7 +145,7 @@ def read_file(filename, fmt=None, settings=None): if not fmt: fmt = filename.split('.')[-1] - if fmt not in _EXTENSIONS.keys(): + if fmt not in _EXTENSIONS: raise TypeError('Pelican does not know how to parse %s' % filename) reader = _EXTENSIONS[fmt](settings) From 39bdbcfd86bc0f3025ec82b51d86892796356c10 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 14 Mar 2012 12:36:55 +0100 Subject: [PATCH 13/33] files_changed: cleanup and add a test --- pelican/utils.py | 3 --- tests/test_utils.py | 22 ++++++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index 1b84f108..7ffd9eb9 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -210,9 +210,6 @@ LAST_MTIME = 0 def files_changed(path, extensions): """Return True if the files have changed since the last check""" - def with_extension(f): - return any(f.endswith(ext) for ext in extensions) - def file_times(path): """Return the last time files have been modified""" for root, dirs, files in os.walk(path): diff --git a/tests/test_utils.py b/tests/test_utils.py index 9654825e..40f710d9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,11 +3,12 @@ try: import unittest2 as unittest except ImportError: import unittest # NOQA + +import os import datetime +import time from pelican import utils -from pelican.contents import Article - from support import get_article @@ -73,3 +74,20 @@ class TestUtils(unittest.TestCase): self.assertIn(fr_article1, trans) self.assertNotIn(en_article1, trans) self.assertNotIn(fr_article1, index) + + def test_files_changed(self): + "Test if file changes are correctly detected" + + path = os.path.join(os.path.dirname(__file__), 'content') + filename = os.path.join(path, 'article_with_metadata.rst') + changed = utils.files_changed(path, 'rst') + self.assertEquals(changed, True) + + changed = utils.files_changed(path, 'rst') + self.assertEquals(changed, False) + + t = time.time() + os.utime(filename, (t, t)) + changed = utils.files_changed(path, 'rst') + self.assertEquals(changed, True) + self.assertAlmostEqual(utils.LAST_MTIME, t, places=2) From 4bac1ee7451cda501bb7826f808f11ff12574cf4 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 14 Mar 2012 19:54:28 +0000 Subject: [PATCH 14/33] - remove default=None with argparse is redundant since it's the default value already. - use the argparse.ArgumentDefaultsHelpFormatter as the formatter_class, to print out automatically the default values --- pelican/__init__.py | 9 +++++---- tools/pelican_import.py | 3 ++- tools/pelican_quickstart.py | 10 ++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 0b53dbcc..5ffcc3b5 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -135,7 +135,8 @@ class Pelican(object): def main(): parser = argparse.ArgumentParser(description="""A tool to generate a - static blog, with restructured text input files.""") + static blog, with restructured text input files.""", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(dest='path', nargs='?', help='Path where to find the content files.') @@ -145,11 +146,11 @@ def main(): parser.add_argument('-o', '--output', dest='output', help='Where to output the generated files. If not specified, a ' 'directory will be created, named "output" in the current path.') - parser.add_argument('-m', '--markup', default=None, dest='markup', + parser.add_argument('-m', '--markup', dest='markup', help='The list of markup language to use (rst or md). Please indicate ' 'them separated by commas.') - parser.add_argument('-s', '--settings', dest='settings', default='', - help='The settings of the application. Default to False.') + parser.add_argument('-s', '--settings', dest='settings', + help='The settings of the application.') parser.add_argument('-d', '--delete-output-directory', dest='delete_outputdir', action='store_true', help='Delete the output directory.') diff --git a/tools/pelican_import.py b/tools/pelican_import.py index b883f7fc..bfa0f623 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -234,7 +234,8 @@ def fields2pelican(fields, out_markup, output_path, dircat=False): def main(): parser = argparse.ArgumentParser( description="Transform feed, Wordpress or Dotclear files to rst files." - "Be sure to have pandoc installed") + "Be sure to have pandoc installed", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(dest='input', help='The input file to read') parser.add_argument('--wpfile', action='store_true', dest='wpfile', diff --git a/tools/pelican_quickstart.py b/tools/pelican_quickstart.py index 04fc20be..4427be65 100755 --- a/tools/pelican_quickstart.py +++ b/tools/pelican_quickstart.py @@ -193,14 +193,16 @@ def ask(question, answer=str, default=None, l=None): def main(): - parser = argparse.ArgumentParser(description="A kickstarter for pelican") + parser = argparse.ArgumentParser( + description="A kickstarter for pelican", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-p', '--path', default=".", help="The path to generate the blog into") - parser.add_argument('-t', '--title', default=None, metavar="title", + parser.add_argument('-t', '--title', metavar="title", help='Set the title of the website') - parser.add_argument('-a', '--author', default=None, metavar="author", + parser.add_argument('-a', '--author', metavar="author", help='Set the author name of the website') - parser.add_argument('-l', '--lang', default=None, metavar="lang", + parser.add_argument('-l', '--lang', metavar="lang", help='Set the default lang of the website') args = parser.parse_args() From ec31832c5cf5f1bdfcf42a6719648c7c5efdffb2 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 14 Mar 2012 20:04:58 +0000 Subject: [PATCH 15/33] - reorganize imports and remove unused import - remove trailing spaces at the end of the generated files --- tools/pelican_quickstart.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/pelican_quickstart.py b/tools/pelican_quickstart.py index 04fc20be..f2ec9e88 100755 --- a/tools/pelican_quickstart.py +++ b/tools/pelican_quickstart.py @@ -1,10 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -import os, sys, argparse, string +import os +import string +import argparse + from pelican import __version__ -TEMPLATES={ +TEMPLATES = { 'Makefile' : ''' PELICAN=$pelican PELICANOPTS=$pelicanopts @@ -60,7 +63,7 @@ github: $$(OUTPUTDIR)/index.html \tgit push origin gh-pages .PHONY: html help clean ftp_upload ssh_upload dropbox_upload github - ''', +''', 'pelican.conf.py': '''#!/usr/bin/env python # -*- coding: utf-8 -*- # @@ -87,9 +90,7 @@ SOCIAL = ( ) DEFAULT_PAGINATION = $default_pagination - - - ''' +''' } CONF = { From d01606e86d126e46d63a16a72b5f10bbe8162d01 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Wed, 14 Mar 2012 20:06:13 +0000 Subject: [PATCH 16/33] remove unused class _dict --- tools/pelican_quickstart.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tools/pelican_quickstart.py b/tools/pelican_quickstart.py index f2ec9e88..2358161e 100755 --- a/tools/pelican_quickstart.py +++ b/tools/pelican_quickstart.py @@ -109,17 +109,6 @@ CONF = { } -class _dict(dict): - def __init__(self, *args, **kwargs): - dict.__init__(self, *args, **kwargs) - - def __getitem__(self, i): - return dict.get(self,i,None) - - def has_key(k): - return True - - def ask(question, answer=str, default=None, l=None): if answer == str: r = '' From 10fc8a733d7e8f8c99f31101067c77a8ae7c7c6c Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Thu, 15 Mar 2012 00:17:01 +0000 Subject: [PATCH 17/33] fix warnings and errors from settings.rst --- docs/settings.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 9eb46439..c9b58d04 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -160,6 +160,8 @@ maintain multiple languages with different date formats, you can set this dict using language name (``lang`` in your posts) as key. Regarding available format codes, see `strftime document of python`_ : +.. parsed-literal:: + DATE_FORMAT = { 'en': '%a, %d %b %Y', 'jp': '%Y-%m-%d(%a)', @@ -167,6 +169,8 @@ codes, see `strftime document of python`_ : You can set locale to further control date format: +.. parsed-literal:: + LOCALE = ('usa', 'jpn', # On Windows 'en_US', 'ja_JP' # On Unix/Linux ) @@ -175,6 +179,7 @@ Also, it is possible to set different locale settings for each language. If you put (locale, format) tuples in the dict, this will override the LOCALE setting above: +.. parsed-literal:: # On Unix/Linux DATE_FORMAT = { 'en': ('en_US','%a, %d %b %Y'), From 7f8f6e8a7e0a4d9b8c313f22e65eb1b4ea055513 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Thu, 15 Mar 2012 00:17:50 +0000 Subject: [PATCH 18/33] the sys.path should not contain the _themes directory, which is not a python package --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 4c4530e2..b4a58992 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,6 @@ release = version # -- Options for HTML output --------------------------------------------------- -sys.path.append(os.path.abspath('_themes')) html_theme_path = ['_themes'] html_theme = 'pelican' From 020c1400e22ec1b3f45e7bf5c4ec404223b83a6a Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Thu, 15 Mar 2012 00:23:07 +0000 Subject: [PATCH 19/33] add the pelican path to the sys.path, to be able to use autodoc --- docs/conf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index b4a58992..6c4e1ce5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import sys, os +sys.path.append(os.path.abspath('..')) + # -- General configuration ----------------------------------------------------- templates_path = ['_templates'] extensions = ['sphinx.ext.autodoc',] From 99852ebda8e581a9ecf2710761bb35dbcef89734 Mon Sep 17 00:00:00 2001 From: Dana Woodman Date: Thu, 15 Mar 2012 11:59:58 -0700 Subject: [PATCH 20/33] `MD_EXTENSIONS` should be a list not a tuple. --- docs/settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/settings.rst b/docs/settings.rst index c9b58d04..b98b649e 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -46,7 +46,7 @@ Setting name (default value) What does it do? `MARKUP` (``('rst', 'md')``) A list of available markup languages you want to use. For the moment, the only available values are `rst` and `md`. -`MD_EXTENSIONS` (``('codehilite','extra')``) A list of the extensions that the Markdown processor +`MD_EXTENSIONS` (``['codehilite','extra']``) A list of the extensions that the Markdown processor will use. Refer to the extensions chapter in the Python-Markdown documentation for a complete list of supported extensions. From 2ff3db8f517772c6b9c57fb35a8572827551694b Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Thu, 15 Mar 2012 19:37:49 +0000 Subject: [PATCH 21/33] fix the reset term code to make it work also on OSX --- pelican/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/log.py b/pelican/log.py index 1cb76e16..027743d0 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -5,7 +5,7 @@ from logging import critical, error, info, warning, warn, debug from logging import Formatter, getLogger, StreamHandler -RESET_TERM = u'\033[1;m' +RESET_TERM = u'\033[0;m' def term_color(code): From 74c2449d8f0fe4e6ae8c237835b438f87dfc9aad Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Fri, 16 Mar 2012 14:27:26 +0000 Subject: [PATCH 22/33] add version information in __init__.py and import them from setup.py and conf.py --- docs/conf.py | 6 ++++-- pelican/__init__.py | 4 +++- setup.py | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 6c4e1ce5..ac2d67ee 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,6 +3,8 @@ import sys, os sys.path.append(os.path.abspath('..')) +from pelican import __version__, __major__ + # -- General configuration ----------------------------------------------------- templates_path = ['_templates'] extensions = ['sphinx.ext.autodoc',] @@ -11,8 +13,8 @@ master_doc = 'index' project = u'Pelican' copyright = u'2010, Alexis Metaireau and contributors' exclude_patterns = ['_build'] -version = "2" -release = version +version = __version__ +release = __major__ # -- Options for HTML output --------------------------------------------------- diff --git a/pelican/__init__.py b/pelican/__init__.py index 5ffcc3b5..780938a7 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -11,7 +11,9 @@ from pelican.utils import clean_output_dir, files_changed from pelican.writers import Writer from pelican import log -__version__ = "3.0" +__major__ = 3 +__minor__ = 0 +__version__ = "{0}.{1}".format(__major__, __minor__) class Pelican(object): diff --git a/setup.py b/setup.py index 910499de..d26ad5f4 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from setuptools import setup -VERSION = "3.0" # find a better way to do so. +from pelican import __version__ requires = ['feedgenerator', 'jinja2', 'pygments', 'docutils', 'pytz'] @@ -21,7 +21,7 @@ entry_points = { setup( name = "pelican", - version = VERSION, + version = __version__, url = 'http://pelican.notmyidea.org/', author = 'Alexis Metaireau', author_email = 'alexis@notmyidea.org', From df8b71f8110566351db3fdc358fcf8ff65d6bdcf Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Fri, 16 Mar 2012 14:27:51 +0000 Subject: [PATCH 23/33] remove unused *bat include --- MANIFEST.in | 1 - 1 file changed, 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index fc46d905..a092ecd0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,3 @@ include *.rst global-include *.py recursive-include pelican *.html *.css *png include LICENSE -global-include *.bat From 26078ecc175764c138b8415c70ba85aecbb81565 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Fri, 16 Mar 2012 14:50:26 +0000 Subject: [PATCH 24/33] remove unused colors and refactor more how the escaping is done --- pelican/log.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/pelican/log.py b/pelican/log.py index 027743d0..c5e9b688 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -8,31 +8,25 @@ from logging import Formatter, getLogger, StreamHandler RESET_TERM = u'\033[0;m' -def term_color(code): - return lambda text: code + unicode(text) + RESET_TERM +def start_color(index): + return u'\033[1;{0}m'.format(index) + + +def term_color(color): + code = COLOR_CODES[color] + return lambda text: start_color(code) + unicode(text) + RESET_TERM COLOR_CODES = { - 'gray': u'\033[1;30m', - 'red': u'\033[1;31m', - 'green': u'\033[1;32m', - 'yellow': u'\033[1;33m', - 'blue': u'\033[1;34m', - 'magenta': u'\033[1;35m', - 'cyan': u'\033[1;36m', - 'white': u'\033[1;37m', - 'bgred': u'\033[1;41m', - 'bggreen': u'\033[1;42m', - 'bgbrown': u'\033[1;43m', - 'bgblue': u'\033[1;44m', - 'bgmagenta': u'\033[1;45m', - 'bgcyan': u'\033[1;46m', - 'bggray': u'\033[1;47m', - 'bgyellow': u'\033[1;43m', - 'bggrey': u'\033[1;100m', + 'red': 31, + 'yellow': 33, + 'cyan': 36, + 'white': 37, + 'bgred': 41, + 'bggrey': 100, } -ANSI = dict((col, term_color(code)) for col, code in COLOR_CODES.items()) +ANSI = dict((col, term_color(col)) for col in COLOR_CODES) class ANSIFormatter(Formatter): From 173133dbf34b322511feb36663e189709e505949 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Fri, 16 Mar 2012 14:53:28 +0000 Subject: [PATCH 25/33] remove couple of extra spaces --- pelican/log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelican/log.py b/pelican/log.py index c5e9b688..8811b372 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -1,6 +1,6 @@ import os import sys -from logging import CRITICAL, ERROR, WARN, INFO, DEBUG +from logging import CRITICAL, ERROR, WARN, INFO, DEBUG from logging import critical, error, info, warning, warn, debug from logging import Formatter, getLogger, StreamHandler @@ -74,7 +74,7 @@ class DummyFormatter(object): and not sys.platform.startswith('win'): return ANSIFormatter(*args, **kwargs) else: - return TextFormatter( *args, **kwargs) + return TextFormatter(*args, **kwargs) def init(level=None, logger=getLogger(), handler=StreamHandler()): From 4e4af9d011625f79c04a6ab1d55de892dbaf5149 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Fri, 16 Mar 2012 18:53:08 +0000 Subject: [PATCH 26/33] move tools in pelican.tools and add the pelican.tools package to setup.py --- {tools => pelican/tools}/__init__.py | 0 {tools => pelican/tools}/pelican_import.py | 0 {tools => pelican/tools}/pelican_quickstart.py | 0 {tools => pelican/tools}/pelican_themes.py | 0 setup.py | 8 ++++---- 5 files changed, 4 insertions(+), 4 deletions(-) rename {tools => pelican/tools}/__init__.py (100%) rename {tools => pelican/tools}/pelican_import.py (100%) rename {tools => pelican/tools}/pelican_quickstart.py (100%) rename {tools => pelican/tools}/pelican_themes.py (100%) diff --git a/tools/__init__.py b/pelican/tools/__init__.py similarity index 100% rename from tools/__init__.py rename to pelican/tools/__init__.py diff --git a/tools/pelican_import.py b/pelican/tools/pelican_import.py similarity index 100% rename from tools/pelican_import.py rename to pelican/tools/pelican_import.py diff --git a/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py similarity index 100% rename from tools/pelican_quickstart.py rename to pelican/tools/pelican_quickstart.py diff --git a/tools/pelican_themes.py b/pelican/tools/pelican_themes.py similarity index 100% rename from tools/pelican_themes.py rename to pelican/tools/pelican_themes.py diff --git a/setup.py b/setup.py index 910499de..a8e0f57d 100755 --- a/setup.py +++ b/setup.py @@ -13,9 +13,9 @@ except ImportError: entry_points = { 'console_scripts': [ 'pelican = pelican:main', - 'pelican-import = tools.pelican_import:main', - 'pelican-quickstart = tools.pelican_quickstart:main', - 'pelican-themes = tools.pelican_themes:main' + 'pelican-import = pelican.tools.pelican_import:main', + 'pelican-quickstart = pelican.tools.pelican_quickstart:main', + 'pelican-themes = pelican.tools.pelican_themes:main' ] } @@ -27,7 +27,7 @@ setup( author_email = 'alexis@notmyidea.org', description = "A tool to generate a static blog from reStructuredText or Markdown input files.", long_description=open('README.rst').read(), - packages = ['pelican'], + packages = ['pelican', 'pelican.tools'], include_package_data = True, install_requires = requires, entry_points = entry_points, From c75ab513daa0c4b78d2f0ebfd23077fcc6b158e2 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Fri, 16 Mar 2012 19:59:03 +0100 Subject: [PATCH 27/33] use 'summary' rather than ':summary:' in comments --- pelican/contents.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index d8ccf9f3..2a7dc22a 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -89,7 +89,7 @@ class Page(object): if hasattr(self, 'date') and self.date > datetime.now(): self.status = 'draft' - # store the :summary: metadata if it is set + # store the summary metadata if it is set if 'summary' in metadata: self._summary = metadata['summary'] @@ -126,7 +126,7 @@ class Page(object): return content def _get_summary(self): - """Returns the summary of an article, based on the :summary: metadata + """Returns the summary of an article, based on the summary metadata if it is set, else troncate the content.""" if hasattr(self, '_summary'): return self._summary From 3dcedb60d83e80ecfd16d6440f21f7cfe110bcef Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Fri, 16 Mar 2012 20:56:00 +0100 Subject: [PATCH 28/33] add irc support to travis-ci --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8f5dc3a3..89a2ebde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,5 @@ install: - pip install nose unittest2 mock --use-mirrors - pip install . --use-mirrors script: nosetests -s tests +notifications: + irc: "irc.freenode.org#pelican" From 8b846b9fe2eaff627b411ef6af1f9ba1bae2a5b8 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Fri, 16 Mar 2012 21:12:48 +0100 Subject: [PATCH 29/33] restore back to hardcoded version in setup.py due to import hell --- setup.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 1f75131b..67bbae80 100755 --- a/setup.py +++ b/setup.py @@ -1,8 +1,6 @@ #!/usr/bin/env python from setuptools import setup -from pelican import __version__ - requires = ['feedgenerator', 'jinja2', 'pygments', 'docutils', 'pytz'] try: @@ -16,12 +14,12 @@ entry_points = { 'pelican-import = pelican.tools.pelican_import:main', 'pelican-quickstart = pelican.tools.pelican_quickstart:main', 'pelican-themes = pelican.tools.pelican_themes:main' - ] + ] } setup( name = "pelican", - version = __version__, + version = "3.0", url = 'http://pelican.notmyidea.org/', author = 'Alexis Metaireau', author_email = 'alexis@notmyidea.org', From 4819a830037ec56466a4d0fb35f6441db663774e Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Fri, 16 Mar 2012 21:13:24 +0100 Subject: [PATCH 30/33] Fix #171. Handle unicode filenames --- pelican/contents.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pelican/contents.py b/pelican/contents.py index 2a7dc22a..3386dba9 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -42,9 +42,10 @@ class Page(object): if 'AUTHOR' in settings: self.author = Author(settings['AUTHOR'], settings) else: + title = filename.decode('utf-8') if filename else self.title self.author = Author(getenv('USER', 'John Doe'), settings) warning(u"Author of `{0}' unknown, assuming that his name is " - "`{1}'".format(filename or self.title, self.author)) + "`{1}'".format(title, self.author)) # manage languages self.in_default_lang = True From cbc609c8f00277efbbb2e17becbc36054526d48f Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Fri, 16 Mar 2012 21:23:34 +0100 Subject: [PATCH 31/33] only notify build is okay if it was failing previously --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 89a2ebde..823c1172 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,7 @@ install: - pip install . --use-mirrors script: nosetests -s tests notifications: - irc: "irc.freenode.org#pelican" + irc: + channels: + - "irc.freenode.org#pelican" + on_success: change From a9f5fdc47b5c42dee41e8ffebd773bcc9c2276ab Mon Sep 17 00:00:00 2001 From: Martin Brochhaus Date: Sun, 18 Mar 2012 14:57:53 +0800 Subject: [PATCH 32/33] Always using normal capitalization in headlines. --- docs/settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/settings.rst b/docs/settings.rst index b98b649e..b1c35122 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -83,7 +83,7 @@ Setting name (default value) What does it do? .. [#] Default is the system locale. -URL Settings +URL settings ------------ You can customize the URL's and locations where files will be saved. The URL's and From 9c4b40fd35833a6f68b04316ca5ce8f77f19c325 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sun, 18 Mar 2012 15:12:06 +0100 Subject: [PATCH 33/33] Keep raw metadata text (but for summary) --- pelican/readers.py | 5 ++++- tests/content/article_with_metadata.rst | 1 + tests/test_readers.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pelican/readers.py b/pelican/readers.py index d4e13b4d..2e269647 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -71,7 +71,10 @@ class RstReader(Reader): if element.tagname == 'field': # custom fields (e.g. summary) name_elem, body_elem = element.children name = name_elem.astext() - value = render_node_to_html(document, body_elem) + if name == 'summary': + value = render_node_to_html(document, body_elem) + else: + value = body_elem.astext() else: # standard fields (e.g. address) name = element.tagname value = element.astext() diff --git a/tests/content/article_with_metadata.rst b/tests/content/article_with_metadata.rst index 3410885e..d4bac1c0 100644 --- a/tests/content/article_with_metadata.rst +++ b/tests/content/article_with_metadata.rst @@ -9,3 +9,4 @@ This is a super article ! :summary: Multi-line metadata should be supported as well as **inline markup**. +:custom_field: http://notmyidea.org diff --git a/tests/test_readers.py b/tests/test_readers.py index 058469d4..4c04a212 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -30,6 +30,7 @@ class RstReaderTest(unittest.TestCase): ' inline markup.', 'date': datetime.datetime(2010, 12, 2, 10, 14), 'tags': ['foo', 'bar', 'foobar'], + 'custom_field': 'http://notmyidea.org', } for key, value in expected.items():