From 0441127c41c5f7caa194d585ca838121da6e9ac7 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 19:23:37 +0200 Subject: [PATCH 1/9] logging star import cleanups --- pelican/log.py | 4 +++- pelican/utils.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pelican/log.py b/pelican/log.py index 72b7a017..4b3dee71 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -1,4 +1,6 @@ -from logging import * +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 diff --git a/pelican/utils.py b/pelican/utils.py index 732b1830..864717ae 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -6,7 +6,7 @@ from datetime import datetime from codecs import open as _open from itertools import groupby from operator import attrgetter -from pelican.log import * +from pelican.log import warning, info def get_date(string): From 9c99db7119f853264f980e231ca6ea3ac8066a6f Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 19:24:25 +0200 Subject: [PATCH 2/9] better log info for doubls slug/empty slug --- pelican/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pelican/utils.py b/pelican/utils.py index 864717ae..c113efdd 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -164,9 +164,13 @@ def process_translations(content_list): len_ = len(default_lang_items) if len_ > 1: warning(u'there are %s variants of "%s"' % (len_, slug)) + for x in default_lang_items: + warning(' %s' % x.filename) elif len_ == 0: default_lang_items = items[:1] + if not slug: + warning('empty slug for %r' %( default_lang_items[0].filename,)) index.extend(default_lang_items) translations.extend(filter( lambda x: x not in default_lang_items, From e69b55dbcdc110b588dd4c25e5bde133f3371853 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 19:25:11 +0200 Subject: [PATCH 3/9] use absolute import for the rstdirectives --- pelican/readers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/readers.py b/pelican/readers.py index 4e1d7b2e..6cadcd4d 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -3,7 +3,7 @@ try: from docutils import core # import the directives to have pygments support - import rstdirectives + from pelican import rstdirectives except ImportError: core = False try: From 3c37704b3b819bee5d441c75a6fd59a64279a0e8 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 19:26:25 +0200 Subject: [PATCH 4/9] use unicode.strip instead of string.strip of the string module for metadata processors --- pelican/readers.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 6cadcd4d..c69e156e 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -11,15 +11,14 @@ try: except ImportError: Markdown = False import re -import string from pelican.utils import get_date, open _METADATAS_PROCESSORS = { - 'tags': lambda x: map(string.strip, x.split(',')), + 'tags': lambda x: map(unicode.strip, x.split(',')), 'date': lambda x: get_date(x), - 'status': string.strip, + 'status': unicode.strip, } From e7c75147d25e09f6a92fb2da9af64ee36d42ebfa Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 19:28:14 +0200 Subject: [PATCH 5/9] pass along the source filename of the rst files for better errors --- pelican/readers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pelican/readers.py b/pelican/readers.py index c69e156e..92bb7bce 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -45,7 +45,9 @@ class RstReader(Reader): metadatas = self._parse_metadata(text) extra_params = {'input_encoding': 'unicode', 'initial_header_level': '2'} - rendered_content = core.publish_parts(text, writer_name='html', + rendered_content = core.publish_parts(text, + source_path=filename, + writer_name='html', settings_overrides=extra_params) title = rendered_content.get('title') content = rendered_content.get('body') From b270c1bac4b6ef5cf30f4f0289cc290eb69520d4 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 19:29:01 +0200 Subject: [PATCH 6/9] stupidly replace rmtree by a pass, since we dont want to rmtree the output dir --- pelican/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/utils.py b/pelican/utils.py index c113efdd..f9f17489 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -62,7 +62,7 @@ def clean_output_dir(path): # remove all the existing content from the output folder try: - shutil.rmtree(path) + pass # WEEEEE dont kill except Exception: pass From 24c3447d6c3cdff80a35e159935c059d4db1714a Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 21:04:29 +0200 Subject: [PATCH 7/9] make file-times directly use walk, also skip dot-dirs --- pelican/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index f9f17489..42a4fc0c 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -192,9 +192,10 @@ def files_changed(path, extensions): def file_times(path): """Return the last time files have been modified""" - for top_level in os.listdir(path): - for root, dirs, files in os.walk(top_level): - for file in filter(with_extension, files): + for root, dirs, files in os.walk(path): + dirs[:] = [x for x in dirs if x[0] != '.'] + for file in files: + if any(file.endswith(ext) for ext in extensions): yield os.stat(os.path.join(root, file)).st_mtime global LAST_MTIME From d03a412e5be455a85ad0a4b624c71bbc30fb1ffb Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 22:05:13 +0200 Subject: [PATCH 8/9] add a sleep to the autoreload loop since we dont need too high cpu load --- pelican/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pelican/__init__.py b/pelican/__init__.py index 12d12210..c525c66a 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -1,5 +1,6 @@ import argparse import os +import time from pelican.generators import (ArticlesGenerator, PagesGenerator, StaticGenerator, PdfGenerator) @@ -142,6 +143,7 @@ def main(): pelican.run() except KeyboardInterrupt: break + time.sleep(.5) # sleep to avoid cpu load else: pelican.run() except Exception, e: From ffe8e00046bbd085e6732856a9e558cfe27d2ccf Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 6 May 2011 22:09:49 +0200 Subject: [PATCH 9/9] move the sleep so we correctly handle keyboard interupts --- pelican/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index c525c66a..52775f94 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -141,9 +141,9 @@ def main(): try: if files_changed(pelican.path, pelican.markup): pelican.run() + time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: break - time.sleep(.5) # sleep to avoid cpu load else: pelican.run() except Exception, e: