DocumentationTools/QtHelpGenerator.py

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

eric ide

mercurial