e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsync"""
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsyncCopyright (C) 2008-2012 Oracle Corporation
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsync
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsyncavailable from http://www.virtualbox.org. This file is free software;
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsyncyou can redistribute it and/or modify it under the terms of the GNU
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsyncGeneral Public License (GPL) as published by the Free Software
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e30fdd5b5f903e0cc7113ed731bb8b29aa25f985vboxsync"""
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncimport xpcom
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncimport sys
fa28a063d8ed660b9ae9aef07f417338b0efd8acvboxsyncimport platform
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync#
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync# This code overcomes somewhat unlucky feature of Python, where it searches
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# for binaries in the same place as platfom independent modules, while
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# rest of Python bindings expect _xpcom to be inside xpcom module
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync#
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync_asVBoxPythons = [
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync 'VBoxPython' + str(sys.version_info[0]) + '_' + str(sys.version_info[1]),
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync 'VBoxPython' + str(sys.version_info[0]),
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync 'VBoxPython'
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync];
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync# On platforms where we ship both 32-bit and 64-bit API bindings, we have to
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync# look for the right set if we're a 32-bit process.
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsyncif platform.system() in [ 'SunOS', ] and sys.maxsize <= 2**32:
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync _asNew = [ sCandidate + '_x86' for sCandidate in _asVBoxPythons ];
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync _asNew.extend(_asVBoxPythons);
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync _asVBoxPythons = _asNew;
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync del _asNew;
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync# On Darwin (aka Mac OS X) we know exactly where things are in a normal
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync# VirtualBox installation.
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync## @todo Edit this at build time to the actual VBox location set in the make files.
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync## @todo We know the location for most hardened builds, not just darwin!
fa28a063d8ed660b9ae9aef07f417338b0efd8acvboxsyncif platform.system() == 'Darwin':
8bb33f676e931af74370adf623e55b06e0972801vboxsync sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
8bb33f676e931af74370adf623e55b06e0972801vboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync_oVBoxPythonMod = None
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsyncfor m in _asVBoxPythons:
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync try:
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync _oVBoxPythonMod = __import__(m)
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync break
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync except Exception, x:
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync print 'm=%s x=%s' % (m, x);
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync #except:
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync # pass
8bb33f676e931af74370adf623e55b06e0972801vboxsync
8bb33f676e931af74370adf623e55b06e0972801vboxsyncif platform.system() == 'Darwin':
8bb33f676e931af74370adf623e55b06e0972801vboxsync sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
8bb33f676e931af74370adf623e55b06e0972801vboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsyncif _oVBoxPythonMod == None:
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),));
8bb33f676e931af74370adf623e55b06e0972801vboxsync
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsyncsys.modules['xpcom._xpcom'] = _oVBoxPythonMod;
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsyncxpcom._xpcom = _oVBoxPythonMod;
a7a0244227b5c1fb4410f6a1fa6cf7a462eaf4c1vboxsync