54 HelpCollectionFile = 'collection.qhc' |
55 HelpCollectionFile = 'collection.qhc' |
55 |
56 |
56 |
57 |
57 class QtHelpGenerator(object): |
58 class QtHelpGenerator(object): |
58 """ |
59 """ |
59 Class implementing the QtHelp generator for the builtin documentation generator. |
60 Class implementing the QtHelp generator for the builtin documentation |
|
61 generator. |
60 """ |
62 """ |
61 def __init__(self, htmlDir, |
63 def __init__(self, htmlDir, |
62 outputDir, namespace, virtualFolder, filterName, filterAttributes, |
64 outputDir, namespace, virtualFolder, filterName, |
63 title, createCollection): |
65 filterAttributes, title, createCollection): |
64 """ |
66 """ |
65 Constructor |
67 Constructor |
66 |
68 |
67 @param htmlDir directory containing the HTML files (string) |
69 @param htmlDir directory containing the HTML files (string) |
68 @param outputDir output directory for the files (string) |
70 @param outputDir output directory for the files (string) |
69 @param namespace namespace to be used (string) |
71 @param namespace namespace to be used (string) |
70 @param virtualFolder virtual folder to be used (string) |
72 @param virtualFolder virtual folder to be used (string) |
71 @param filterName name of the custom filter (string) |
73 @param filterName name of the custom filter (string) |
72 @param filterAttributes ':' separated list of filter attributes (string) |
74 @param filterAttributes ':' separated list of filter attributes |
|
75 (string) |
73 @param title title to be used for the generated help (string) |
76 @param title title to be used for the generated help (string) |
74 @param createCollection flag indicating the generation of the collection |
77 @param createCollection flag indicating the generation of the |
75 files (boolean) |
78 collection files (boolean) |
76 """ |
79 """ |
77 self.htmlDir = htmlDir |
80 self.htmlDir = htmlDir |
78 self.outputDir = outputDir |
81 self.outputDir = outputDir |
79 self.namespace = namespace |
82 self.namespace = namespace |
80 self.virtualFolder = virtualFolder |
83 self.virtualFolder = virtualFolder |
81 self.filterName = filterName |
84 self.filterName = filterName |
82 self.filterAttributes = filterAttributes and filterAttributes.split(':') or [] |
85 self.filterAttributes = \ |
|
86 filterAttributes and filterAttributes.split(':') or [] |
83 self.relPath = relpath(self.htmlDir, self.outputDir) |
87 self.relPath = relpath(self.htmlDir, self.outputDir) |
84 self.title = title |
88 self.title = title |
85 self.createCollection = createCollection |
89 self.createCollection = createCollection |
86 |
90 |
87 self.packages = { |
91 self.packages = { |
141 except KeyError: |
145 except KeyError: |
142 elt = self.packages["00index"] |
146 elt = self.packages["00index"] |
143 elt["modules"][moduleDocument.name()] = moduleDocument.name() |
147 elt["modules"][moduleDocument.name()] = moduleDocument.name() |
144 |
148 |
145 if "__init__" not in file: |
149 if "__init__" not in file: |
146 kwEntry = ("{0} (Module)".format(moduleDocument.name().split('.')[-1]), |
150 kwEntry = ( |
147 joinext(moduleDocument.name(), ".html")) |
151 "{0} (Module)".format(moduleDocument.name().split('.')[-1]), |
|
152 joinext(moduleDocument.name(), ".html")) |
148 if kwEntry not in self.keywords: |
153 if kwEntry not in self.keywords: |
149 self.keywords.append(kwEntry) |
154 self.keywords.append(kwEntry) |
150 for kw in moduleDocument.getQtHelpKeywords(): |
155 for kw in moduleDocument.getQtHelpKeywords(): |
151 kwEntry = (kw[0], "{0}{1}".format( |
156 kwEntry = (kw[0], "{0}{1}".format( |
152 joinext(moduleDocument.name(), ".html"), kw[1])) |
157 joinext(moduleDocument.name(), ".html"), kw[1])) |
213 basename = basename.replace(os.sep, ".") |
218 basename = basename.replace(os.sep, ".") |
214 if not basename.endswith("."): |
219 if not basename.endswith("."): |
215 basename = "{0}.".format(basename) |
220 basename = "{0}.".format(basename) |
216 |
221 |
217 sections = self.__generateSections("00index", 3) |
222 sections = self.__generateSections("00index", 3) |
218 filesList = sorted([e for e in os.listdir(self.htmlDir) if e.endswith('.html')]) |
223 filesList = sorted( |
219 files = "\n".join([" <file>{0}</file>".format(f) for f in filesList]) |
224 [e for e in os.listdir(self.htmlDir) if e.endswith('.html')]) |
220 filterAttribs = "\n".join([" <filterAttribute>{0}</filterAttribute>".format(a) \ |
225 files = "\n".join( |
221 for a in sorted(self.filterAttributes)]) |
226 [" <file>{0}</file>".format(f) for f in filesList]) |
|
227 filterAttribs = "\n".join( |
|
228 [" <filterAttribute>{0}</filterAttribute>".format(a) |
|
229 for a in sorted(self.filterAttributes)]) |
222 keywords = "\n".join( |
230 keywords = "\n".join( |
223 [' <keyword name="{0}" id="{1}" ref="{2}" />'.format( |
231 [' <keyword name="{0}" id="{1}" ref="{2}" />'.format( |
224 html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1])) \ |
232 html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1])) |
225 for kw in sorted(self.keywords)]) |
233 for kw in sorted(self.keywords)]) |
226 |
234 |
227 helpAttribs = { |
235 helpAttribs = { |
228 "namespace": self.namespace, |
236 "namespace": self.namespace, |
229 "folder": self.virtualFolder, |
237 "folder": self.virtualFolder, |
239 encoding="utf-8", newline=newline) |
247 encoding="utf-8", newline=newline) |
240 f.write(txt) |
248 f.write(txt) |
241 f.close() |
249 f.close() |
242 |
250 |
243 if self.createCollection and \ |
251 if self.createCollection and \ |
244 not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)): |
252 not os.path.exists( |
|
253 os.path.join(self.outputDir, HelpCollectionProjectFile)): |
245 collectionAttribs = { |
254 collectionAttribs = { |
246 "helpfile": HelpHelpFile, |
255 "helpfile": HelpHelpFile, |
247 } |
256 } |
248 |
257 |
249 txt = self.__convertEol(HelpCollection.format(**collectionAttribs), newline) |
258 txt = self.__convertEol( |
|
259 HelpCollection.format(**collectionAttribs), newline) |
250 f = open(os.path.join(self.outputDir, HelpCollectionProjectFile), |
260 f = open(os.path.join(self.outputDir, HelpCollectionProjectFile), |
251 "w", encoding="utf-8", newline=newline) |
261 "w", encoding="utf-8", newline=newline) |
252 f.write(txt) |
262 f.write(txt) |
253 f.close() |
263 f.close() |
254 |
264 |
257 sys.stdout.flush() |
267 sys.stdout.flush() |
258 sys.stderr.flush() |
268 sys.stderr.flush() |
259 |
269 |
260 cwd = os.getcwd() |
270 cwd = os.getcwd() |
261 # generate the compressed files |
271 # generate the compressed files |
262 shutil.copy(os.path.join(self.outputDir, HelpProjectFile), self.htmlDir) |
272 shutil.copy( |
|
273 os.path.join(self.outputDir, HelpProjectFile), self.htmlDir) |
263 os.chdir(self.htmlDir) |
274 os.chdir(self.htmlDir) |
264 subprocess.call([os.path.join(getQtBinariesPath(), "qhelpgenerator"), |
275 subprocess.call([ |
265 "source.qhp", "-o", os.path.join(self.outputDir, HelpHelpFile)]) |
276 os.path.join(getQtBinariesPath(), "qhelpgenerator"), |
|
277 "source.qhp", "-o", os.path.join(self.outputDir, HelpHelpFile)]) |
266 os.remove(HelpProjectFile) |
278 os.remove(HelpProjectFile) |
267 |
279 |
268 if self.createCollection: |
280 if self.createCollection: |
269 sys.stdout.write("Generating QtHelp collection...\n") |
281 sys.stdout.write("Generating QtHelp collection...\n") |
270 sys.stdout.flush() |
282 sys.stdout.flush() |
271 sys.stderr.flush() |
283 sys.stderr.flush() |
272 os.chdir(self.outputDir) |
284 os.chdir(self.outputDir) |
273 subprocess.call([os.path.join(getQtBinariesPath(), "qcollectiongenerator"), |
285 subprocess.call([ |
274 "source.qhcp", "-o", "collection.qhc"]) |
286 os.path.join(getQtBinariesPath(), "qcollectiongenerator"), |
|
287 "source.qhcp", "-o", "collection.qhc"]) |
275 |
288 |
276 os.chdir(cwd) |
289 os.chdir(cwd) |