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
Temhil Offline
Skilled Python Coder
Posts: 395
Joined: Apr 2008
Reputation: 1
Location: Canada
Thumbs Up  FIXED in XBMC Beta1 Post: #11
Hi guys,

Sorry for coming back only now but since I don't have Linux box I wasn't able to generate logs for opening a bug.

Good news!
With MAC OS port I tried it and now it seems this issue has beem solved in XBMC Beta1 (probably before).
So now instead of doing a test on the OS, it just takes one line of code:
Code:
ROOTDIR = xbmc.translatePath( os.path.join( os.getcwd().replace( ";", "" )))
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #12
what are you joining?

PHP Code:
ROOTDIR os.getcwd() 
will suffice.

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
blittan Offline
Team-XBMC Handyman
Posts: 1,714
Joined: Jun 2004
Reputation: 11
Location: Sweden
Post: #13
for backwards compability, use os.getcwd().replace(';','')

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.
If you don't have the time to read them, please don't take the time to post in this forum!
For troubleshooting and bug reporting please make sure you read this first.
find quote
CrashX Offline
Posting Freak
Posts: 1,216
Joined: Jan 2009
Reputation: 2
Post: #14
Found this info quite usefull:-

http://xbmc.org/jmarshall/2009/02/10/cha...d-plugins/
find quote
CrashX Offline
Posting Freak
Posts: 1,216
Joined: Jan 2009
Reputation: 2
Post: #15
Linux is case sensitive. Hence default.py and default.tbn is not the same as Default.py and Default.tbn. This will actually cause the plugin not to load on linux but will work fine on windows. http://forum.xbmc.org/showthread.php?tid=45547
find quote
BigBellyBilly Offline
Skilled Python Coder
Posts: 959
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,914
Joined: Dec 2004
Reputation: 17
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: 959
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: -10
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
Post Reply