1 | """
|
---|
2 | Copyright (C) 2008-2024 Oracle and/or its affiliates.
|
---|
3 |
|
---|
4 | This file is part of VirtualBox base platform packages, as
|
---|
5 | available from https://www.virtualbox.org.
|
---|
6 |
|
---|
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.
|
---|
11 |
|
---|
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
|
---|
21 | """
|
---|
22 |
|
---|
23 | import xpcom
|
---|
24 | import sys
|
---|
25 | import platform
|
---|
26 |
|
---|
27 | #
|
---|
28 | # This code overcomes somewhat unlucky feature of Python, where it searches
|
---|
29 | # for binaries in the same place as platfom independent modules, while
|
---|
30 | # rest of Python bindings expect _xpcom to be inside xpcom module
|
---|
31 | #
|
---|
32 |
|
---|
33 | _asVBoxPythons = [
|
---|
34 | 'VBoxPython' + str(sys.version_info[0]) + '_' + str(sys.version_info[1]),
|
---|
35 | 'VBoxPython' + str(sys.version_info[0]),
|
---|
36 | 'VBoxPython'
|
---|
37 | ]
|
---|
38 |
|
---|
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:
|
---|
43 | if sCandidate[-1:].isdigit():
|
---|
44 | _asNew.append(sCandidate + sys.abiflags)
|
---|
45 | else:
|
---|
46 | _asNew.append(sCandidate)
|
---|
47 | _asVBoxPythons = _asNew
|
---|
48 | del _asNew
|
---|
49 |
|
---|
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:
|
---|
53 | _asNew = [ sCandidate + '_x86' for sCandidate in _asVBoxPythons ]
|
---|
54 | _asNew.extend(_asVBoxPythons)
|
---|
55 | _asVBoxPythons = _asNew
|
---|
56 | del _asNew
|
---|
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!
|
---|
62 | if platform.system() == 'Darwin':
|
---|
63 | sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
64 |
|
---|
65 | _oVBoxPythonMod = None
|
---|
66 | for m in _asVBoxPythons:
|
---|
67 | try:
|
---|
68 | _oVBoxPythonMod = __import__(m)
|
---|
69 | break
|
---|
70 | except:
|
---|
71 | pass
|
---|
72 | #except Exception as x:
|
---|
73 | # print('m=%s x=%s' % (m, x))
|
---|
74 |
|
---|
75 | if platform.system() == 'Darwin':
|
---|
76 | sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
77 |
|
---|
78 | if _oVBoxPythonMod == None:
|
---|
79 | raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
|
---|
80 |
|
---|
81 | sys.modules['xpcom._xpcom'] = _oVBoxPythonMod
|
---|
82 | xpcom._xpcom = _oVBoxPythonMod
|
---|
83 |
|
---|