| View previous topic :: View next topic |
| Author |
Message |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Tue Mar 20, 2012 8:38 am Post subject: [Solved][PyUno] Getting the file path of the extension |
|
|
When a python extension is added to libreoffice, the files for that extension are located in a arbitrarily named folder in /home/<user_name>/.libreoffice/3/user/uno_packages/cache/uno_packages . Is there anyway the script(extension) to find out the file path where the extension is installed...?
As an example if the extension is in a folder named lucio2yk.tmp_, the script should be able to find out that the full file path for it self is /home/<user_name>/.libreoffice/3/user/uno_packages/cache/uno_packages/lucio2yk.tmp_/6.zip/6.
Any help is highly appreciated 
Last edited by ishanthilina on Mon Mar 26, 2012 9:40 am; edited 1 time in total |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Tue Mar 20, 2012 10:49 am Post subject: [PyUno] accessing the extensions directory |
|
|
Hi Hanya, thank you again for the great help you are always extending towards me .
As you already know, I'm a newbie to Libreoffice. I wrote the following code.
self.ctx is setup by the code above in the class.
| Code: | pir = self.ctx.getValueByName(
"/singletons/com.sun.star.deployment.PackageInformationProvider" )
expath=pir.getExtensionList()
|
Till that point everything seems to be working. But the execution doesnt happen of the next line
| Code: | | text.insertString( cursor, type(expath), 0 ) |
or
| Code: | for exts in expath:
text.insertString( cursor, exts, 0 )
text.insertString( cursor, "\n", 0 ) |
But the interface XPackageInformationProvider ( http://api.libreoffice.org/docs/common/ref/com/sun/star/deployment/XPackageInformationProvider.html#getExtensionList ) clearly specifies that XPackageInformationProvider has a method named getExtensionList() which returns list.
What could be the reason for this weird problem..?  |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Tue Mar 20, 2012 11:17 am Post subject: |
|
|
Why don't you use getPackageLocation method? getExtensionList method returns tuple of tuple in Python.
It seems you are working on Linux or UNIX environment, you can see standard output on such system. Start your office in terminal and then you can use print function of Python. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Tue Mar 20, 2012 6:09 pm Post subject: |
|
|
Hi Hanya,
| hanya wrote: | | Why don't you use getPackageLocation method? getExtensionList method returns tuple of tuple in Python. |
I used that method because that method doesn't need any parameters. getPackageLocation method needs the id of the extension,which I don't know how to find at the moment .
Even when I use the getExtensionList method, noting is returned
Could it be because I'm not instantiating the singleton class properly...?
| hanya wrote: |
It seems you are working on Linux or UNIX environment, you can see standard output on such system. Start your office in terminal and then you can use print function of Python. |
Thanks for the tip...!  |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Tue Mar 20, 2012 9:40 pm Post subject: |
|
|
Hi,
| Code: | def vsp(*args):
ctx = XSCRIPTCONTEXT.getComponentContext()
pir = ctx.getValueByName(
"/singletons/com.sun.star.deployment.PackageInformationProvider" )
expath=pir.getExtensionList()
print(expath) | This code shows me the following: | Code: | ((u'mytools.bookmarks.BookmarksMenu', u'1.0.0'),
(u'mytools.BookmarksMenu', u'0.6.2'), (u'mytools.bookmarks.BookmarksMenu.30ed1f7', u'1.0.0'),
(u'mytools.search.IncrementalSearch', u'0.1.0'),
(u'mytools.mri', u'1.1.0'),
(u'mytools.test.Mri', u'1.0.0')) |
The extension identifier used by getPackageLocation method is defined by identifier element in description.xml file of OXT package. See: http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Extensions/Example |
|
| Back to top |
|
 |
SuneOskar General User

Joined: 24 Aug 2010 Posts: 8
|
Posted: Thu Mar 22, 2012 5:09 am Post subject: |
|
|
Hanya,
I'm interestded in what you you are saying about the print function. I've opened office
by means of open -a LbreOffice.app and runned a macro placed in My Macros and with a print ("something") in it. However nothing is printed on the Terminal!
More to set up? I'm using OS X 10.7.3 |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Thu Mar 22, 2012 7:05 am Post subject: |
|
|
Hi, SuneOskar
I am sorry, I can not say anything about the office on MacOS X. Maybe there is someone can make answer for you. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Mon Mar 26, 2012 9:38 am Post subject: |
|
|
| hanya wrote: | Hi,
| Code: | def vsp(*args):
ctx = XSCRIPTCONTEXT.getComponentContext()
pir = ctx.getValueByName(
"/singletons/com.sun.star.deployment.PackageInformationProvider" )
expath=pir.getExtensionList()
print(expath) | This code shows me the following: | Code: | ((u'mytools.bookmarks.BookmarksMenu', u'1.0.0'),
(u'mytools.BookmarksMenu', u'0.6.2'), (u'mytools.bookmarks.BookmarksMenu.30ed1f7', u'1.0.0'),
(u'mytools.search.IncrementalSearch', u'0.1.0'),
(u'mytools.mri', u'1.1.0'),
(u'mytools.test.Mri', u'1.0.0')) |
The extension identifier used by getPackageLocation method is defined by identifier element in description.xml file of OXT package. See: http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Extensions/Example |
Thank you hanya. The method you showed worked for me. Thanks  |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
|
| Back to top |
|
 |
SuneOskar General User

Joined: 24 Aug 2010 Posts: 8
|
Posted: Mon Apr 02, 2012 8:31 am Post subject: The Python print command |
|
|
Hi Hanya,
Thanks for your code. However, I haven' t got a working PC.
My old one with XP hangs up when I try to start it. I tried to fix it but have given it up.
But could you please describe how you do it in Linux o Unix with a simple
office macro with a python print command (statement ??) in it.
I would very much apprecciate that. |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Mon Apr 02, 2012 10:06 am Post subject: |
|
|
Hi SuneOskar,
sys.stdout of Python is the reference to the output stream, maybe it writes something to a file or show it on a console. It can be replaced with an instance which has write method takes one argument as string to output.
On UNIX like environment, I can see the output to the console from Python when I start the office in the terminal. But Windows like environment does not provide such output.
This kind of toy helps me to see output directly on such silly environment. Read end of the code for how to use it.
| Code: |
import sys
import unohelper
from com.sun.star.util import XCloseListener
class WriterAsOutput(unohelper.Base, XCloseListener):
""" Toy of alternative output window.
If you change default font of standard paragraph style to
mono type and change mode to print layout, you can get
much better look.
"""
Out = None
def __init__(self):
self.doc = None
self._stdout = None
self._stderr = None
def disposing(self, ev): pass
def queryClosing(self, ev, ownership): pass
def notifyClosing(self, ev):
self.end()
def create_doc(self, ctx):
desktop = ctx.getServiceManager().createInstanceWithContext(
"com.sun.star.frame.Desktop", ctx)
return desktop.loadComponentFromURL(
"private:factory/swriter", "_blank", 0, ())
def start(self, ctx):
if self.__class__.Out is None:
self.doc = self.create_doc(ctx)
self.doc.addCloseListener(self)
self.__class__.Out = self
self._stdout = sys.stdout
self._stderr = sys.stderr
sys.stdout = self
sys.stderr = self
def end():
klass = WriterAsOutput
if not klass.Out is None:
i = klass.Out
i.doc = None
sys.stdout = i._stdout
sys.stderr = i._stderr
klass.Out = None
else:
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
end = staticmethod(end)
def _write(self, s):
if self.doc:
self.doc.getText().getEnd().setString(s)
def write(self, s):
self._write(s)
def start_output(*args):
""" Open writer document as output window. """
WriterAsOutput().start(XSCRIPTCONTEXT.getComponentContext())
def close_output(*args):
""" End to use the document as output window. """
WriterAsOutput.end()
|
|
|
| Back to top |
|
 |
SuneOskar General User

Joined: 24 Aug 2010 Posts: 8
|
Posted: Sun Apr 08, 2012 8:23 am Post subject: |
|
|
Hi Hanya,
Thanks for the code. Just what I needed! |
|
| Back to top |
|
 |
SuneOskar General User

Joined: 24 Aug 2010 Posts: 8
|
Posted: Sun Apr 08, 2012 11:07 pm Post subject: |
|
|
Hanya wrote: | Quote: | | On UNIX like environment, I can see the output to the console from Python when I start the office in the terminal. But Windows like environment does not provide such output. |
It works for Mac OS X too if you start office from python in the Terminal.
For start i used:
| Code: | import subprocess
subprocess.call( [ '/applications/LibreOffice.app/Contents/MacOS/soffice.bin', '-scalc' ]) |
I didn't know how to start it from python but have been taught now.
Thanks Hanya for your interest and kindness. |
|
| Back to top |
|
 |
|