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".
This commit is contained in:
Alexis Metaireau 2011-01-12 23:45:06 +01:00
commit b8fb45de9e
3 changed files with 49 additions and 5 deletions

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