VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/python/vboxxpcom.py@ 106061

Last change on this file since 106061 was 106061, checked in by vboxsync, 8 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.7 KB
Line 
1"""
2Copyright (C) 2008-2024 Oracle and/or its affiliates.
3
4This file is part of VirtualBox base platform packages, as
5available from https://www.virtualbox.org.
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation, in version 3 of the
10License.
11
12This program is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, see <https://www.gnu.org/licenses>.
19
20SPDX-License-Identifier: GPL-3.0-only
21"""
22
23import xpcom
24import sys
25import 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.
40if 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.
52if 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!
62if platform.system() == 'Darwin':
63 sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
64
65_oVBoxPythonMod = None
66for 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
75if platform.system() == 'Darwin':
76 sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
77
78if _oVBoxPythonMod == None:
79 raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
80
81sys.modules['xpcom._xpcom'] = _oVBoxPythonMod
82xpcom._xpcom = _oVBoxPythonMod
83
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette