PDA

View Full Version : Any way to ascertain the application path?



dan131m
April 6th, 2009, 01:39 PM
Is there any easy way to determine the directory that my running application is located in? I tried os.getcwd() but on the Mac that actually seems to be located inside the Boxee.app directory.

DPK
April 6th, 2009, 01:42 PM
Do you need to dynamically reference it? Would just calling app://app-name/path/to/etc work for the case required?

Need more details. :)

dan131m
April 6th, 2009, 02:42 PM
I want to add it to the python's system.path so that I can include a third-party python library. I don't think that would work (although I haven't actually tried it...)

DPK
April 6th, 2009, 06:44 PM
You don't have to append system.path. There's another way. Here's an example from my app/plugin endeavors utilizing a custom python library (common.py).


Say your main app's (my_plugin) python file is default.py and you want to include the common.py library, but it's located in your plugins resources/lib directory. Create a file called __init__.py with nothing in it at all.
Place that file in your resources sub-directory and another copy in your lib sub-directory.
Your directory structure should now look something like this:



my_plugin


resources


lib


__init__.py
common.py


__init__.py


default.py




Now open up default.py and somewhere at the top you are going to have to insert the following line to get access to your 3rd party library, common.py:


import resources.lib.common as common

You can now reference your 3rd party library using the handle common.* from within default.py. Where * is some arg/function.

junda
May 26th, 2009, 12:05 PM
i think for latest boxee, you only need to put .py into your app root folder, and import it in your code. I did this in my facebook photo app, you can look at the source for more details
http://forum.boxee.tv/showthread.php?t=9018

jurrabi
March 10th, 2010, 10:40 AM
Ok, maybe for imports that will solve the issue.

But I'm creating a plugin that read&stores files in the app directory (like images or application data).
as dan131m said I use os.getcwd() in XBMC to get the right path. But in Boxee this refers to the plugin directory.

Is there a way to get the application path?

Thanks in advance.

agentlame
March 10th, 2010, 11:46 AM
You'd be might be better off using Boxee's temp directory, if you don't need the content forever:


mc.GetTempDir()


However, you can use:



dir = mc.GetApp().GetAppMediaDir()
#or
dir = mc.GetApp().GetAppDir()