1
0
Fork 0
forked from github/pelican

Merge branch 'master' of github.com:ametaireau/pelican into tests

This commit is contained in:
Alexis Metaireau 2011-01-12 23:50:47 +01:00
commit 39b761c056
4 changed files with 49 additions and 13 deletions

View file

@ -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__':

View file

@ -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 */

View file

@ -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