mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
parent
3dd63a012e
commit
ed8b8bc27e
2 changed files with 41 additions and 12 deletions
|
|
@ -9,7 +9,7 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||||
StaticGenerator, PdfGenerator, LessCSSGenerator)
|
StaticGenerator, PdfGenerator, LessCSSGenerator)
|
||||||
from pelican.log import init
|
from pelican.log import init
|
||||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||||
from pelican.utils import clean_output_dir, files_changed
|
from pelican.utils import clean_output_dir, files_changed, file_changed
|
||||||
from pelican.writers import Writer
|
from pelican.writers import Writer
|
||||||
|
|
||||||
__major__ = 3
|
__major__ = 3
|
||||||
|
|
@ -134,7 +134,7 @@ class Pelican(object):
|
||||||
generators = [ArticlesGenerator, PagesGenerator, StaticGenerator]
|
generators = [ArticlesGenerator, PagesGenerator, StaticGenerator]
|
||||||
if self.settings['PDF_GENERATOR']:
|
if self.settings['PDF_GENERATOR']:
|
||||||
generators.append(PdfGenerator)
|
generators.append(PdfGenerator)
|
||||||
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
||||||
generators.append(LessCSSGenerator)
|
generators.append(LessCSSGenerator)
|
||||||
return generators
|
return generators
|
||||||
|
|
||||||
|
|
@ -192,11 +192,7 @@ def parse_arguments():
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def get_instance(args):
|
||||||
args = parse_arguments()
|
|
||||||
init(args.verbosity)
|
|
||||||
# Split the markup languages only if some have been given. Otherwise,
|
|
||||||
# populate the variable with None.
|
|
||||||
markup = [a.strip().lower() for a in args.markup.split(',')]\
|
markup = [a.strip().lower() for a in args.markup.split(',')]\
|
||||||
if args.markup else None
|
if args.markup else None
|
||||||
|
|
||||||
|
|
@ -208,9 +204,18 @@ def main():
|
||||||
module = __import__(module)
|
module = __import__(module)
|
||||||
cls = getattr(module, cls_name)
|
cls = getattr(module, cls_name)
|
||||||
|
|
||||||
|
return cls(settings, args.path, args.theme, args.output, markup,
|
||||||
|
args.delete_outputdir)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parse_arguments()
|
||||||
|
init(args.verbosity)
|
||||||
|
# Split the markup languages only if some have been given. Otherwise,
|
||||||
|
# populate the variable with None.
|
||||||
|
pelican = get_instance(args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pelican = cls(settings, args.path, args.theme, args.output, markup,
|
|
||||||
args.delete_outputdir)
|
|
||||||
if args.autoreload:
|
if args.autoreload:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
@ -222,6 +227,14 @@ def main():
|
||||||
if files_changed(pelican.path, pelican.markup) or \
|
if files_changed(pelican.path, pelican.markup) or \
|
||||||
files_changed(pelican.theme, ['']):
|
files_changed(pelican.theme, ['']):
|
||||||
pelican.run()
|
pelican.run()
|
||||||
|
|
||||||
|
# reload also if settings.py changed
|
||||||
|
if file_changed(args.settings):
|
||||||
|
logger.info('%s changed, re-generating' %
|
||||||
|
args.settings)
|
||||||
|
pelican = get_instance(args)
|
||||||
|
pelican.run()
|
||||||
|
|
||||||
time.sleep(.5) # sleep to avoid cpu load
|
time.sleep(.5) # sleep to avoid cpu load
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import re
|
||||||
import pytz
|
import pytz
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from codecs import open as _open
|
from codecs import open as _open
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
@ -221,9 +222,9 @@ def files_changed(path, extensions):
|
||||||
"""Return the last time files have been modified"""
|
"""Return the last time files have been modified"""
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
dirs[:] = [x for x in dirs if x[0] != '.']
|
dirs[:] = [x for x in dirs if x[0] != '.']
|
||||||
for file in files:
|
for f in files:
|
||||||
if any(file.endswith(ext) for ext in extensions):
|
if any(f.endswith(ext) for ext in extensions):
|
||||||
yield os.stat(os.path.join(root, file)).st_mtime
|
yield os.stat(os.path.join(root, f)).st_mtime
|
||||||
|
|
||||||
global LAST_MTIME
|
global LAST_MTIME
|
||||||
mtime = max(file_times(path))
|
mtime = max(file_times(path))
|
||||||
|
|
@ -233,6 +234,21 @@ def files_changed(path, extensions):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
FILENAMES_MTIMES = defaultdict(int)
|
||||||
|
|
||||||
|
|
||||||
|
def file_changed(filename):
|
||||||
|
mtime = os.stat(filename).st_mtime
|
||||||
|
if FILENAMES_MTIMES[filename] == 0:
|
||||||
|
FILENAMES_MTIMES[filename] = mtime
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if mtime > FILENAMES_MTIMES[filename]:
|
||||||
|
FILENAMES_MTIMES[filename] = mtime
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def set_date_tzinfo(d, tz_name=None):
|
def set_date_tzinfo(d, tz_name=None):
|
||||||
""" Date without tzinfo shoudbe utc.
|
""" Date without tzinfo shoudbe utc.
|
||||||
This function set the right tz to date that aren't utc and don't have
|
This function set the right tz to date that aren't utc and don't have
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue