1
0
Fork 0
forked from github/pelican

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Nico Di Rocco 2012-08-31 22:04:05 +02:00
commit 680e04b4a1
12 changed files with 132 additions and 96 deletions

View file

@ -1,3 +1,4 @@
import copy
import os
import re
import sys
@ -11,7 +12,7 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator,
StaticGenerator, PdfGenerator, LessCSSGenerator)
from pelican.log import init
from pelican.settings import read_settings, _DEFAULT_CONFIG
from pelican.utils import clean_output_dir, files_changed, file_changed
from pelican.utils import clean_output_dir, files_changed, file_changed, NoFilesError
from pelican.writers import Writer
__major__ = 3
@ -29,7 +30,7 @@ class Pelican(object):
before doing anything else.
"""
if settings is None:
settings = _DEFAULT_CONFIG
settings = copy.deepcopy(_DEFAULT_CONFIG)
self.path = path or settings['PATH']
if not self.path:
@ -267,6 +268,7 @@ def main():
try:
if args.autoreload:
files_found_error = True
while True:
try:
# Check source dir for changed files ending with the given
@ -276,6 +278,8 @@ def main():
# have.
if files_changed(pelican.path, pelican.markup) or \
files_changed(pelican.theme, ['']):
if files_found_error == False:
files_found_error = True
pelican.run()
# reload also if settings.py changed
@ -289,6 +293,10 @@ def main():
except KeyboardInterrupt:
logger.warning("Keyboard interrupt, quitting.")
break
except NoFilesError:
if files_found_error == True:
logger.warning("No valid files found in content. Nothing to generate.")
files_found_error = False
except Exception, e:
logger.warning(
"Caught exception \"{}\". Reloading.".format(e)

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import copy
import locale
import logging
import functools
@ -29,7 +30,7 @@ class Page(object):
if not metadata:
metadata = {}
if not settings:
settings = _DEFAULT_CONFIG
settings = copy.deepcopy(_DEFAULT_CONFIG)
self.settings = settings
self._content = content

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import copy
import imp
import inspect
import os
@ -81,7 +82,7 @@ def read_settings(filename=None):
if filename:
local_settings = get_settings_from_file(filename)
else:
local_settings = _DEFAULT_CONFIG
local_settings = copy.deepcopy(_DEFAULT_CONFIG)
configured_settings = configure_settings(local_settings, None, filename)
return configured_settings
@ -89,10 +90,9 @@ def read_settings(filename=None):
def get_settings_from_module(module=None, default_settings=_DEFAULT_CONFIG):
"""
Load settings from a module, returning a dict.
"""
context = default_settings.copy()
context = copy.deepcopy(default_settings)
if module is not None:
context.update(
(k, v) for k, v in inspect.getmembers(module) if k.isupper()
@ -114,7 +114,7 @@ def get_settings_from_file(filename, default_settings=_DEFAULT_CONFIG):
def configure_settings(settings, default_settings=None, filename=None):
"""Provide optimizations, error checking, and warnings for loaded settings"""
if default_settings is None:
default_settings = _DEFAULT_CONFIG
default_settings = copy.deepcopy(_DEFAULT_CONFIG)
# Make the paths relative to the settings file
if filename:
@ -138,7 +138,7 @@ def configure_settings(settings, default_settings=None, filename=None):
for locale_ in locales:
try:
locale.setlocale(locale.LC_ALL, locale_)
break # break if it is successfull
break # break if it is successful
except locale.Error:
pass
else:

View file

@ -1,7 +1,7 @@
PELICAN=$pelican
PELICANOPTS=$pelicanopts
BASEDIR=$$(PWD)
BASEDIR=$$(CURDIR)
INPUTDIR=$$(BASEDIR)/content
OUTPUTDIR=$$(BASEDIR)/output
CONFFILE=$$(BASEDIR)/pelicanconf.py

View file

@ -1,11 +1,11 @@
#!/bin/bash
#!/usr/bin/env bash
##
# This section should match your Makefile
##
PELICAN=$pelican
PELICANOPTS=$pelicanopts
BASEDIR=$$(PWD)
BASEDIR=$$(pwd)
INPUTDIR=$$BASEDIR/content
OUTPUTDIR=$$BASEDIR/output
CONFFILE=$$BASEDIR/pelicanconf.py
@ -65,6 +65,7 @@ function start_up(){
python -m SimpleHTTPServer &
echo $$! > $$SRV_PID
cd $$BASEDIR
sleep 1 && echo 'Pelican and SimpleHTTPServer processes now running in background.'
}
###

View file

@ -14,6 +14,9 @@ from operator import attrgetter
logger = logging.getLogger(__name__)
class NoFilesError(Exception):
pass
def get_date(string):
"""Return a datetime object from a string.
@ -241,10 +244,13 @@ def files_changed(path, extensions):
yield os.stat(os.path.join(root, f)).st_mtime
global LAST_MTIME
mtime = max(file_times(path))
if mtime > LAST_MTIME:
LAST_MTIME = mtime
return True
try:
mtime = max(file_times(path))
if mtime > LAST_MTIME:
LAST_MTIME = mtime
return True
except ValueError:
raise NoFilesError("No files with the given extension(s) found.")
return False