How to properly detect the underlying OS inside of XBMC python?
#1
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.

ANY HELP MUCH APPRECIATED!!

My code is currently:

Code:
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
SYSTEM=""

try:
  #will return Windows or Darwin
  SYSTEM = platform.platform()
except:
  #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"):
  EXE = [BINWIN]
elif SYSTEM.startswith("Darwin"):
  EXE = [BINOSX]
else:
  if is_64bits:
    EXE = [BINLIN64]
  else:
    EXE = [BINLIN32]

#chmod +X the exe file...
if SYSTEM=="Darwin" or SYSTEM=="Linux":
  try:
    #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")
  except:
    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*
Reply
#2
Have you tried
Code:
sys.platform

you probably will need to use a combination of sys.platform and the platform module.
Image
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
fanart.tv


Reply
#3
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*
Reply
#4
Most everything except for 32 bit vs 64 bit but you can narrow that down easily...

https://github.com/analogue/mythbox/blob...orm.py#L31
MythBox for XBMC - http://mythbox.googlecode.com
Reply
#5
Or you can go with this code: https://github.com/dersphere/script.xbmc...gui.py#L68

No 32/64 bit detection in linux...
My GitHub. My Add-ons:
Image
Reply
#6
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.... http://forum.xbmc.org/showthread.php?tid=123613
Sorry, no help w/out a *full debug log*
Reply
#7
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*
Reply
 
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