From 55da03ad2fb1cdcb94c5748204ebee75616fec91 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Wed, 12 Jan 2011 19:08:29 +0100 Subject: [PATCH 1/3] Fix notmyidea layout. This fixes #54 --- pelican/themes/notmyidea/static/css/main.css | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pelican/themes/notmyidea/static/css/main.css b/pelican/themes/notmyidea/static/css/main.css index 0972ca0b..a3fd60f1 100644 --- a/pelican/themes/notmyidea/static/css/main.css +++ b/pelican/themes/notmyidea/static/css/main.css @@ -276,14 +276,6 @@ img.left, figure.left {float: right; margin: 0 0 2em 2em;} padding: .3em .25em; } -#extras li:last-child, -#extras li:last-child a {border: 0} - -#extras .blogroll li:nth-last-child(2), -#extras .blogroll li:nth-last-child(3), -#extras .blogroll li:nth-last-child(2) a, -#extras .blogroll li:nth-last-child(3) a {border: 0;} - #extras a:hover, #extras a:active {color: #fff;} /* Blogroll */ From b8fb45de9e512c8c9fc729647a8a843fda6714fc Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Wed, 12 Jan 2011 23:45:06 +0100 Subject: [PATCH 2/3] Add the autoreload feature. This fixes #45. I've choosen to not serve the content via HTTP, because it's really simple to do "firefox output/index.html". --- docs/getting_started.rst | 7 +++++++ pelican/__init__.py | 25 +++++++++++++++++++------ pelican/utils.py | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 0b928afe..db3c0431 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -127,3 +127,10 @@ And the french one:: Despite the text quality, you can see that only the slug is the same here. You're not forced to define the slug that way, and it's completely possible to have two translations with the same title (which defines the slug) + +Autoreload +========== + +It's possible to tell pelican to watch for your modifications, instead of +manually launching it each time you need. Use the `-r` option, or +`--autoreload`. diff --git a/pelican/__init__.py b/pelican/__init__.py index f0684d65..e9a98375 100755 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -1,11 +1,12 @@ import argparse import os +from functools import partial -from pelican.settings import read_settings -from pelican.utils import clean_output_dir -from pelican.writers import Writer from pelican.generators import (ArticlesGenerator, PagesGenerator, - StaticGenerator, PdfGenerator) + StaticGenerator, PdfGenerator) +from pelican.settings import read_settings +from pelican.utils import clean_output_dir, files_changed +from pelican.writers import Writer VERSION = "2.5.3" @@ -107,7 +108,10 @@ def main(): help='Keep the output directory and just update all the generated files.' 'Default is to delete the output directory.') parser.add_argument('--version', action='version', version=VERSION, - help="Print the pelican version and exit") + help='Print the pelican version and exit') + parser.add_argument('-r', '--autoreload', dest='autoreload', action='store_true', + help="Relaunch pelican each time a modification occurs on the content" + "files") args = parser.parse_args() # Split the markup languages only if some have been given. Otherwise, populate @@ -125,7 +129,16 @@ def main(): cls = getattr(module, cls_name) pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep) - pelican.run() + + if args.autoreload: + while True: + try: + if files_changed(pelican.path, pelican.markup): + pelican.run() + except KeyboardInterrupt: + break + else: + pelican.run() if __name__ == '__main__': diff --git a/pelican/utils.py b/pelican/utils.py index 7def7881..5a7fbaaf 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -174,3 +174,27 @@ def process_translations(content_list): for a in items: a.translations = filter(lambda x: x != a, items) return index, translations + + +LAST_MTIME = 0 + + +def files_changed(path, extensions): + """Return True if the files have changed since the last check""" + + def with_extension(f): + return True if True in [f.endswith(ext) for ext in extensions] else False + + 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): + yield os.stat(os.path.join(root, file)).st_mtime + + global LAST_MTIME + mtime = max(file_times(path)) + if mtime > LAST_MTIME: + LAST_MTIME = mtime + return True + return False From a64ecf24be357348025b1f45b1687e24b6ff2b85 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Wed, 12 Jan 2011 23:47:19 +0100 Subject: [PATCH 3/3] Merge branches 'autoreload' and 'master'