2008-09-08, 22:23
Hi Guys,
I am developing (at least trying ) XBMC scripts with a French community of users using XBMC some on Linux and some on XBOX (and recently some on windows).
We went few time through the problem of having python script for XBMC NOT compatible for both Linux/Mac and XBOX/Windows.
Hopefully we have found a solution which should be compatible with all the platforms: Linux/Mac and XBOX/Windows
I don't know it has been already a topic on this subject, so sorry if I repeat something but it is better to give this information again since it could be very useful for XBMC Script developers.
The main problem between the 2 platforms Linux/Mac and XBOX/windows is:
Here is an example of code to add to your script in order to find the current path of your script:
The other important thing is to only use the 'os.path.join' command instead of a combination of '+' and the os separtor '/' or '\\'.
And if you need to use this separator, it is better to use 'os.sep' instead.
Now an example of code of how to use those paths in order to remain compatible with all the platforms:
Those examples have been tested and work on both Linux/Xbox platforms.
I hope it will help. If every XBMC script developer could do script compatible script between platform it would be nice for the end user.
Right now we can see the issue with Linux users who try to use some script and it doesn't work because of issue on the format of the path used in the script, my guess is it is the same for Mac user too, and it would be a shame not to fix that on new scripts :o.
If you have a better way of writing thos code, please feel free to share with us. Thanks
I am developing (at least trying ) XBMC scripts with a French community of users using XBMC some on Linux and some on XBOX (and recently some on windows).
We went few time through the problem of having python script for XBMC NOT compatible for both Linux/Mac and XBOX/Windows.
Hopefully we have found a solution which should be compatible with all the platforms: Linux/Mac and XBOX/Windows
I don't know it has been already a topic on this subject, so sorry if I repeat something but it is better to give this information again since it could be very useful for XBMC Script developers.
The main problem between the 2 platforms Linux/Mac and XBOX/windows is:
- the format of the path,
- certain os command does NOT return the same result depending on the OS
Here is an example of code to add to your script in order to find the current path of your script:
Code:
############################################################################
# Get current working directory and update internal vars with it
############################################################################
# Set paths
if os.name=='posix':
# Linux case
ROOTDIR = os.path.abspath(os.curdir).replace(';','')
else:
# Xbox and Windows case
ROOTDIR = os.getcwd().replace(';','')
IMAGEDIR = os.path.join(ROOTDIR, "images")
CACHEDIR = os.path.join(ROOTDIR, "cache")
DOWNLOADDIR = os.path.join(ROOTDIR, "download")
The other important thing is to only use the 'os.path.join' command instead of a combination of '+' and the os separtor '/' or '\\'.
And if you need to use this separator, it is better to use 'os.sep' instead.
Now an example of code of how to use those paths in order to remain compatible with all the platforms:
Code:
os.remove(os.path.join(DOWNLOADDIR, filename))
Those examples have been tested and work on both Linux/Xbox platforms.
I hope it will help. If every XBMC script developer could do script compatible script between platform it would be nice for the end user.
Right now we can see the issue with Linux users who try to use some script and it doesn't work because of issue on the format of the path used in the script, my guess is it is the same for Mac user too, and it would be a shame not to fix that on new scripts :o.
If you have a better way of writing thos code, please feel free to share with us. Thanks