1
0
Fork 0
forked from github/pelican

Implemented better "valid files not found" behavior.

Used an exception so show error state.
Used a bool flag to make sure the error is only shown once PER error.
Updated tests to check for the correct Exception raised
This commit is contained in:
tBunnyMan 2012-08-23 12:44:22 -07:00
commit a37ba369ef
3 changed files with 14 additions and 5 deletions

View file

@ -11,7 +11,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
@ -265,6 +265,7 @@ def main():
try:
if args.autoreload:
files_found_error = True
while True:
try:
# Check source dir for changed files ending with the given
@ -274,6 +275,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
@ -287,6 +290,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

@ -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.
@ -247,8 +250,7 @@ def files_changed(path, extensions):
LAST_MTIME = mtime
return True
except ValueError:
logger.info("No files found in path")
return False
raise NoFilesError("No files with the given extension(s) found.")
return False

View file

@ -96,8 +96,8 @@ class TestUtils(unittest.TestCase):
os.mkdir(empty_path)
os.mkdir(os.path.join(empty_path, "empty_folder"))
shutil.copy(__file__, empty_path)
changed = utils.files_changed(empty_path, 'rst')
self.assertFalse(changed)
with self.assertRaises(NoFilesError):
utils.files_changed(empty_path, 'rst')
except OSError:
self.fail("OSError Exception in test_files_changed test")
finally: