OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved][PyUno] Getting the file path of the extension

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Tue Mar 20, 2012 8:38 am    Post subject: [Solved][PyUno] Getting the file path of the extension Reply with quote

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 Smile


Last edited by ishanthilina on Mon Mar 26, 2012 9:40 am; edited 1 time in total
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Tue Mar 20, 2012 9:37 am    Post subject: Reply with quote

Try: http://api.libreoffice.org/docs/common/ref/com/sun/star/deployment/PackageInformationProvider.html
Back to top
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Tue Mar 20, 2012 10:49 am    Post subject: [PyUno] accessing the extensions directory Reply with quote

Quote:
Try: http://api.libreoffice.org/docs/common/ref/com/sun/star/deployment/PackageInformationProvider.html


Hi Hanya, thank you again for the great help you are always extending towards me Smile.

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..? Confused
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Tue Mar 20, 2012 11:17 am    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Tue Mar 20, 2012 6:09 pm    Post subject: Reply with quote

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 Confused .

Even when I use the getExtensionList method, noting is returned Confused

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...! Very Happy
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Tue Mar 20, 2012 9:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
SuneOskar
General User
General User


Joined: 24 Aug 2010
Posts: 8

PostPosted: Thu Mar 22, 2012 5:09 am    Post subject: Reply with quote

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
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Thu Mar 22, 2012 7:05 am    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Mon Mar 26, 2012 9:38 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Tue Mar 27, 2012 11:28 am    Post subject: Reply with quote

Hi, SuneOskar
I uses the following script to see standard output on windows environment:
http://hermione.s41.xrea.com/pukiwiki/index.php?OOoPython%2Fmytools%2Fsstdout
Back to top
View user's profile Send private message
SuneOskar
General User
General User


Joined: 24 Aug 2010
Posts: 8

PostPosted: Mon Apr 02, 2012 8:31 am    Post subject: The Python print command Reply with quote

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
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Mon Apr 02, 2012 10:06 am    Post subject: Reply with quote

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
View user's profile Send private message
SuneOskar
General User
General User


Joined: 24 Aug 2010
Posts: 8

PostPosted: Sun Apr 08, 2012 8:23 am    Post subject: Reply with quote

Hi Hanya,
Thanks for the code. Just what I needed!
Back to top
View user's profile Send private message
SuneOskar
General User
General User


Joined: 24 Aug 2010
Posts: 8

PostPosted: Sun Apr 08, 2012 11:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group