def callLibreOffice(self, resultName, resultType): '''Call LibreOffice in server mode to convert or update the result.''' loOutput = '' try: if (not isinstance(self.ooPort, int)) and \ (not isinstance(self.ooPort, int)): raise PodError(BAD_OO_PORT % str(self.ooPort)) try: from appy.pod.converter import Converter, ConverterError try: Converter(resultName, resultType, self.ooPort, self.stylesTemplate).run() except ConverterError as ce: raise PodError(CONVERT_ERROR % str(ce)) except ImportError: # I do not have UNO. So try to launch a UNO-enabled Python # interpreter which should be in self.pyPath. if not self.pyPath: raise PodError(NO_PY_PATH % resultType) if self.pyPath.find(' ') != -1: raise PodError(BLANKS_IN_PATH % self.pyPath) if not os.path.isfile(self.pyPath): raise PodError(PY_PATH_NOT_FILE % self.pyPath) if resultName.find(' ') != -1: qResultName = '"%s"' % resultName else: qResultName = resultName convScript = '%s/converter.py' % \ os.path.dirname(appy.pod.__file__) if convScript.find(' ') != -1: convScript = '"%s"' % convScript cmd = '%s %s %s %s -p%d' % \ (self.pyPath, convScript, qResultName, resultType, self.ooPort) if self.stylesTemplate: cmd += ' -t%s' % self.stylesTemplate loOutput = executeCommand(cmd) except PodError as pe: # When trying to call LO in server mode for producing ODT or ODS # (=forceOoCall=True), if an error occurs we have nevertheless # an ODT or ODS to return to the user. So we produce a warning # instead of raising an error. if (resultType in self.templateTypes) and self.forceOoCall: print((WARNING_INCOMPLETE_OD % str(pe))) else: raise pe return loOutput
def callLibreOffice(self, resultName, resultType): '''Call LibreOffice in server mode to convert or update the result''' loOutput = '' try: if (not isinstance(self.ooPort, int)) and \ (not isinstance(self.ooPort, long)): raise PodError(BAD_OO_PORT % str(self.ooPort)) try: from appy.pod.converter import Converter, ConverterError try: Converter(resultName, resultType, self.ooPort, self.stylesTemplate, self.optimalColumnWidths, self.script).run() except ConverterError as ce: raise PodError(CONVERT_ERROR % str(ce)) except ImportError: # I do not have UNO. So try to launch a UNO-enabled Python # interpreter which should be in self.pyPath. if not self.pyPath: raise PodError(NO_PY_PATH % resultType) if not os.path.isfile(self.pyPath): raise PodError(PY_PATH_NOT_FILE % self.pyPath) convScript = '%s/converter.py' % \ os.path.dirname(appy.pod.__file__) cmd = [self.pyPath, convScript, resultName, resultType, '-p%d' % self.ooPort] if self.stylesTemplate: cmd.append('-t%s' % self.stylesTemplate) if self.optimalColumnWidths: cmd.append('-o') cmd.append('%s' % str(self.optimalColumnWidths)) if self.script: cmd.append('-s') cmd.append('%s' % self.script) out, loOutput = utils.executeCommand(cmd) except PodError as pe: # When trying to call LO in server mode for producing ODT or ODS # (=forceOoCall=True), if an error occurs we have nevertheless # an ODT or ODS to return to the user. So we produce a warning # instead of raising an error. if (resultType in self.templateTypes) and self.forceOoCall: print(WARNING_INCOMPLETE_OD % str(pe)) else: raise pe return loOutput
def callOpenOffice(self, resultOdtName, resultType): '''Call Open Office in server mode to convert or update the ODT result.''' ooOutput = '' try: if (not isinstance(self.ooPort, int)) and \ (not isinstance(self.ooPort, long)): raise PodError(BAD_OO_PORT % str(self.ooPort)) try: from appy.pod.converter import Converter, ConverterError try: Converter(resultOdtName, resultType, self.ooPort).run() except ConverterError, ce: raise PodError(CONVERT_ERROR % str(ce)) except ImportError: # I do not have UNO. So try to launch a UNO-enabled Python # interpreter which should be in self.pyPath. if not self.pyPath: raise PodError(NO_PY_PATH % resultType) if self.pyPath.find(' ') != -1: raise PodError(BLANKS_IN_PATH % self.pyPath) if not os.path.isfile(self.pyPath): raise PodError(PY_PATH_NOT_FILE % self.pyPath) if resultOdtName.find(' ') != -1: qResultOdtName = '"%s"' % resultOdtName else: qResultOdtName = resultOdtName convScript = '%s/converter.py' % \ os.path.dirname(appy.pod.__file__) if convScript.find(' ') != -1: convScript = '"%s"' % convScript cmd = '%s %s %s %s -p%d' % \ (self.pyPath, convScript, qResultOdtName, resultType, self.ooPort) ooOutput = executeCommand(cmd) except PodError, pe: # When trying to call OO in server mode for producing # ODT (=forceOoCall=True), if an error occurs we still # have an ODT to return to the user. So we produce a # warning instead of raising an error. if (resultType == 'odt') and self.forceOoCall: print WARNING_INCOMPLETE_ODT % str(pe) else: raise pe