DocumentationTools/QtHelpGenerator.py

changeset 945
8cd4d08fa9f6
parent 839
9605f699731f
child 1509
c0b5e693b0eb
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
49 HelpProjectFile = 'source.qhp' 49 HelpProjectFile = 'source.qhp'
50 HelpHelpFile = 'source.qch' 50 HelpHelpFile = 'source.qch'
51 HelpCollectionProjectFile = 'source.qhcp' 51 HelpCollectionProjectFile = 'source.qhcp'
52 HelpCollectionFile = 'collection.qhc' 52 HelpCollectionFile = 'collection.qhc'
53 53
54
54 class QtHelpGenerator(object): 55 class QtHelpGenerator(object):
55 """ 56 """
56 Class implementing the QtHelp generator for the builtin documentation generator. 57 Class implementing the QtHelp generator for the builtin documentation generator.
57 """ 58 """
58 def __init__(self, htmlDir, 59 def __init__(self, htmlDir,
59 outputDir, namespace, virtualFolder, filterName, filterAttributes, 60 outputDir, namespace, virtualFolder, filterName, filterAttributes,
60 title, createCollection): 61 title, createCollection):
61 """ 62 """
62 Constructor 63 Constructor
63 64
64 @param htmlDir directory containing the HTML files (string) 65 @param htmlDir directory containing the HTML files (string)
80 self.relPath = relpath(self.htmlDir, self.outputDir) 81 self.relPath = relpath(self.htmlDir, self.outputDir)
81 self.title = title 82 self.title = title
82 self.createCollection = createCollection 83 self.createCollection = createCollection
83 84
84 self.packages = { 85 self.packages = {
85 "00index" : { 86 "00index": {
86 "subpackages" : {}, 87 "subpackages": {},
87 "modules" : {} 88 "modules": {}
88 } 89 }
89 } 90 }
90 self.remembered = False 91 self.remembered = False
91 self.keywords = [] 92 self.keywords = []
92 93
93 def remember(self, file, moduleDocument, basename=""): 94 def remember(self, file, moduleDocument, basename=""):
94 """ 95 """
95 Public method to remember a documentation file. 96 Public method to remember a documentation file.
96 97
97 @param file The filename to be remembered. (string) 98 @param file The filename to be remembered. (string)
98 @param moduleDocument The ModuleDocument object containing the 99 @param moduleDocument The ModuleDocument object containing the
99 information for the file. 100 information for the file.
100 @param basename The basename of the file hierarchy to be documented. 101 @param basename The basename of the file hierarchy to be documented.
101 The basename is stripped off the filename if it starts with 102 The basename is stripped off the filename if it starts with
102 the basename. 103 the basename.
103 """ 104 """
118 elt = self.packages["00index"] 119 elt = self.packages["00index"]
119 package = dir.replace(os.sep, ".") 120 package = dir.replace(os.sep, ".")
120 elt["subpackages"][package] = moduleDocument.name() 121 elt["subpackages"][package] = moduleDocument.name()
121 122
122 self.packages[package] = { 123 self.packages[package] = {
123 "subpackages" : {}, 124 "subpackages": {},
124 "modules" : {} 125 "modules": {}
125 } 126 }
126 127
127 kwEntry = ("{0} (Package)".format(package.split('.')[-1]), 128 kwEntry = ("{0} (Package)".format(package.split('.')[-1]),
128 joinext("index-{0}".format(package), ".html")) 129 joinext("index-{0}".format(package), ".html"))
129 if kwEntry not in self.keywords: 130 if kwEntry not in self.keywords:
130 self.keywords.append(kwEntry) 131 self.keywords.append(kwEntry)
131 132
132 if moduleDocument.isEmpty(): 133 if moduleDocument.isEmpty():
138 except KeyError: 139 except KeyError:
139 elt = self.packages["00index"] 140 elt = self.packages["00index"]
140 elt["modules"][moduleDocument.name()] = moduleDocument.name() 141 elt["modules"][moduleDocument.name()] = moduleDocument.name()
141 142
142 if "__init__" not in file: 143 if "__init__" not in file:
143 kwEntry = ("{0} (Module)".format(moduleDocument.name().split('.')[-1]), 144 kwEntry = ("{0} (Module)".format(moduleDocument.name().split('.')[-1]),
144 joinext(moduleDocument.name(), ".html")) 145 joinext(moduleDocument.name(), ".html"))
145 if kwEntry not in self.keywords: 146 if kwEntry not in self.keywords:
146 self.keywords.append(kwEntry) 147 self.keywords.append(kwEntry)
147 for kw in moduleDocument.getQtHelpKeywords(): 148 for kw in moduleDocument.getQtHelpKeywords():
148 kwEntry = (kw[0], "{0}{1}".format( 149 kwEntry = (kw[0], "{0}{1}".format(
158 @param level indentation level (integer) 159 @param level indentation level (integer)
159 @return sections part (string) 160 @return sections part (string)
160 """ 161 """
161 indent = level * ' ' 162 indent = level * ' '
162 indent1 = indent + ' ' 163 indent1 = indent + ' '
163 s = indent + '<section title="{0}" ref="{1}">\n'.format( 164 s = indent + '<section title="{0}" ref="{1}">\n'.format(
164 package == "00index" and self.title or package, 165 package == "00index" and self.title or package,
165 package == "00index" and \ 166 package == "00index" and \
166 joinext("index", ".html") or \ 167 joinext("index", ".html") or \
167 joinext("index-{0}".format(package), ".html")) 168 joinext("index-{0}".format(package), ".html"))
168 for subpack in sorted(self.packages[package]["subpackages"]): 169 for subpack in sorted(self.packages[package]["subpackages"]):
169 s += self.__generateSections(subpack, level + 1) 170 s += self.__generateSections(subpack, level + 1)
191 elif newline in ["\r", "\r\n"]: 192 elif newline in ["\r", "\r\n"]:
192 return txt.replace("\n", newline) 193 return txt.replace("\n", newline)
193 else: 194 else:
194 return txt 195 return txt
195 196
196 def generateFiles(self, basename = "", newline = None): 197 def generateFiles(self, basename="", newline=None):
197 """ 198 """
198 Public method to generate all index files. 199 Public method to generate all index files.
199 200
200 @param basename The basename of the file hierarchy to be documented. 201 @param basename The basename of the file hierarchy to be documented.
201 The basename is stripped off the filename if it starts with 202 The basename is stripped off the filename if it starts with
220 [' <keyword name="{0}" id="{1}" ref="{2}" />'.format( 221 [' <keyword name="{0}" id="{1}" ref="{2}" />'.format(
221 html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1])) \ 222 html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1])) \
222 for kw in self.keywords]) 223 for kw in self.keywords])
223 224
224 helpAttribs = { 225 helpAttribs = {
225 "namespace" : self.namespace, 226 "namespace": self.namespace,
226 "folder" : self.virtualFolder, 227 "folder": self.virtualFolder,
227 "filter_name" : self.filterName, 228 "filter_name": self.filterName,
228 "filter_attributes" : filterAttribs, 229 "filter_attributes": filterAttribs,
229 "sections" : sections, 230 "sections": sections,
230 "keywords" : keywords, 231 "keywords": keywords,
231 "files" : files, 232 "files": files,
232 } 233 }
233 234
234 txt = self.__convertEol(HelpProject.format(**helpAttribs), newline) 235 txt = self.__convertEol(HelpProject.format(**helpAttribs), newline)
235 f = open(os.path.join(self.outputDir, HelpProjectFile), "w", 236 f = open(os.path.join(self.outputDir, HelpProjectFile), "w",
236 encoding = "utf-8", newline = newline) 237 encoding="utf-8", newline=newline)
237 f.write(txt) 238 f.write(txt)
238 f.close() 239 f.close()
239 240
240 if self.createCollection and \ 241 if self.createCollection and \
241 not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)): 242 not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)):
242 collectionAttribs = { 243 collectionAttribs = {
243 "helpfile" : HelpHelpFile, 244 "helpfile": HelpHelpFile,
244 } 245 }
245 246
246 txt = self.__convertEol(HelpCollection.format(**collectionAttribs), newline) 247 txt = self.__convertEol(HelpCollection.format(**collectionAttribs), newline)
247 f = open(os.path.join(self.outputDir, HelpCollectionProjectFile), 248 f = open(os.path.join(self.outputDir, HelpCollectionProjectFile),
248 "w", encoding = "utf-8", newline = newline) 249 "w", encoding="utf-8", newline=newline)
249 f.write(txt) 250 f.write(txt)
250 f.close() 251 f.close()
251 252
252 sys.stdout.write("QtHelp files written.\n") 253 sys.stdout.write("QtHelp files written.\n")
253 sys.stdout.write("Generating QtHelp documentation...\n") 254 sys.stdout.write("Generating QtHelp documentation...\n")
256 257
257 cwd = os.getcwd() 258 cwd = os.getcwd()
258 # generate the compressed files 259 # generate the compressed files
259 shutil.copy(os.path.join(self.outputDir, HelpProjectFile), self.htmlDir) 260 shutil.copy(os.path.join(self.outputDir, HelpProjectFile), self.htmlDir)
260 os.chdir(self.htmlDir) 261 os.chdir(self.htmlDir)
261 subprocess.call(["qhelpgenerator", "source.qhp", 262 subprocess.call(["qhelpgenerator", "source.qhp",
262 "-o", os.path.join(self.outputDir, HelpHelpFile)]) 263 "-o", os.path.join(self.outputDir, HelpHelpFile)])
263 os.remove(HelpProjectFile) 264 os.remove(HelpProjectFile)
264 265
265 if self.createCollection: 266 if self.createCollection:
266 sys.stdout.write("Generating QtHelp collection...\n") 267 sys.stdout.write("Generating QtHelp collection...\n")

eric ide

mercurial