好吧,我测试了我的 jython 程序,它做了一些简洁的 [".xls"、".doc"、".rtf"、".tif"、".tiff"、".pdf" 文件] -> pdf(中间文件) -> 使用 Open Office 进行 tif(最终输出)转换。由于自动化方面的问题,我们离开了 MS Office。现在看来,我们已经击倒了许多与显示塞子错误相关的瓶子,只剩下一瓶。OO 会在一段时间后挂起。
它发生在你在代码中看到这一行 '<<<<<<<<<<<'
什么是我处理停滞不前的 Open Office 流程的正确方法。您能否提供有用的链接,并在出路时给我一个好的建议。
还有一个问题。
总结:
* 如何处理停滞的 Open Office 实例?
* 如何使用 java headless 进行转换,所以我不会一直弹出 GUI 浪费内存。
* 任何关于代码质量、优化和通用编码标准的一般性建议也将不胜感激。
Traceback(最里面的最后一个):
文件“dcmail.py”,第 184 行,在?
文件“dcmail.py”,第 174 行,主
文件“C:\DCMail\digestemails.py”,第 126 行,process_inbox
文件“C:\DCMail\digestemails.py”,第 258 行,_convert
文件“C: \DCMail\digestemails.py",第 284 行,在 _choose_conversion_type
文件中 "C:\DCMail\digestemails.py",第 287 行,在 _open_office_convert
文件中 "C:\DCMail\digestemails.py",第 299 行,在 _load_attachment_to_convert
com.sun .star.lang.DisposedException:
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDi spatcher.run(java_remote_bridge.java:176)处的 java.io.EOFException
com.sun.star.lang.DisposedException: com.sun.star.lang.DisposedException: java.i o.EOFException
只是为了清除此异常仅在我终止打开的办公室进程时引发。否则程序只是等待开放办公室完成。无限期
代码(带有非功能代码标签)
[代码]
#ghost script handles these file types GS_WHITELIST=[".pdf"] #Open Office handles these file types OO_WHITELIST=[".xls", ".doc", ".rtf", ".tif", ".tiff"] #whitelist is used to check against any unsupported files. WHITELIST=GS_WHITELIST + OO_WHITELIST
def _get_service_manager(self):
try:
self._context=Bootstrap.bootstrap();
self._xMultiCompFactory=self._context.getServiceManager()
self._xcomponentloader=UnoRuntime.queryInterface(XComponentLoader, self._xMultiCompFactory.createInstanceWithContext("com.sun.star.frame.Desktop", self._context))
except:
raise OpenOfficeException("Exception Occurred with Open Office")
def _choose_conversion_type(self,fn):
ext=os.path.splitext(fn)[1]
if ext in GS_WHITELIST:
self._ghostscript_convert_to_tiff(fn)
elif ext in OO_WHITELIST:
self._open_office_convert(fn)
def _open_office_convert(self,fn):
self._load_attachment_to_convert(fn)
self._save_as_pdf(fn)
self._ghostscript_convert_to_tiff(fn)
def _load_attachment_to_convert(self, file):
file=self._create_UNO_File_URL(file)
properties=[]
p=PropertyValue()
p.Name="Hidden"
p.Value=True
properties.append(p)
properties=tuple(properties)
self._doc=self._xcomponentloader.loadComponentFromURL(file, "_blank",0, properties) <<<<<<<<<<<<<<< here is line 299
def _create_UNO_File_URL(self, filepath):
try:
file=str("file:///" + filepath)
file=file.replace("\\", "/")
except MalformedURLException, e:
raise e
return file
def _save_as_pdf(self, docSource):
dirName=os.path.dirname(docSource)
baseName=os.path.basename(docSource)
baseName, ext=os.path.splitext(baseName)
dirTmpPdfConverted=os.path.join(dirName + DIR + PDF_TEMP_CONVERT_DIR)
if not os.path.exists(dirTmpPdfConverted):
os.makedirs(dirTmpPdfConverted)
pdfDest=os.path.join(dirTmpPdfConverted + DIR + baseName + ".pdf")
url_save=self._create_UNO_File_URL(pdfDest)
properties=self._create_properties(ext)
try:
try:
self._xstorable=UnoRuntime.queryInterface(XStorable, self._doc);
self._xstorable.storeToURL(url_save, properties)
except AttributeError,e:
self.logger.info("pdf file already created (" + str(e) + ")")
raise e
finally:
try:
self._doc.dispose()
except:
raise
def _create_properties(self,ext):
properties=[]
p=PropertyValue()
p.Name="Overwrite"
p.Value=True
properties.append(p)
p=PropertyValue()
p.Name="FilterName"
if ext==".doc":
p.Value='writer_pdf_Export'
elif ext==".rtf":
p.Value='writer_pdf_Export'
elif ext==".xls":
p.Value='calc_pdf_Export'
elif ext==".tif":
p.Value='draw_pdf_Export'
elif ext==".tiff":
p.Value='draw_pdf_Export'
properties.append(p)
return tuple(properties)
def _ghostscript_convert_to_tiff(self, docSource):
dest, source=self._get_dest_and_source_conversion_file(docSource)
try:
command = ' '.join([
self._ghostscriptPath + 'gswin32c.exe',
'-q',
'-dNOPAUSE',
'-dBATCH',
'-r500',
'-sDEVICE=tiffg4',
'-sPAPERSIZE=a4',
'-sOutputFile=%s %s' % (dest, source),
])
self._execute_ghostscript(command)
self.convertedTifDocList.append(dest)
except OSError, e:
self.logger.info(e)
raise e
except TypeError, (e):
raise e
except AttributeError, (e):
raise e
except:
raise
[/代码]