Tips for coding python scripts / plugins compatible with Linux, Mac, Windows AND Xbox

  Thread Rating:
  • 2 Votes - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
BigBellyBilly Offline
Skilled Python Coder
Posts: 900
Joined: Feb 2005
Reputation: 2
Location: UK
Post: #16
using os.getcwd() in conjunction with the recommended url style path divider '/' creates a path with mixed dividers.

ie.

DIR_HOME = os.getcwd().replace( ";", "" )
DIR_RESOURCES_LIB = "/".join( [DIR_HOME, "resources", "lib"] )
sys.path.insert(0, xbmc.translatePath(DIR_RESOURCES_LIB) )

gives

C:\Program Files\XBMC\scripts\<scriptname>/resources/lib

which is ugly, but it still works on win32 and xbox (don't know about others)
HOME_DIR is only really used as a base for relative subdirs and it doesnt upset
translatePath() but any recommendations to get a path all using the same divider ?

Note:: xbmc.Language( DIR_HOME ) which appends 'resources' must produce:
C:\Program Files\XBMC\scripts\<scriptname>/resources/

Is this likely to be a future problem ?

BBB

My Addons (myTV, T3CH Upgrader, DVDProfiler, BBCPodRadio, Comics, Football, GoogleReader, reeplay.it, Metacritic, Phonebin, FileViewer,SVN Repo Installer (contributor)) available at Box.net
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,910
Joined: Dec 2004
Reputation: 18
Post: #17
BBB, do NOT use "/".join() for an actual path.

you use os.cwd() to get the actual current directory, so use os.path.join()

only use "/".join() when you start with a url eg "special://home/"

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
(This post was last modified: 2009-02-17 15:59 by Nuka1195.)
find quote
BigBellyBilly Offline
Skilled Python Coder
Posts: 900
Joined: Feb 2005
Reputation: 2
Location: UK
Post: #18
ok. will do.

Would a special:// that relates to current location ( as found with os.getcwd() ) be a useful one to have too ?

My Addons (myTV, T3CH Upgrader, DVDProfiler, BBCPodRadio, Comics, Football, GoogleReader, reeplay.it, Metacritic, Phonebin, FileViewer,SVN Repo Installer (contributor)) available at Box.net
find quote
plex Offline
Senior Member
Posts: 107
Joined: Mar 2008
Reputation: 0
Post: #19
Doesn't xbmc python support SYS module
os.getcwd() doesnt always give current directory of script, it depends where the script is RUN from... even on windows or linux..

Try os.path.dirname( sys.argv[0] )

Spread the knowledge, nothing else.[Image: b.gif]
find quote
Filipe Mauro Offline
Junior Member
Posts: 4
Joined: Sep 2013
Reputation: 0
Post: #20
Hi, my name is Filipe, and i need some helps. Im new on XBMC development, and i dont now where can i find material to learn how to use python on XBMC.
I need do some modifications in the pythons code. Someone can help me?

Att,
find quote
Post Reply