[43100] | 1 | """
|
---|
[98103] | 2 | Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
[11746] | 3 |
|
---|
[96407] | 4 | This file is part of VirtualBox base platform packages, as
|
---|
| 5 | available from https://www.virtualbox.org.
|
---|
[60492] | 6 |
|
---|
[96407] | 7 | This program is free software; you can redistribute it and/or
|
---|
| 8 | modify it under the terms of the GNU General Public License
|
---|
| 9 | as published by the Free Software Foundation, in version 3 of the
|
---|
| 10 | License.
|
---|
[60492] | 11 |
|
---|
[96407] | 12 | This program is distributed in the hope that it will be useful, but
|
---|
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 15 | General Public License for more details.
|
---|
| 16 |
|
---|
| 17 | You should have received a copy of the GNU General Public License
|
---|
| 18 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 19 |
|
---|
| 20 | SPDX-License-Identifier: GPL-3.0-only
|
---|
[43100] | 21 | """
|
---|
| 22 |
|
---|
[11746] | 23 | import xpcom
|
---|
| 24 | import sys
|
---|
[11852] | 25 | import platform
|
---|
[11746] | 26 |
|
---|
[48282] | 27 | #
|
---|
| 28 | # This code overcomes somewhat unlucky feature of Python, where it searches
|
---|
[11746] | 29 | # for binaries in the same place as platfom independent modules, while
|
---|
| 30 | # rest of Python bindings expect _xpcom to be inside xpcom module
|
---|
[48282] | 31 | #
|
---|
[12207] | 32 |
|
---|
[48282] | 33 | _asVBoxPythons = [
|
---|
| 34 | 'VBoxPython' + str(sys.version_info[0]) + '_' + str(sys.version_info[1]),
|
---|
| 35 | 'VBoxPython' + str(sys.version_info[0]),
|
---|
| 36 | 'VBoxPython'
|
---|
[63775] | 37 | ]
|
---|
[48282] | 38 |
|
---|
[63775] | 39 | # For Python 3.2 and later use the right ABI flag suffix for the module.
|
---|
| 40 | if sys.hexversion >= 0x030200f0 and sys.abiflags:
|
---|
| 41 | _asNew = []
|
---|
| 42 | for sCandidate in _asVBoxPythons:
|
---|
[68042] | 43 | if sCandidate[-1:].isdigit():
|
---|
[63775] | 44 | _asNew.append(sCandidate + sys.abiflags)
|
---|
| 45 | else:
|
---|
| 46 | _asNew.append(sCandidate)
|
---|
| 47 | _asVBoxPythons = _asNew
|
---|
| 48 | del _asNew
|
---|
| 49 |
|
---|
[48282] | 50 | # On platforms where we ship both 32-bit and 64-bit API bindings, we have to
|
---|
| 51 | # look for the right set if we're a 32-bit process.
|
---|
| 52 | if platform.system() in [ 'SunOS', ] and sys.maxsize <= 2**32:
|
---|
[63775] | 53 | _asNew = [ sCandidate + '_x86' for sCandidate in _asVBoxPythons ]
|
---|
| 54 | _asNew.extend(_asVBoxPythons)
|
---|
| 55 | _asVBoxPythons = _asNew
|
---|
| 56 | del _asNew
|
---|
[48282] | 57 |
|
---|
| 58 | # On Darwin (aka Mac OS X) we know exactly where things are in a normal
|
---|
| 59 | # VirtualBox installation.
|
---|
| 60 | ## @todo Edit this at build time to the actual VBox location set in the make files.
|
---|
| 61 | ## @todo We know the location for most hardened builds, not just darwin!
|
---|
[11852] | 62 | if platform.system() == 'Darwin':
|
---|
[12207] | 63 | sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
| 64 |
|
---|
[48282] | 65 | _oVBoxPythonMod = None
|
---|
| 66 | for m in _asVBoxPythons:
|
---|
| 67 | try:
|
---|
| 68 | _oVBoxPythonMod = __import__(m)
|
---|
| 69 | break
|
---|
[92612] | 70 | except:
|
---|
| 71 | pass
|
---|
| 72 | #except Exception as x:
|
---|
| 73 | # print('m=%s x=%s' % (m, x))
|
---|
[12207] | 74 |
|
---|
| 75 | if platform.system() == 'Darwin':
|
---|
| 76 | sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
| 77 |
|
---|
[48282] | 78 | if _oVBoxPythonMod == None:
|
---|
[63775] | 79 | raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
|
---|
[12207] | 80 |
|
---|
[63775] | 81 | sys.modules['xpcom._xpcom'] = _oVBoxPythonMod
|
---|
| 82 | xpcom._xpcom = _oVBoxPythonMod
|
---|
[11905] | 83 |
|
---|