def generateFiles(self, basename="", newline=None): """ Public method to generate all index files. @param basename The basename of the file hierarchy to be documented. The basename is stripped off the filename if it starts with the basename. @param newline newline character to be used (string) """ if not self.remembered: sys.stderr.write("No QtHelp to generate.\n") return if basename: basename = basename.replace(os.sep, ".") if not basename.endswith("."): basename = "{0}.".format(basename) sections = self.__generateSections("00index", 3) filesList = sorted([e for e in os.listdir(self.htmlDir) if e.endswith(".html")]) files = "\n".join([" <file>{0}</file>".format(f) for f in filesList]) filterAttribs = "\n".join( [" <filterAttribute>{0}</filterAttribute>".format(a) for a in sorted(self.filterAttributes)] ) keywords = "\n".join( [ ' <keyword name="{0}" id="{1}" ref="{2}" />'.format( html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1]) ) for kw in sorted(self.keywords) ] ) helpAttribs = { "namespace": self.namespace, "folder": self.virtualFolder, "filter_name": self.filterName, "filter_attributes": filterAttribs, "sections": sections, "keywords": keywords, "files": files, } txt = self.__convertEol(HelpProject.format(**helpAttribs), newline) f = open(os.path.join(self.outputDir, HelpProjectFile), "w", encoding="utf-8", newline=newline) f.write(txt) f.close() if self.createCollection and not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)): collectionAttribs = {"helpfile": HelpHelpFile} txt = self.__convertEol(HelpCollection.format(**collectionAttribs), newline) f = open(os.path.join(self.outputDir, HelpCollectionProjectFile), "w", encoding="utf-8", newline=newline) f.write(txt) f.close() sys.stdout.write("QtHelp files written.\n") sys.stdout.write("Generating QtHelp documentation...\n") sys.stdout.flush() sys.stderr.flush() cwd = os.getcwd() # generate the compressed files shutil.copy(os.path.join(self.outputDir, HelpProjectFile), self.htmlDir) os.chdir(self.htmlDir) subprocess.call( [ os.path.join(getQtBinariesPath(), "qhelpgenerator"), "source.qhp", "-o", os.path.join(self.outputDir, HelpHelpFile), ] ) os.remove(HelpProjectFile) if self.createCollection: sys.stdout.write("Generating QtHelp collection...\n") sys.stdout.flush() sys.stderr.flush() os.chdir(self.outputDir) subprocess.call( [os.path.join(getQtBinariesPath(), "qcollectiongenerator"), "source.qhcp", "-o", "collection.qhc"] ) os.chdir(cwd)
def generateFiles(self, basename="", newline=None): """ Public method to generate all index files. @param basename The basename of the file hierarchy to be documented. The basename is stripped off the filename if it starts with the basename. @param newline newline character to be used (string) """ if not self.remembered: sys.stderr.write("No QtHelp to generate.\n") return if basename: basename = basename.replace(os.sep, ".") if not basename.endswith("."): basename = "{0}.".format(basename) sections = self.__generateSections("00index", 3) filesList = sorted(e for e in os.listdir(self.htmlDir) if e.endswith('.html')) files = "\n".join( [" <file>{0}</file>".format(f) for f in filesList]) filterAttribs = "\n".join([ " <filterAttribute>{0}</filterAttribute>".format(a) for a in sorted(self.filterAttributes) ]) keywords = "\n".join([ ' <keyword name="{0}" id="{1}" ref="{2}" />'.format( html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1])) for kw in sorted(self.keywords) ]) helpAttribs = { "namespace": self.namespace, "folder": self.virtualFolder, "filter_name": self.filterName, "filter_attributes": filterAttribs, "sections": sections, "keywords": keywords, "files": files, } txt = self.__convertEol(HelpProject.format(**helpAttribs), newline) f = open(os.path.join(self.outputDir, HelpProjectFile), "w", encoding="utf-8", newline=newline) f.write(txt) f.close() if (self.createCollection and not os.path.exists( os.path.join(self.outputDir, HelpCollectionProjectFile))): collectionAttribs = { "helpfile": HelpHelpFile, } txt = self.__convertEol(HelpCollection.format(**collectionAttribs), newline) f = open(os.path.join(self.outputDir, HelpCollectionProjectFile), "w", encoding="utf-8", newline=newline) f.write(txt) f.close() sys.stdout.write("QtHelp files written.\n") sys.stdout.write("Generating QtHelp documentation...\n") sys.stdout.flush() sys.stderr.flush() cwd = os.getcwd() # generate the compressed files qhelpgeneratorExe = os.path.join(getQtBinariesPath(), generateQtToolName("qhelpgenerator")) shutil.copy(os.path.join(self.outputDir, HelpProjectFile), self.htmlDir) os.chdir(self.htmlDir) subprocess.call([ qhelpgeneratorExe, HelpProjectFile, "-o", os.path.join(self.outputDir, HelpHelpFile) ]) os.remove(HelpProjectFile) if self.createCollection: qcollectiongeneratorExe = os.path.join( getQtBinariesPath(), generateQtToolName("qcollectiongenerator")) if not isExecutable(qcollectiongeneratorExe): # assume Qt >= 5.12.0 qcollectiongeneratorExe = qhelpgeneratorExe sys.stdout.write("Generating QtHelp collection...\n") sys.stdout.flush() sys.stderr.flush() os.chdir(self.outputDir) subprocess.call([ qcollectiongeneratorExe, HelpCollectionProjectFile, "-o", HelpCollectionFile ]) os.chdir(cwd)
def generateFiles(self, basename = ""): """ Public method to generate all index files. @param basename The basename of the file hierarchy to be documented. The basename is stripped off the filename if it starts with the basename. """ if not self.remembered: sys.stderr.write("No QtHelp to generate.\n") return if basename: basename = basename.replace(os.sep, ".") if not basename.endswith("."): basename = "%s." % basename sections = self.__generateSections("00index", 3) filesList = sorted([e for e in os.listdir(self.htmlDir) if e.endswith('.html')]) files = "\n".join([" <file>%s</file>" % f for f in filesList]) filterAttribs = "\n".join([" <filterAttribute>%s</filterAttribute>" % a \ for a in sorted(self.filterAttributes)]) keywords = "\n".join( [' <keyword name="%s" id="%s" ref="%s" />' % \ (html_encode(kw[0]), html_encode(kw[0]), html_encode(kw[1])) \ for kw in sorted(self.keywords)]) helpAttribs = { "namespace" : self.namespace, "folder" : self.virtualFolder, "filter_name" : self.filterName, "filter_attributes" : filterAttribs, "sections" : sections, "keywords" : keywords, "files" : files, } f = codecs.open(os.path.join(self.outputDir, HelpProjectFile), 'w', 'utf-8') f.write(HelpProject % helpAttribs) f.close() if self.createCollection and \ not os.path.exists(os.path.join(self.outputDir, HelpCollectionProjectFile)): collectionAttribs = { "helpfile" : HelpHelpFile, } f = codecs.open(os.path.join(self.outputDir, HelpCollectionProjectFile), 'w', 'utf-8') f.write(HelpCollection % collectionAttribs) f.close() sys.stdout.write("QtHelp files written.\n") sys.stdout.write("Generating QtHelp documentation...\n") sys.stdout.flush() sys.stderr.flush() cwd = os.getcwd() # generate the compressed files shutil.copy(os.path.join(self.outputDir, HelpProjectFile), self.htmlDir) os.chdir(self.htmlDir) subprocess.call(["qhelpgenerator", "source.qhp", "-o", os.path.join(self.outputDir, HelpHelpFile)]) os.remove(HelpProjectFile) if self.createCollection: sys.stdout.write("Generating QtHelp collection...\n") sys.stdout.flush() sys.stderr.flush() os.chdir(self.outputDir) subprocess.call(["qcollectiongenerator", "source.qhcp", "-o", "collection.qhc"]) os.chdir(cwd)