Attachment '1.patch'
Download 1 changeset: 4206:0274b9f1343b
2 branch: docbook
3 parent: 4199:f414aece63e0
4 user: matthijs@stdin.nl
5 date: Mon Nov 24 22:40:14 2008 +0100
6 summary: docbook parser: Use the caching framework for the compiled XSL file.
7
8 diff -r f414aece63e0 -r 0274b9f1343b MoinMoin/config/multiconfig.py
9 --- a/MoinMoin/config/multiconfig.py Tue Nov 11 22:00:33 2008 +0100
10 +++ b/MoinMoin/config/multiconfig.py Mon Nov 24 22:40:14 2008 +0100
11 @@ -900,8 +900,10 @@
12 ('plugin_dir', None, "Plugin directory, by default computed to be `data_dir`/plugin."),
13 ('plugin_dirs', [], "Additional plugin directories."),
14
15 - ('docbook_html_dir', r"/usr/share/xml/docbook/stylesheet/nwalsh/html/",
16 - 'Path to the directory with the Docbook to HTML XSLT files (optional, used by the docbook parser). The default value is correct for Debian Etch.'),
17 + ('docbook_html_dir', None,
18 + 'Path to the docbook.xsl file. Deprecated, use docbook_xsl instead.'),
19 + ('docbook_xsl', r"/usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl",
20 + 'Path to the HTML XSLT file (optional, used by the docbook parser). The default value is correct for Debian Etch.'),
21 ('shared_intermap', None,
22 "Path to a file containing global InterWiki definitions (or a list of such filenames)"),
23 )),
24 diff -r f414aece63e0 -r 0274b9f1343b MoinMoin/parser/text_docbook.py
25 --- a/MoinMoin/parser/text_docbook.py Tue Nov 11 22:00:33 2008 +0100
26 +++ b/MoinMoin/parser/text_docbook.py Mon Nov 24 22:40:14 2008 +0100
27 @@ -35,6 +35,9 @@
28 import re
29
30 from MoinMoin import Page
31 +from MoinMoin import caching
32 +from MoinMoin import log
33 +logging = log.getLogger(__name__)
34 from MoinMoin.parser.text_xslt import Parser as XsltParser
35 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
36
37 @@ -52,31 +55,97 @@
38 XsltParser.__init__(self, raw, request)
39
40 # relative path to docbook.xsl and compiled_xsl
41 - docbook_html_directory = request.cfg.docbook_html_dir
42 - self.db_xsl = os.path.join(docbook_html_directory, 'docbook.xsl')
43 - self.db_compiled_xsl = os.path.join(docbook_html_directory, 'db_compiled.dat')
44 + if not request.cfg.docbook_html_dir is None:
45 + self.db_xsl = os.path.join(request.cfg.docbook_html, 'docbook.xsl')
46 + else:
47 + self.db_xsl = request.cfg.docbook_xsl
48
49 self.wikiParser = WikiParser(raw=self.raw, request=self.request, pretty_url=1)
50 self.key = 'docbook'
51
52 + # We save the compiled version of the XSL file in the cache, to
53 + # speed up rendering. We have a separate entry for the filename,
54 + # so we can properly refresh the cache when the docbook_xsl
55 + # configuration value changes.
56 + self.cached = caching.CacheEntry(self.request,
57 + arena='docbook',
58 + key='compiled_xsl',
59 + scope='farm',
60 + use_pickle=True)
61 +
62 + self.cached_name = caching.CacheEntry(self.request,
63 + arena='docbook',
64 + key='docbook_xsl_filename',
65 + scope='farm',
66 + use_pickle=True)
67 +
68 +
69 def format(self, formatter):
70 self.wikiParser.formatter = formatter
71 XsltParser.format(self, formatter)
72
73 + def get_cached_stylesheet(self, abs_db_xsl, log=True):
74 + """ Try to get the compiled xsl file from the cache.
75 +
76 + @param abs_db_xsl: The input xsl file of which we should find
77 + the compiled version.
78 + @param errors: Should we do logging?
79 + """
80 + try:
81 + if self.cached_name.content() != abs_db_xsl:
82 + if log:
83 + logging.debug(
84 + "Docbook XSL file configuration changed from %s to %s" %
85 + (cached_name.content(), abs_db_xsl)
86 + )
87 + elif self.cached.needsUpdate(abs_db_xsl):
88 + if log:
89 + logging.debug("Docbook XSL file changed")
90 + else:
91 + # Good, we got a cache hit!
92 + compiled = self.cached.content()
93 + if log:
94 + logging.debug("Got compiled Docbook XSL file from cache")
95 + return compiled
96 + except caching.CacheError:
97 + if log:
98 + logging.debug("Got cache error for compiled XSL file")
99 + return None
100 +
101 def append_stylesheet(self):
102 """"
103 virtual function, for docbook parser
104 """
105 abs_db_xsl = os.path.abspath(self.db_xsl)
106 - abs_db_compiled_xsl = os.path.abspath(self.db_compiled_xsl)
107
108 - # same as path.exists, but also test if it is a file
109 - if not os.path.isfile(abs_db_compiled_xsl):
110 - _compile_xsl(abs_db_xsl, abs_db_compiled_xsl)
111 + compiled = self.get_cached_stylesheet(abs_db_xsl)
112
113 - assert os.path.isfile(abs_db_compiled_xsl)
114 + if compiled is None:
115 + # Recompile the XSL file
116 + logging.debug("(Re)compiling Docbook XSL file: '%s'" % (abs_db_xsl))
117 + compiled = _compile_xsl(abs_db_xsl)
118 + # Check the cache again (another thread might have filled
119 + # the cache by now) and update the cache if that's not the
120 + # case. Don't do any logging of the result, since that might
121 + # be confusing.
122 + if (self.get_cached_stylesheet(abs_db_xsl, log=False) is None):
123 + # We first remove the old cached_name, to prevent an
124 + # inconsistent situation and invalid cache hits after
125 + # changing the xsl filename configuration. This does
126 + # allow for possibly indefinite recompiling, if
127 + # everytime a new thread triggers recompilation just
128 + # between the remove and update of cached_name. However,
129 + # the recheck of the cache combined with the long time
130 + # needed to compile the xsl should make this case
131 + # extremely unlikely.
132 + self.cached_name.remove()
133 + self.cached.update(compiled)
134 + self.cached_name.update(abs_db_xsl)
135 + logging.debug("Saved compiled Docbook XSL file to cache")
136 + else:
137 + logging.debug("Skipping saving of compiled Docbook XSL file to cache")
138
139 - self.processor.appendStylesheetInstance(cPickle.load(file(abs_db_compiled_xsl, 'rb')))
140 + self.processor.appendStylesheetInstance(compiled)
141
142 def parse_result(self, result):
143 """
144 @@ -153,7 +222,7 @@
145
146
147
148 -def _compile_xsl(XSLT_FILE, XSLT_COMPILED_FILE):
149 +def _compile_xsl(XSLT_FILE):
150 """
151 compiling docbook stylesheet
152
153 @@ -176,9 +245,8 @@
154
155 # Pickled stylesheet will be self.abs_db_compiled_xsl file
156 db_root = db_processor.stylesheet.root
157 - fw = file(XSLT_COMPILED_FILE, 'wb')
158 - cPickle.dump(db_root, fw) # , protocol=2)
159 - fw.close()
160 +
161 + return db_root
162
163
164 def _splitResult(iterator, result):
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.