mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #476 from tbunnyman/fixAutorunInfLoop
Fix autorun inf loop
This commit is contained in:
commit
fb8a069d4a
3 changed files with 33 additions and 6 deletions
|
|
@ -11,7 +11,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, file_changed
|
from pelican.utils import clean_output_dir, files_changed, file_changed, NoFilesError
|
||||||
from pelican.writers import Writer
|
from pelican.writers import Writer
|
||||||
|
|
||||||
__major__ = 3
|
__major__ = 3
|
||||||
|
|
@ -265,6 +265,7 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.autoreload:
|
if args.autoreload:
|
||||||
|
files_found_error = True
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# Check source dir for changed files ending with the given
|
# Check source dir for changed files ending with the given
|
||||||
|
|
@ -274,6 +275,8 @@ def main():
|
||||||
# have.
|
# have.
|
||||||
if files_changed(pelican.path, pelican.markup) or \
|
if files_changed(pelican.path, pelican.markup) or \
|
||||||
files_changed(pelican.theme, ['']):
|
files_changed(pelican.theme, ['']):
|
||||||
|
if files_found_error == False:
|
||||||
|
files_found_error = True
|
||||||
pelican.run()
|
pelican.run()
|
||||||
|
|
||||||
# reload also if settings.py changed
|
# reload also if settings.py changed
|
||||||
|
|
@ -287,6 +290,10 @@ def main():
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.warning("Keyboard interrupt, quitting.")
|
logger.warning("Keyboard interrupt, quitting.")
|
||||||
break
|
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:
|
except Exception, e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Caught exception \"{}\". Reloading.".format(e)
|
"Caught exception \"{}\". Reloading.".format(e)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ from operator import attrgetter
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class NoFilesError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_date(string):
|
def get_date(string):
|
||||||
"""Return a datetime object from a 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
|
yield os.stat(os.path.join(root, f)).st_mtime
|
||||||
|
|
||||||
global LAST_MTIME
|
global LAST_MTIME
|
||||||
mtime = max(file_times(path))
|
try:
|
||||||
if mtime > LAST_MTIME:
|
mtime = max(file_times(path))
|
||||||
LAST_MTIME = mtime
|
if mtime > LAST_MTIME:
|
||||||
return True
|
LAST_MTIME = mtime
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
raise NoFilesError("No files with the given extension(s) found.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import time
|
||||||
|
|
||||||
from pelican import utils
|
from pelican import utils
|
||||||
from .support import get_article, unittest
|
from .support import get_article, unittest
|
||||||
|
from pelican.utils import NoFilesError
|
||||||
|
|
||||||
|
|
||||||
class TestUtils(unittest.TestCase):
|
class TestUtils(unittest.TestCase):
|
||||||
|
|
@ -74,7 +75,8 @@ class TestUtils(unittest.TestCase):
|
||||||
self.assertNotIn(fr_article1, index)
|
self.assertNotIn(fr_article1, index)
|
||||||
|
|
||||||
def test_files_changed(self):
|
def test_files_changed(self):
|
||||||
"Test if file changes are correctly detected"
|
"""Test if file changes are correctly detected
|
||||||
|
Make sure to handle not getting any files correctly"""
|
||||||
|
|
||||||
path = os.path.join(os.path.dirname(__file__), 'content')
|
path = os.path.join(os.path.dirname(__file__), 'content')
|
||||||
filename = os.path.join(path, 'article_with_metadata.rst')
|
filename = os.path.join(path, 'article_with_metadata.rst')
|
||||||
|
|
@ -90,6 +92,18 @@ class TestUtils(unittest.TestCase):
|
||||||
self.assertEquals(changed, True)
|
self.assertEquals(changed, True)
|
||||||
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
||||||
|
|
||||||
|
empty_path = os.path.join(os.path.dirname(__file__), 'empty')
|
||||||
|
try:
|
||||||
|
os.mkdir(empty_path)
|
||||||
|
os.mkdir(os.path.join(empty_path, "empty_folder"))
|
||||||
|
shutil.copy(__file__, empty_path)
|
||||||
|
with self.assertRaises(NoFilesError):
|
||||||
|
utils.files_changed(empty_path, 'rst')
|
||||||
|
except OSError:
|
||||||
|
self.fail("OSError Exception in test_files_changed test")
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(empty_path, True)
|
||||||
|
|
||||||
def test_clean_output_dir(self):
|
def test_clean_output_dir(self):
|
||||||
test_directory = os.path.join(os.path.dirname(__file__), 'clean_output')
|
test_directory = os.path.join(os.path.dirname(__file__), 'clean_output')
|
||||||
content = os.path.join(os.path.dirname(__file__), 'content')
|
content = os.path.join(os.path.dirname(__file__), 'content')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue