How to properly detect the underlying OS inside of XBMC python?
This should in principle be easy enough, but it's not working as expected for me.

Some background - I need to know which OS my addon is running on as it supplies and calls an external binary.

I need to distinguish OSX, Windows, and then Linux 32 and Linux 64.

I have tried both platform.platform() and platform.system() and they seem to work on Windows but raise an exception on OSX.

Has anyone got a good XBMC Ok way of doing this? I don't have a Mac very handy to try this out unfortunately.


My code is currently:

LOCALSQUEEZESLAVEVERSION = 'squeezeslave-1.2-311'
BINWIN    = xbmc.translatePath(os.path.join( BIN_PATH, LOCALSQUEEZESLAVEVERSION + "-win") + "//squeezeslave.exe")
BINOSX    = xbmc.translatePath(os.path.join( BIN_PATH, LOCALSQUEEZESLAVEVERSION + "-osx") + "//squeezeslave")
BINLIN32  = xbmc.translatePath(os.path.join( BIN_PATH, LOCALSQUEEZESLAVEVERSION + "-lnx26") + "//squeezeslave")
BINLIN64  = xbmc.translatePath(os.path.join( BIN_PATH, LOCALSQUEEZESLAVEVERSION + "-lnx26") + "//squeezeslave-i64")

#need to work out what system we're on

  #will return Windows or Darwin
  SYSTEM = platform.platform()
  #otherwise we assume some linux 2.6+ flavour...
  SYSTEM = "Linux"

#32 or 64 bit?
is_64bits = sys.maxsize > 2**32

#choose the right executable
if SYSTEM.startswith("Windows"):
elif SYSTEM.startswith("Darwin"):
  if is_64bits:
    EXE = [BINLIN64]
    EXE = [BINLIN32]

#chmod +X the exe file...
if SYSTEM=="Darwin" or SYSTEM=="Linux":
    #attempt to make the binary executable - this never works really...
    #it's really about triggering the messages in the except clause below...
    os.system("chmod a+x " + EXE[0])
    xbmc.log(__addonname__ + "-" + __version__ +": ### chmod +x the Squeezeslave binaries - success")
    xbmc.log(__addonname__ + __version__ +": chmod +x the Squeezeslave binaries - failure -> You must do this manually!!")
    #Logger.notify("Failed to chmod +x the binaries" "Please do so manually - most likely a user permissions error", 10000)
Sorry, no help w/out a *full debug log*
Have you tried

you probably will need to use a combination of sys.platform and the platform module.
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager

I am pretty sure I have actually. It's not having a Mac that makes this hard....but I think all the ones I have tried raise exceptions. Although maybe I have been confusing platform.platform and sys.platform....
Sorry, no help w/out a *full debug log*
Most everything except for 32 bit vs 64 bit but you can narrow that down easily...
MythBox for XBMC -
Or you can go with this code:

No 32/64 bit detection in linux...
My GitHub. My Add-ons:
Hey folks - thanks, those examples really helped and I think I've got it going on ok now. sys.platform is definitly the way to go, as platform.platform() raises exception (only on OSX)

Next issue is the subprocess call....
Sorry, no help w/out a *full debug log*
Looks like my subprocess call may have been a permissions error (despite the wierd error message)...the call to os.system(chmod) - does NOT raise an exception on the Mac but apparently also does not do what it should

grrr. I hate platform stuff, such a pain to work on and test!
Sorry, no help w/out a *full debug log*
Thread Rating:
  • 0 Vote(s) - 0 Average

Logout Mark Read Team Forum Stats Members Help
How to properly detect the underlying OS inside of XBMC python?00