From 224faf5dc4143ec3d6c90328577917166ec02289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 31 Dec 2012 17:45:21 +0100 Subject: [PATCH] Avoid parsing the template again and again by cloning it --- generators/index.py | 7 +++++-- generators/post.py | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/generators/index.py b/generators/index.py index 362eb16..e2e6102 100644 --- a/generators/index.py +++ b/generators/index.py @@ -315,15 +315,18 @@ class Index(DynastieGenerator): os.mkdir(output + self.dirname) filename = self.dirname + '/' + self.filename + '.html' + + impl = xml.dom.getDOMImplementation() while self.cur_page <= self.nb_pages: #print 'Generate ' + filename + dom_ = impl.createDocument('', 'xml', None) + dom_.replaceChild(dom.firstChild.cloneNode(0), dom_.firstChild) 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.cur_page = self.cur_page + 1 filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html' - dom = parse(src + '/_%s.html' % name) filename = output + filename diff --git a/generators/post.py b/generators/post.py index ddabce5..f350c7d 100644 --- a/generators/post.py +++ b/generators/post.py @@ -158,10 +158,13 @@ class Post(Index): self.addError('Error parsing _%s.html : ' + e) return self.report + impl = xml.dom.getDOMImplementation() for post in posts: #print 'Generate ' + filename + dom_ = impl.createDocument('', 'xml', None) + dom_.replaceChild(dom.firstChild.cloneNode(0), dom_.firstChild) nodes = dom.getElementsByTagName("*") - nodes[0] = self.parse(src, self.hooks, post, dom, nodes[0]) + nodes[0] = self.parse(src, self.hooks, post, dom_, nodes[0]) filename = output + '/post/' filename = filename + post.creation_date.strftime("%Y") + '/' + post.creation_date.strftime("%m") + '/' @@ -169,7 +172,6 @@ class Post(Index): os.makedirs(filename) filename = filename + post.title_slug + '.html' self.writeIfNotTheSame(filename, nodes[0]) - dom = parse(src + '/_post.html') if not self.somethingWrote: self.addReport('Nothing changed')