Add a cache for post reading during blog generation
This commit is contained in:
parent
2c7f4be96e
commit
0cef65c4e1
|
@ -14,7 +14,6 @@ class StrictUTF8Writer(codecs.StreamWriter):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.value = u''
|
self.value = u''
|
||||||
pass
|
|
||||||
|
|
||||||
def write(self, object):
|
def write(self, object):
|
||||||
object = object.replace('<', '<')
|
object = object.replace('<', '<')
|
||||||
|
@ -41,9 +40,10 @@ class DynastieGenerator:
|
||||||
report = ''
|
report = ''
|
||||||
somethingWrote = False
|
somethingWrote = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, hash_posts=None):
|
||||||
self.report = ''
|
self.report = ''
|
||||||
self.somethingWrote = False
|
self.somethingWrote = False
|
||||||
|
self.hash_posts = hash_posts
|
||||||
|
|
||||||
def addReport(self, string, color=''):
|
def addReport(self, string, color=''):
|
||||||
if color != '':
|
if color != '':
|
||||||
|
|
|
@ -98,9 +98,13 @@ class Index(DynastieGenerator):
|
||||||
self.addError('File does not exists ' + filename)
|
self.addError('File does not exists ' + filename)
|
||||||
return
|
return
|
||||||
|
|
||||||
f = open(filename, 'rb')
|
if self.hash_posts is None or not filename in self.hash_posts:
|
||||||
post_content = f.read()
|
f = open(filename, 'rb')
|
||||||
f.close()
|
post_content = f.read()
|
||||||
|
f.close()
|
||||||
|
self.hash_posts[filename] = post_content
|
||||||
|
else:
|
||||||
|
post_content = self.hash_posts[filename]
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
start = post_content.find('<dyn:code')
|
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):
|
if not directory is None and not os.path.exists(output + self.dirname):
|
||||||
os.mkdir(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:
|
while self.cur_page <= self.nb_pages:
|
||||||
#print 'Generate ' + filename
|
#print 'Generate ' + filename
|
||||||
nodes = dom.getElementsByTagName("*")
|
nodes = dom.getElementsByTagName("*")
|
||||||
nodes[0] = self.parse(src, self.hooks, posts, dom, nodes[0])
|
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
|
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)
|
dom = parse(src + '/_%s.html' % name)
|
||||||
|
|
||||||
filename = output + '/' + filename
|
filename = output + filename
|
||||||
|
|
||||||
while os.path.exists(filename):
|
while os.path.exists(filename):
|
||||||
self.addReport('Removing unused ' + filename)
|
self.addReport('Removing unused ' + filename)
|
||||||
|
@ -331,7 +335,8 @@ class Index(DynastieGenerator):
|
||||||
self.addReport('Removing unused ' + filename)
|
self.addReport('Removing unused ' + filename)
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
self.cur_page = self.cur_page + 1
|
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):
|
def generate(self, blog, src, output):
|
||||||
from dynastie.models import Post, Blog
|
from dynastie.models import Post, Blog
|
||||||
|
|
|
@ -149,13 +149,14 @@ class Blog(models.Model):
|
||||||
self.load_generators()
|
self.load_generators()
|
||||||
self.copytree(self.src_path, self.output_path)
|
self.copytree(self.src_path, self.output_path)
|
||||||
generated = []
|
generated = []
|
||||||
|
hash_posts = {}
|
||||||
for engine in self.engines:
|
for engine in self.engines:
|
||||||
if not inspect.ismodule(engine):
|
if not inspect.ismodule(engine):
|
||||||
continue
|
continue
|
||||||
for name, obj in inspect.getmembers(engine):
|
for name, obj in inspect.getmembers(engine):
|
||||||
if inspect.isclass(obj) and obj.__module__.startswith("dynastie.generators"):
|
if inspect.isclass(obj) and obj.__module__.startswith("dynastie.generators"):
|
||||||
if obj.__module__ in generated: continue
|
if obj.__module__ in generated: continue
|
||||||
e = obj()
|
e = obj(hash_posts)
|
||||||
r = e.generate(self, self.src_path, self.output_path)
|
r = e.generate(self, self.src_path, self.output_path)
|
||||||
generated.append(obj.__module__)
|
generated.append(obj.__module__)
|
||||||
if not r is None:
|
if not r is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user