diff --git a/bin/pelican b/bin/pelican index 4f860e40..9e376b89 100755 --- a/bin/pelican +++ b/bin/pelican @@ -1,5 +1,5 @@ #!/usr/bin/python -from pelican.generator import generate_output +from pelican.bloggenerator import generate_blog import argparse parser = argparse.ArgumentParser(description="""A tool to generate a @@ -22,7 +22,7 @@ parser.add_argument('-b', '--debug', dest='debug', action='store_true') def run(args): - generate_output(args.path, args.templates, args.output, args.markup, + generate_blog(args.path, args.templates, args.output, args.markup, args.settings) print 'Done !' diff --git a/pelican/generator.py b/pelican/bloggenerator.py similarity index 92% rename from pelican/generator.py rename to pelican/bloggenerator.py index 017c7bfd..dcccd86c 100644 --- a/pelican/generator.py +++ b/pelican/bloggenerator.py @@ -11,13 +11,18 @@ from operator import attrgetter from jinja2 import Environment, FileSystemLoader from feedgenerator import Atom1Feed -import rstdirectives # import the directives to have pygments support +# import the directives to have pygments support +import rstdirectives + +## Constants ########################################################## _TEMPLATES = ('index', 'tag', 'tags', 'article', 'category', 'categories', 'archives') + _DIRECT_TEMPLATES = ('index', 'tags', 'categories', 'archives') -_DEFAULT_THEME =\ - os.sep.join([os.path.dirname(os.path.abspath(__file__)), "themes"]) + +_DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)), + "themes"]) _DEFAULT_CONFIG = {'PATH': None, 'THEME': _DEFAULT_THEME, 'OUTPUT_PATH': 'output/', @@ -29,10 +34,10 @@ _DEFAULT_CONFIG = {'PATH': None, } -def generate_output(path=None, theme=None, output_path=None, markup=None, - settings=None): - """Given a list of files, a template and a destination, - output the static files. +def generate_blog(path=None, theme=None, output_path=None, markup=None, + settings=None): + """Search the given path for files, and generate a static blog in output, + using the given theme. That's the main logic of pelican. @@ -114,9 +119,14 @@ def generate_output(path=None, theme=None, output_path=None, markup=None, # copy static paths to output for path in context['STATIC_PATHS']: try: - shutil.copytree(os.path.join(theme, path), - os.path.join(output_path, path)) - except OSError: + real_output = os.path.join(output_path, path) + theme_path = os.path.join(theme, path) + + print "updating %s" % real_output + shutil.rmtree(real_output) + shutil.copytree(theme_path, real_output) + + except OSError as e: pass @@ -174,7 +184,7 @@ def generate_file(path, name, template, context, **kwargs): pass with open(filename, 'w', encoding='utf-8') as f: f.write(output) - print filename + print 'writing %s' % filename def get_templates(path=None): diff --git a/samples/themes/notmyidea/templates/index.html b/samples/themes/notmyidea/templates/index.html index ab04853b..7818a1aa 100644 --- a/samples/themes/notmyidea/templates/index.html +++ b/samples/themes/notmyidea/templates/index.html @@ -4,7 +4,7 @@ {% for article in articles %} {% if loop.index == 1 %}
@@ -12,7 +12,7 @@ {% else %}