def createImage(self, tempFileSet, exportType, source, insParams): """ """ # Retrieve quoted content of the insertion if self.extAppExe == "": # No path to executable -> show message return u"Please set path to GraphViz executables in options", None # Get exporters temporary file set (manages creation and deletion of # temporary files) tfs = tempFileSet source = lineendToOs(utf8Enc(source, "replace")[0]) pythonUrl = (exportType != "html_previewWX") dstFullPath = tfs.createTempFile("", ".png", relativeTo="") url = tfs.getRelativeUrl(None, dstFullPath, pythonUrl=pythonUrl) # Store token content in a temporary file srcfilepath = createTempFile(source, ".dot") try: cmdline = subprocess.list2cmdline( (self.extAppExe, "-Tpng", "-o" + dstFullPath, srcfilepath)) # Run external application # childIn, childOut, childErr = os.popen3(cmdline, "b") popenObject = subprocess.Popen(cmdline, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) childErr = popenObject.stderr # See http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error # why this is necessary popenObject.stdin.close() popenObject.stdout.close() if u"noerror" in [a.strip() for a in insParams]: childErr.read() errResponse = None else: errResponse = childErr.read() childErr.close() finally: os.unlink(srcfilepath) if errResponse is not None and errResponse != "": appname = mbcsDec(self.EXAPPNAME, "replace")[0] errResponse = mbcsDec(errResponse, "replace")[0] return (_(u"%s Error: %s") % (appname, errResponse)), None return None, url
def createImage(self, tempFileSet, exportType, source, insParams): """ """ # Retrieve quoted content of the insertion if self.extAppExe == "": # No path to executable -> show message return "Please set path to GraphViz executables in options", None # Get exporters temporary file set (manages creation and deletion of # temporary files) tfs = tempFileSet source = lineendToOs(utf8Enc(source, "replace")[0]) pythonUrl = (exportType != "html_previewWX") dstFullPath = tfs.createTempFile("", ".png", relativeTo="") url = tfs.getRelativeUrl(None, dstFullPath, pythonUrl=pythonUrl) # Store token content in a temporary file srcfilepath = createTempFile(source, ".dot") try: cmdline = subprocess.list2cmdline((self.extAppExe, "-Tpng", "-o" + dstFullPath, srcfilepath)) # Run external application # childIn, childOut, childErr = os.popen3(cmdline, "b") popenObject = subprocess.Popen(cmdline, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) childErr = popenObject.stderr # See http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error # why this is necessary popenObject.stdin.close() popenObject.stdout.close() if "noerror" in [a.strip() for a in insParams]: childErr.read() errResponse = None else: errResponse = childErr.read() childErr.close() finally: os.unlink(srcfilepath) if errResponse is not None and errResponse != "": appname = mbcsDec(self.EXAPPNAME, "replace")[0] errResponse = mbcsDec(errResponse, "replace")[0] return (_("%s Error: %s") % (appname, errResponse)), None return None, url
def createContent(self, exporter, exportType, insToken): """ Handle an insertion and create the appropriate content. exporter -- Exporter object calling the handler exportType -- string describing the export type insToken -- insertion token to create content for An insertion token has the following member variables: key: insertion key (unistring) value: value of an insertion (unistring) appendices: sequence of strings with the appendices Meaning and type of return value is solely defined by the type of the calling exporter. For HtmlExporter a unistring is returned with the HTML code to insert instead of the insertion. """ # Retrieve quoted content of the insertion bstr = lineendToOs(utf8Enc(insToken.value, "replace")[0]) # mbcsEnc if not bstr: # Nothing in, nothing out return u"" if self.extAppExe == "": # No path to MimeTeX executable -> show message return u"<pre>" + _(u"[Please set path to GraphViz executables]") + "</pre>" # Get exporters temporary file set (manages creation and deletion of # temporary files) tfs = exporter.getTempFileSet() pythonUrl = exportType != "html_previewWX" dstFullPath = tfs.createTempFile("", ".png", relativeTo="") url = tfs.getRelativeUrl(None, dstFullPath, pythonUrl=pythonUrl) # Store token content in a temporary file srcfilepath = createTempFile(bstr, ".dot") try: cmdline = subprocess.list2cmdline((self.extAppExe, "-Tpng", "-o" + dstFullPath, srcfilepath)) # Run external application # childIn, childOut, childErr = os.popen3(cmdline, "b") popenObject = subprocess.Popen( cmdline, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE ) childErr = popenObject.stderr # See http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error # why this is necessary popenObject.stdin.close() popenObject.stdout.close() if u"noerror" in [a.strip() for a in insToken.appendices]: childErr.read() errResponse = "" else: errResponse = childErr.read() childErr.close() finally: os.unlink(srcfilepath) if errResponse != "": appname = mbcsDec(self.EXAPPNAME, "replace")[0] errResponse = mbcsDec(errResponse, "replace")[0] return u"<pre>" + _(u"[%s Error: %s]") % (appname, errResponse) + u"</pre>" # Return appropriate HTML code for the image if exportType == "html_previewWX": # Workaround for internal HTML renderer return (u'<img src="%s" border="0" align="bottom" alt="formula" />' u" ") % url else: return u'<img src="%s" border="0" align="bottom" alt="formula" />' % url
def createContent(self, exporter, exportType, insToken): """ Handle an insertion and create the appropriate content. exporter -- Exporter object calling the handler exportType -- string describing the export type insToken -- insertion token to create content for An insertion token has the following member variables: key: insertion key (unistring) value: value of an insertion (unistring) appendices: sequence of strings with the appendices Meaning and type of return value is solely defined by the type of the calling exporter. For HtmlExporter a unistring is returned with the HTML code to insert instead of the insertion. """ if not insToken.value: # Nothing in, nothing out return "" if self.extAppExe == "": # No path to Gnuplot executable -> show message return '<pre>' + _('[Please set path to Gnuplot executable]') +\ '</pre>' # Get exporters temporary file set (manages creation and deletion of # temporary files) tfs = exporter.getTempFileSet() pythonUrl = (exportType != "html_previewWX") dstFullPath = tfs.createTempFile("", ".png", relativeTo="") url = tfs.getRelativeUrl(None, dstFullPath, pythonUrl=pythonUrl) baseDir = os.path.dirname( exporter.getMainControl().getWikiConfigPath()) # Prepend source code with appropriate settings for PNG output srcCode = ("set terminal png\nset output '%s'\n" % dstFullPath) + \ insToken.value # Retrieve quoted content of the insertion bstr = lineendToOs(mbcsEnc(srcCode, "replace")[0]) # Store token content in a temporary file srcfilepath = createTempFile(bstr, ".gpt") try: cmdline = subprocess.list2cmdline((self.extAppExe, srcfilepath)) # Run external application # childIn, childOut, childErr = os.popen3(cmdline, "b") popenObject = subprocess.Popen(cmdline, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) childErr = popenObject.stderr # See http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error # why this is necessary popenObject.stdin.close() popenObject.stdout.close() if "noerror" in [a.strip() for a in insToken.appendices]: childErr.read() errResponse = b"" else: errResponse = childErr.read() childErr.close() finally: os.unlink(srcfilepath) if errResponse != b"": errResponse = mbcsDec(errResponse, "replace")[0] return '<pre>' + _('[Gnuplot error: %s]') % errResponse +\ '</pre>' # Return appropriate HTML code for the image if exportType == "html_previewWX": # Workaround for internal HTML renderer return ('<img src="%s" border="0" align="bottom" alt="gnuplot" />' ' ') % url else: return '<img src="%s" border="0" align="bottom" alt="gnuplot" />' \ % url
def createContent(self, exporter, exportType, insToken): """ Handle an insertion and create the appropriate content. exporter -- Exporter object calling the handler exportType -- string describing the export type insToken -- insertion token to create content for An insertion token has the following member variables: key: insertion key (unistring) value: value of an insertion (unistring) appendices: sequence of strings with the appendices Meaning and type of return value is solely defined by the type of the calling exporter. For HtmlExporter a unistring is returned with the HTML code to insert instead of the insertion. """ if not insToken.value: # Nothing in, nothing out return u"" if self.extAppExe == "": # No path to Gnuplot executable -> show message return u'<pre>' + _(u'[Please set path to Gnuplot executable]') +\ u'</pre>' # Get exporters temporary file set (manages creation and deletion of # temporary files) tfs = exporter.getTempFileSet() pythonUrl = (exportType != "html_previewWX") dstFullPath = tfs.createTempFile("", ".png", relativeTo="") url = tfs.getRelativeUrl(None, dstFullPath, pythonUrl=pythonUrl) baseDir = os.path.dirname(exporter.getMainControl().getWikiConfigPath()) # Prepend source code with appropriate settings for PNG output srcCode = ("set terminal png\nset output '%s'\n" % dstFullPath) + \ insToken.value # Retrieve quoted content of the insertion bstr = lineendToOs(mbcsEnc(srcCode, "replace")[0]) # Store token content in a temporary file srcfilepath = createTempFile(bstr, ".gpt") try: cmdline = subprocess.list2cmdline((self.extAppExe, srcfilepath)) # Run external application # childIn, childOut, childErr = os.popen3(cmdline, "b") popenObject = subprocess.Popen(cmdline, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) childErr = popenObject.stderr # See http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error # why this is necessary popenObject.stdin.close() popenObject.stdout.close() if u"noerror" in [a.strip() for a in insToken.appendices]: childErr.read() errResponse = "" else: errResponse = childErr.read() childErr.close() finally: os.unlink(srcfilepath) if errResponse != "": errResponse = mbcsDec(errResponse, "replace")[0] return u'<pre>' + _(u'[Gnuplot error: %s]') % errResponse +\ u'</pre>' # Return appropriate HTML code for the image if exportType == "html_previewWX": # Workaround for internal HTML renderer return (u'<img src="%s" border="0" align="bottom" alt="gnuplot" />' u' ') % url else: return u'<img src="%s" border="0" align="bottom" alt="gnuplot" />' \ % url