os.getcwd returns path to user home directory, not script directory (svn22528)
#1
hi

original post here: http://www.xbmc.org/forum/showthread.php?t=59177

case in point - SVN Repo Installer:

Code:
10:35:20 T:3048277840 M:3383496704   DEBUG: LIRC: Update - NEW at 807143:0200002800000201 00 KEY_ENTER Antec_Veris_RM200 (KEY_ENTER)
10:35:21 T:3022416784 M:3383545856   DEBUG: webs: accept request
10:35:21 T:3048277840 M:3383545856   DEBUG: OnKey: 11 pressed, action is 7
10:35:21 T:3048277840 M:3383545856   DEBUG: Clearing cached fileitems [plugin://programs/SVN_Repo_Installer/]
10:35:21 T:3048277840 M:3383545856   DEBUG: CGUIMediaWindow::GetDirectory (plugin://programs/SVN_Repo_Installer/)
10:35:21 T:3048277840 M:3383545856   DEBUG:   ParentPath = [plugin://programs/]
10:35:21 T:3048277840 M:3383545856   DEBUG: StartScript - URL for plugin settings: SVN_Repo_Installer/
10:35:21 T:3048277840 M:3383545856   DEBUG: StartScript - calling plugin special://home/plugins/programs/SVN_Repo_Installer/default.py('plugin://programs/SVN_Repo_Installer/','0','')
10:35:21 T:3048277840 M:3383545856    INFO: initializing python engine.
10:35:21 T:3048277840 M:3383545856   DEBUG: Loading: /usr/share/xbmc/system/python/python25-i486-linux.so
10:35:21 T:3048277840 M:3383545856   DEBUG: Python wrapper library linked with system Python library
10:35:21 T:3048277840 M:3383545856   DEBUG: new python thread created. id=4
10:35:21 T:2995768208 M:3383545856   DEBUG: thread start, auto delete: 0
10:35:21 T:2995768208 M:3383545856   DEBUG: Python thread: start processing
10:35:21 T:2995768208 M:3383545856  NOTICE: -->Python Interpreter Initialized<--
10:35:21 T:2995768208 M:3383545856   DEBUG: Process - The source file to load is special://home/plugins/programs/SVN_Repo_Installer/default.py
10:35:21 T:2995768208 M:3383545856   DEBUG: Process - Setting the Python path to /secure/home/media/.xbmc/plugins/programs/SVN_Repo_Installer:/usr/lib/python25.zip:/usr/lib/python2.5/:/usr/lib/python2.5/plat-linux2:/usr/lib/python2.5/lib-tk:/usr/lib/python2.5/lib-dynload
10:35:21 T:2995768208 M:3383545856   DEBUG: Process - Entering source directory /secure/home/media/.xbmc/plugins/programs/SVN_Repo_Installer
10:35:21 T:2995768208 M:3383545856  NOTICE: [PLUGIN] 'SVN Repo Installer: Version - 1.8.2a-r1335' initialized!
10:35:21 T:2995768208 M:3383545856  NOTICE:      ** Required XBMC Revision: r19001 **
10:35:21 T:2995768208 M:3383545856  NOTICE:      ** Found XBMC Revision: r0 [Unknown] **
10:35:21 T:2995768208 M:3383545856   DEBUG: [SVN Repo Installer]: Module: installerAPI.xbmcplugin_lib Dated: 24-06-2009 loaded!
10:35:21 T:2995768208 M:3383545856   DEBUG: [SVN Repo Installer]: Module: installerAPI.xbmcplugin_list Dated: 24-06-2009 loaded!
10:35:21 T:2995768208 M:3383545856   DEBUG: [SVN Repo Installer]: installerAPI.xbmcplugin_list.Main init!
10:35:21 T:2995768208 M:3383545856   DEBUG: [SVN Repo Installer]: Info() dict={'title': ''}
10:35:21 T:2995768208 M:3383545856   DEBUG: [SVN Repo Installer]: ERROR: _get_repos (127) - [Errno 2] No such file or directory: '/secure/home/media/resources/repositories'
10:35:21 T:2995768208 M:3383545856    INFO: Scriptresult: Success
10:35:21 T:3048277840 M:3383545856   DEBUG: WaitOnScriptResult - waiting on the SVN_Repo_Installer plugin...
10:35:21 T:3048277840 M:3383545856   DEBUG: WaitOnScriptResult- plugin returned failure
10:35:21 T:3048277840 M:3383545856   ERROR: GetDirectory - Error getting plugin://programs/SVN_Repo_Installer/
10:35:21 T:3048277840 M:3383545856   ERROR: CGUIMediaWindow::GetDirectory(plugin://programs/SVN_Repo_Installer/) failed
10:35:21 T:3048277840 M:3383545856   DEBUG: CGUIMediaWindow::GetDirectory (plugin://programs/)
10:35:21 T:3048277840 M:3383545856   DEBUG:   ParentPath = []
10:35:21 T:3048277840 M:3383545856   DEBUG: Sort, sorting took 0 millis
10:35:21 T:2900319120 M:3383545856   DEBUG: thread start, auto delete: 0
10:35:21 T:2900319120 M:3383545856   DEBUG: Thread 2900319120 terminating
xbmc-pvr-ppa-odk68, Gentoo x86 3.0.7-pf, xorg-server-1.11.2, mesa-7.11, nvidia-drivers-290.10
Reply
#2
Please post a ticket on trac. I suspect it will affect only linux/OS X.

Not sure the best approach to fix it at this point.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
http://trac.xbmc.org/ticket/7291
xbmc-pvr-ppa-odk68, Gentoo x86 3.0.7-pf, xorg-server-1.11.2, mesa-7.11, nvidia-drivers-290.10
Reply
#4
This problem seems to be fixed with the latest SVN version of the SVN repo installer. Or at least worked around.

Judging by the bug report, you probably don't need me to tell you how to check it out, but the next guy googling might Smile

Code:
cd ~/.xbmc/plugins/programs
svn co http://xbmc-addons.googlecode.com/svn/trunk/plugins/programs/SVN%20Repo%20Installer/

Had the same problem as you using every other version of the repo installer. This works like a charm on Karmic x64.
Reply
#5
Cerinthus Wrote:This problem seems to be fixed with the latest SVN version of the SVN repo installer. Or at least worked around.

Judging by the bug report, you probably don't need me to tell you how to check it out, but the next guy googling might Smile

Code:
cd ~/.xbmc/plugins/programs
svn co http://xbmc-addons.googlecode.com/svn/trunk/plugins/programs/SVN%20Repo%20Installer/

Had the same problem as you using every other version of the repo installer. This works like a charm on Karmic x64.

the answer is in: do NOT link with external python.

http://trac.xbmc.org/ticket/7291

perhaps someone could mark this with [SOLVED].
xbmc-pvr-ppa-odk68, Gentoo x86 3.0.7-pf, xorg-server-1.11.2, mesa-7.11, nvidia-drivers-290.10
Reply
#6
lkraav Wrote:the answer is in: do NOT link with external python.

http://trac.xbmc.org/ticket/7291

perhaps someone could mark this with [SOLVED].

That's hardly a solution... I thought we were moving towards more external libs, not less...

Perhaps xbmc should provide a 'better' function that resembles / imitates the behavior we DO need.
Reply
#7
Po0ky Wrote:That's hardly a solution... I thought we were moving towards more external libs, not less...

Perhaps xbmc should provide a 'better' function that resembles / imitates the behavior we DO need.

sure, but that is something for trac tickets to handle, in my opinion.
xbmc-pvr-ppa-odk68, Gentoo x86 3.0.7-pf, xorg-server-1.11.2, mesa-7.11, nvidia-drivers-290.10
Reply
#8
This is the intended behavior of os.getcwd(). It returns the path of the directory the python interpreter was started from, in this case, the path to XBMC.

The same thing would happen on windows if we used external python there, too.

The solution is to set a plugin constant to os.path.dirname(sys.argv[0]) or os.path.dirname(__file__) or use the inspect module, or to call os.path.dirname(sys.argv[0]) each time you want the path to your plugin.

IMO something like __base_dir__ = os.path.dirname(sys.argv[0]); BASE_DIR = sys.modules["__main__"].__base_dir__ is the most attractive and readable way of doing things.

Your alternatives:
PHP Code:
#default.py
import sys
import os
import inspect

#plugin constants
__plugin__ 'Test'
__base_dir1__ os.path.dirname(sys.argv[0])
__base_dir2__ os.path.dirname(__file__)


if 
__name__ == '__main__':
    print 
'\n\ndefault.py'
    
print 'os.getcwd():'os.getcwd()
    print 
'sys.argv[0]:'sys.argv[0]
    print 
'__file__:'__file__
    
print 'inspect.currentframe().f_code.co_filename'inspect.currentframe().f_code.co_filename


    import resources
.lib.bar 

PHP Code:
#bar.py
import sys
import os
import inspect

print '\n\nBAR.PY'
print 'os.getcwd():'os.getcwd()
print 
'sys.argv[0]:'sys.argv[0]
print 
'__file__:'__file__
print 'inspect.currentframe().f_code.co_filename'inspect.currentframe().f_code.co_filename
print ''
print 'Getting the Head Directory of your Addon from bar.py:'
print 'os.path.dirname(sys.argv[0])'os.path.dirname(sys.argv[0])
print 
'sys.modules["__main__"].__base_dir1__'sys.modules['__main__'].__base_dir1__
print 'sys.modules["__main__"].__base_dir2__'sys.modules['__main__'].__base_dir2__ 
Quote:#output
07:31:52 T:2264 M:1117196288 NOTICE: -->Python Interpreter Initialized<--
07:31:52 T:2264 M:1116581888 NOTICE:

default.py
07:31:52 T:2264 M:1116581888 NOTICE: os.getcwd():
07:31:52 T:2264 M:1116581888 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo
07:31:52 T:2264 M:1116581888 NOTICE: sys.argv[0]:
07:31:52 T:2264 M:1116581888 NOTICE: plugin://video/foo/
07:31:52 T:2264 M:1116581888 NOTICE: __file__:
07:31:52 T:2264 M:1116581888 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo\default.py
07:31:52 T:2264 M:1116581888 NOTICE: inspect.currentframe().f_code.co_filename
07:31:52 T:2264 M:1116581888 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo\default.py
07:31:53 T:2264 M:1116971008 NOTICE:

BAR.PY
07:31:53 T:2264 M:1116971008 NOTICE: os.getcwd():
07:31:53 T:2264 M:1116971008 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo
07:31:53 T:2264 M:1116971008 NOTICE: sys.argv[0]:
07:31:53 T:2264 M:1116971008 NOTICE: plugin://video/foo/
07:31:53 T:2264 M:1116971008 NOTICE: __file__:
07:31:53 T:2264 M:1116971008 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo\resources\lib\bar.py
07:31:53 T:2264 M:1116971008 NOTICE: inspect.currentframe().f_code.co_filename
07:31:53 T:2264 M:1116971008 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo\resources\lib\bar.py
07:31:53 T:2264 M:1116971008 NOTICE: Getting the Head Directory of your Addon from bar.py:
07:31:53 T:2264 M:1116971008 NOTICE: os.path.dirname(sys.argv[0])
07:31:53 T:2264 M:1116971008 NOTICE: plugin://video/foo
07:31:53 T:2264 M:1116971008 NOTICE: sys.modules["__main__"].__base_dir1__
07:31:53 T:2264 M:1116971008 NOTICE: plugin://video/foo
07:31:53 T:2264 M:1116971008 NOTICE: sys.modules["__main__"].__base_dir2__
07:31:53 T:2264 M:1116971008 NOTICE: C:\Documents and Settings\Owner\Application Data\XBMC\plugins\video\foo
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply

Logout Mark Read Team Forum Stats Members Help
os.getcwd returns path to user home directory, not script directory (svn22528)0