open document from script
Closed this issue · 2 comments
hello! i'm trying to open document from script, which starts with:
import pyoo, os os.system("gnome-terminal -e 'bash -c soffice --accept=\"socket,host=localhost,port=2002;urp;\" --norestore --nologo --nodefault'") desktop = pyoo.Desktop('localhost', 2002) doc = desktop.open_spreadsheet("/home/kirill_krokodil/test.ods") sheet = doc.sheets[0] ...
but getting errror:
`com.sun.star.connection.NoConnectExceptionTraceback (most recent call last)
/usr/lib/python3.5/site-packages/pyoo.py in _get_remote_context(resolver, url)
1799 try:
-> 1800 return resolver.resolve(url)
1801 except _NoConnectException:
com.sun.star.connection.NoConnectException: Connector : couldn't connect to socket (Success)
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
in ()
7 os.system("gnome-terminal -e 'bash -c soffice --accept="socket,host=localhost,port=2002;urp;" --norestore --nologo --nodefault'")
8
----> 9 desktop = pyoo.Desktop('localhost', 2002)
10 doc = desktop.open_spreadsheet("/home/kirill_krokodil/test.ods")
/usr/lib/python3.5/site-packages/pyoo.py in init(self, hostname, port, pipe)
1818 local_context = uno.getComponentContext()
1819 resolver = local_context.getServiceManager().createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', local_context)
-> 1820 remote_context = _get_remote_context(resolver, url)
1821 desktop = remote_context.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", remote_context)
1822 super(Desktop, self).init(desktop)
/usr/lib/python3.5/site-packages/pyoo.py in _get_remote_context(resolver, url)
1800 return resolver.resolve(url)
1801 except _NoConnectException:
-> 1802 raise IOError(resolver, url)
1803
1804 class Desktop(_UnoProxy):
OSError: [Errno pyuno object (com.sun.star.uno.XInterface)0x7f1091eb1258{implementationName=com.sun.star.comp.bridge.UnoUrlResolver, supportedServices={com.sun.star.bridge.UnoUrlResolver}, supportedInterfaces={com.sun.star.lang.XServiceInfo,com.sun.star.bridge.XUnoUrlResolver,com.sun.star.lang.XTypeProvider,com.sun.star.uno.XWeak}}] uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext`
so, the problem, as i see it, that mechanism for opening document from console (which works fine), does not work while inside script. or maybe i'm just using it wrong way.
I do not see any obvious problem with your code. Few random tips:
- Try to use
subprocess.Popen
instead ofos.system
. You can check return code and get PID. - Get rid of
gnome-terminal
andbash
in your command line. You can call directly soffice binary. - Examine process list if OpenOffice is running.
- Use a named pipe instead of a socket. You should see the pipe in
/tmp
directory (if I remember correctly) - Wait for a while after starting the OpenOffice. It can take few seconds before it starts to accept connections. This is my best guess:)
Anyway this does not look like a problem with the PyOO itself so I'm closing this issue.
OK, Miloslav, thank you!
But what am i trying to say is that my scenario of using PyOO looks like pretty obvious and useful. And i'm not very good at linux stuff (pipes, sockets etc). So if someone else (like me, not very good at linux) will try to use PyOO inside script, he may encounter the same problem. It would be great if such scenario was in readme of your project.
Any way thank you for project and answers.