Add a cache for post reading during blog generation

This commit is contained in:
Grégory Soutadé 2012-12-31 16:50:11 +01:00
parent 2c7f4be96e
commit 0cef65c4e1
3 changed files with 17 additions and 11 deletions

View File

@ -14,7 +14,6 @@ class StrictUTF8Writer(codecs.StreamWriter):
def __init__(self):
self.value = u''
pass
def write(self, object):
object = object.replace('&lt;', '<')
@ -41,9 +40,10 @@ class DynastieGenerator:
report = ''
somethingWrote = False
def __init__(self):
def __init__(self, hash_posts=None):
self.report = ''
self.somethingWrote = False
self.hash_posts = hash_posts
def addReport(self, string, color=''):
if color != '':

View File

@ -98,9 +98,13 @@ class Index(DynastieGenerator):
self.addError('File does not exists ' + filename)
return
if self.hash_posts is None or not filename in self.hash_posts:
f = open(filename, 'rb')
post_content = f.read()
f.close()
self.hash_posts[filename] = post_content
else:
post_content = self.hash_posts[filename]
while True:
start = post_content.find('<dyn:code')
@ -310,18 +314,18 @@ class Index(DynastieGenerator):
if not directory is None and not os.path.exists(output + self.dirname):
os.mkdir(output + self.dirname)
filename = self.dirname + self.filename + '.html'
filename = self.dirname + '/' + self.filename + '.html'
while self.cur_page <= self.nb_pages:
#print 'Generate ' + filename
nodes = dom.getElementsByTagName("*")
nodes[0] = self.parse(src, self.hooks, posts, dom, nodes[0])
self.writeIfNotTheSame(output + '/' + filename, nodes[0])
self.writeIfNotTheSame(output + filename, nodes[0])
self.cur_page = self.cur_page + 1
filename = self.dirname + self.filename + str(self.cur_page) + '.html'
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
dom = parse(src + '/_%s.html' % name)
filename = output + '/' + filename
filename = output + filename
while os.path.exists(filename):
self.addReport('Removing unused ' + filename)
@ -331,7 +335,8 @@ class Index(DynastieGenerator):
self.addReport('Removing unused ' + filename)
os.unlink(filename)
self.cur_page = self.cur_page + 1
filename = output + '/' + self.filename + str(self.cur_page) + '.html'
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
filename = output + filename
def generate(self, blog, src, output):
from dynastie.models import Post, Blog

View File

@ -149,13 +149,14 @@ class Blog(models.Model):
self.load_generators()
self.copytree(self.src_path, self.output_path)
generated = []
hash_posts = {}
for engine in self.engines:
if not inspect.ismodule(engine):
continue
for name, obj in inspect.getmembers(engine):
if inspect.isclass(obj) and obj.__module__.startswith("dynastie.generators"):
if obj.__module__ in generated: continue
e = obj()
e = obj(hash_posts)
r = e.generate(self, self.src_path, self.output_path)
generated.append(obj.__module__)
if not r is None: