17 |
17 |
18 HelpCollection = r"""<?xml version="1.0" encoding="utf-8" ?> |
18 HelpCollection = r"""<?xml version="1.0" encoding="utf-8" ?> |
19 <QHelpCollectionProject version="1.0"> |
19 <QHelpCollectionProject version="1.0"> |
20 <docFiles> |
20 <docFiles> |
21 <register> |
21 <register> |
22 <file>%(helpfile)s</file> |
22 <file>{helpfile}</file> |
23 </register> |
23 </register> |
24 </docFiles> |
24 </docFiles> |
25 </QHelpCollectionProject> |
25 </QHelpCollectionProject> |
26 """ |
26 """ |
27 |
27 |
28 HelpProject = r"""<?xml version="1.0" encoding="UTF-8"?> |
28 HelpProject = r"""<?xml version="1.0" encoding="UTF-8"?> |
29 <QtHelpProject version="1.0"> |
29 <QtHelpProject version="1.0"> |
30 <namespace>%(namespace)s</namespace> |
30 <namespace>{namespace}</namespace> |
31 <virtualFolder>%(folder)s</virtualFolder> |
31 <virtualFolder>{folder}</virtualFolder> |
32 <customFilter name="%(filter_name)s"> |
32 <customFilter name="{filter_name}"> |
33 %(filter_attributes)s |
33 {filter_attributes} |
34 </customFilter> |
34 </customFilter> |
35 <filterSection> |
35 <filterSection> |
36 %(filter_attributes)s |
36 {filter_attributes} |
37 <toc> |
37 <toc> |
38 %(sections)s |
38 {sections} |
39 </toc> |
39 </toc> |
40 <keywords> |
40 <keywords> |
41 %(keywords)s |
41 {keywords} |
42 </keywords> |
42 </keywords> |
43 <files> |
43 <files> |
44 %(files)s |
44 {files} |
45 </files> |
45 </files> |
46 </filterSection> |
46 </filterSection> |
47 </QtHelpProject> |
47 </QtHelpProject> |
48 """ |
48 """ |
49 |
49 |
123 self.packages[package] = { |
123 self.packages[package] = { |
124 "subpackages" : {}, |
124 "subpackages" : {}, |
125 "modules" : {} |
125 "modules" : {} |
126 } |
126 } |
127 |
127 |
128 kwEntry = ("%s (Package)" % package.split('.')[-1], |
128 kwEntry = ("{0} (Package)".format(package.split('.')[-1]), |
129 joinext("index-%s" % package, ".html")) |
129 joinext("index-{0}".format(package), ".html")) |
130 if kwEntry not in self.keywords: |
130 if kwEntry not in self.keywords: |
131 self.keywords.append(kwEntry) |
131 self.keywords.append(kwEntry) |
132 |
132 |
133 if moduleDocument.isEmpty(): |
133 if moduleDocument.isEmpty(): |
134 return |
134 return |
139 except KeyError: |
139 except KeyError: |
140 elt = self.packages["00index"] |
140 elt = self.packages["00index"] |
141 elt["modules"][moduleDocument.name()] = moduleDocument.name() |
141 elt["modules"][moduleDocument.name()] = moduleDocument.name() |
142 |
142 |
143 if "__init__" not in file: |
143 if "__init__" not in file: |
144 kwEntry = ("%s (Module)" % moduleDocument.name().split('.')[-1], |
144 kwEntry = ("{0} (Module)".format(moduleDocument.name().split('.')[-1]), |
145 joinext(moduleDocument.name(), ".html")) |
145 joinext(moduleDocument.name(), ".html")) |
146 if kwEntry not in self.keywords: |
146 if kwEntry not in self.keywords: |
147 self.keywords.append(kwEntry) |
147 self.keywords.append(kwEntry) |
148 for kw in moduleDocument.getQtHelpKeywords(): |
148 for kw in moduleDocument.getQtHelpKeywords(): |
149 kwEntry = (kw[0], "%s%s" % (joinext(moduleDocument.name(), ".html"), kw[1])) |
149 kwEntry = (kw[0], "{0}{1}".format( |
|
150 joinext(moduleDocument.name(), ".html"), kw[1])) |
150 if kwEntry not in self.keywords: |
151 if kwEntry not in self.keywords: |
151 self.keywords.append(kwEntry) |
152 self.keywords.append(kwEntry) |
152 |
153 |
153 def __generateSections(self, package, level): |
154 def __generateSections(self, package, level): |
154 """ |
155 """ |
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="%s" ref="%s">\n' % \ |
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-%s" % 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) |
170 s += '\n' |
171 s += '\n' |
171 for mod in sorted(self.packages[package]["modules"]): |
172 for mod in sorted(self.packages[package]["modules"]): |
172 s += indent1 + '<section title="%s" ref="%s" />\n' % \ |
173 s += indent1 + '<section title="{0}" ref="{1}" />\n'.format( |
173 (mod, joinext(mod, ".html")) |
174 mod, joinext(mod, ".html")) |
174 s += indent + '</section>' |
175 s += indent + '</section>' |
175 return s |
176 return s |
176 |
177 |
177 def __convertEol(self, txt, newline): |
178 def __convertEol(self, txt, newline): |
178 """ |
179 """ |
207 return |
208 return |
208 |
209 |
209 if basename: |
210 if basename: |
210 basename = basename.replace(os.sep, ".") |
211 basename = basename.replace(os.sep, ".") |
211 if not basename.endswith("."): |
212 if not basename.endswith("."): |
212 basename = "%s." % basename |
213 basename = "{0}.".format(basename) |
213 |
214 |
214 sections = self.__generateSections("00index", 3) |
215 sections = self.__generateSections("00index", 3) |
215 filesList = sorted([e for e in os.listdir(self.htmlDir) if e.endswith('.html')]) |
216 filesList = sorted([e for e in os.listdir(self.htmlDir) if e.endswith('.html')]) |
216 files = "\n".join([" <file>%s</file>" % f for f in filesList]) |
217 files = "\n".join([" <file>{0}</file>".format(f) for f in filesList]) |
217 filterAttribs = "\n".join([" <filterAttribute>%s</filterAttribute>" % a \ |
218 filterAttribs = "\n".join([" <filterAttribute>{0}</filterAttribute>".format(a) \ |
218 for a in self.filterAttributes]) |
219 for a in self.filterAttributes]) |
219 keywords = "\n".join( |
220 keywords = "\n".join( |
220 [' <keyword name="%s" id="%s" ref="%s" />' % \ |
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, |
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 % helpAttribs, newline) |
235 txt = self.__convertEol(HelpProject.format(**helpAttribs), newline) |
235 f = codecs.open(os.path.join(self.outputDir, HelpProjectFile), 'w', 'utf-8') |
236 f = codecs.open(os.path.join(self.outputDir, HelpProjectFile), 'w', 'utf-8') |
236 f.write(txt) |
237 f.write(txt) |
237 f.close() |
238 f.close() |
238 |
239 |
239 if self.createCollection and \ |
240 if self.createCollection and \ |
240 not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)): |
241 not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)): |
241 collectionAttribs = { |
242 collectionAttribs = { |
242 "helpfile" : HelpHelpFile, |
243 "helpfile" : HelpHelpFile, |
243 } |
244 } |
244 |
245 |
245 txt = self.__convertEol(HelpCollection % collectionAttribs, newline) |
246 txt = self.__convertEol(HelpCollection.format(**collectionAttribs), newline) |
246 f = codecs.open(os.path.join(self.outputDir, HelpCollectionProjectFile), |
247 f = codecs.open(os.path.join(self.outputDir, HelpCollectionProjectFile), |
247 'w', 'utf-8') |
248 'w', 'utf-8') |
248 f.write(txt) |
249 f.write(txt) |
249 f.close() |
250 f.close() |
250 |
251 |