I use a module python from openerp named report_openoffice_helper (i'm not the author).
This module use uno bridge and file DocumentConverter.py modified, but I have this error when I try to connect to openoffice :
'NoneType' object has no attribute 'initialize'
in fact the error comes from this line :
self.inputStream.initialize((uno.ByteSequence(stdinBytes),))
in the original code DocumentConverter.py, this is :
inputStream.initialize((uno.ByteSequence(stdinBytes),)) and is in an other function than def __init__ like in modified code
see the modified code for class DocumentConverter:
Code: Select all
class DocumentConverter:
def __init__(self, stdinBytes, host='localhost', port=DEFAULT_OPENOFFICE_PORT):
self.localContext = uno.getComponentContext()
self.serviceManager = self.localContext.ServiceManager
resolver = self.serviceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.localContext)
try:
context = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
except IllegalArgumentException, exception:
raise DocumentConversionException, "The url is invalid (%s)" % exception
except NoConnectException, exception:
raise DocumentConversionException, "Failed to connect to OpenOffice.org on port %s. %s" % (port, exception)
except ConnectionSetupException, exception:
raise DocumentConversionException, "Not possible to accept on a local resource (%s)" % exception
self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
self.inputStream = self.serviceManager.createInstanceWithContext("com.sun.star.io.SequenceInputStream", self.localContext)
self.inputStream.initialize((uno.ByteSequence(stdinBytes),))
self.document = self.desktop.loadComponentFromURL('private:stream', "_blank", 0, self._toProperties(InputStream = self.inputStream))
Code: Select all
class DocumentConverter:
def __init__(self, port=DEFAULT_OPENOFFICE_PORT):
self.localContext = uno.getComponentContext()
self.serviceManager = self.localContext.ServiceManager
resolver = self.serviceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.localContext)
try:
context = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port)
except NoConnectException, exception:
raise Exception, "Failed to connect to OpenOffice.org on port %s. %s" % (port, exception)
self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
def convertByStream(self, stdinBytes, filterName="writer8"):
inputStream = self.serviceManager.createInstanceWithContext("com.sun.star.io.SequenceInputStream", self.localContext)
inputStream.initialize((uno.ByteSequence(stdinBytes),))
document = self.desktop.loadComponentFromURL('private:stream', "_blank", 0, self._toProperties(
InputStream=inputStream,
Hidden=False))
http://bazaar.launchpad.net/~report-ope ... nverter.py
complete original code :
http://www.oooforum.org/forum/viewtopic.phtml?t=109519
Thanks for help or ideas to solve my problem.
Bye