Merge pull request #248 from saimn/cleanup

Cleanup
This commit is contained in:
Alexis Metaireau 2012-03-15 07:41:10 -07:00
commit 8cd0939bfe
4 changed files with 23 additions and 9 deletions

View file

@ -227,7 +227,7 @@ class ArticlesGenerator(Generator):
continue
# if no category is set, use the name of the path as a category
if 'category' not in metadata.keys():
if 'category' not in metadata:
if os.path.dirname(f) == self.path:
category = self.settings['DEFAULT_CATEGORY']
@ -238,8 +238,7 @@ class ArticlesGenerator(Generator):
if category != '':
metadata['category'] = Category(category, self.settings)
if 'date' not in metadata.keys()\
and self.settings['FALLBACK_ON_FS_DATE']:
if 'date' not in metadata and self.settings['FALLBACK_ON_FS_DATE']:
metadata['date'] = datetime.datetime.fromtimestamp(
os.stat(f).st_ctime)

View file

@ -145,7 +145,7 @@ def read_file(filename, fmt=None, settings=None):
if not fmt:
fmt = filename.split('.')[-1]
if fmt not in _EXTENSIONS.keys():
if fmt not in _EXTENSIONS:
raise TypeError('Pelican does not know how to parse %s' % filename)
reader = _EXTENSIONS[fmt](settings)

View file

@ -210,9 +210,6 @@ LAST_MTIME = 0
def files_changed(path, extensions):
"""Return True if the files have changed since the last check"""
def with_extension(f):
return any(f.endswith(ext) for ext in extensions)
def file_times(path):
"""Return the last time files have been modified"""
for root, dirs, files in os.walk(path):

View file

@ -3,11 +3,12 @@ try:
import unittest2 as unittest
except ImportError:
import unittest # NOQA
import os
import datetime
import time
from pelican import utils
from pelican.contents import Article
from support import get_article
@ -73,3 +74,20 @@ class TestUtils(unittest.TestCase):
self.assertIn(fr_article1, trans)
self.assertNotIn(en_article1, trans)
self.assertNotIn(fr_article1, index)
def test_files_changed(self):
"Test if file changes are correctly detected"
path = os.path.join(os.path.dirname(__file__), 'content')
filename = os.path.join(path, 'article_with_metadata.rst')
changed = utils.files_changed(path, 'rst')
self.assertEquals(changed, True)
changed = utils.files_changed(path, 'rst')
self.assertEquals(changed, False)
t = time.time()
os.utime(filename, (t, t))
changed = utils.files_changed(path, 'rst')
self.assertEquals(changed, True)
self.assertAlmostEqual(utils.LAST_MTIME, t, places=2)