1 | """
|
---|
2 | Copyright (C) 2008-2016 Oracle Corporation
|
---|
3 |
|
---|
4 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
5 | available from http://www.virtualbox.org. This file is free software;
|
---|
6 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
7 | General Public License (GPL) as published by the Free Software
|
---|
8 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
9 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
10 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
11 |
|
---|
12 | The contents of this file may alternatively be used under the terms
|
---|
13 | of the Common Development and Distribution License Version 1.0
|
---|
14 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
15 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
16 | CDDL are applicable instead of those of the GPL.
|
---|
17 |
|
---|
18 | You may elect to license modified versions of this file under the
|
---|
19 | terms and conditions of either the GPL or the CDDL or both.
|
---|
20 | """
|
---|
21 |
|
---|
22 | import xpcom
|
---|
23 | import sys
|
---|
24 | import platform
|
---|
25 |
|
---|
26 | #
|
---|
27 | # This code overcomes somewhat unlucky feature of Python, where it searches
|
---|
28 | # for binaries in the same place as platfom independent modules, while
|
---|
29 | # rest of Python bindings expect _xpcom to be inside xpcom module
|
---|
30 | #
|
---|
31 |
|
---|
32 | _asVBoxPythons = [
|
---|
33 | 'VBoxPython' + str(sys.version_info[0]) + '_' + str(sys.version_info[1]),
|
---|
34 | 'VBoxPython' + str(sys.version_info[0]),
|
---|
35 | 'VBoxPython'
|
---|
36 | ];
|
---|
37 |
|
---|
38 | # On platforms where we ship both 32-bit and 64-bit API bindings, we have to
|
---|
39 | # look for the right set if we're a 32-bit process.
|
---|
40 | if platform.system() in [ 'SunOS', ] and sys.maxsize <= 2**32:
|
---|
41 | _asNew = [ sCandidate + '_x86' for sCandidate in _asVBoxPythons ];
|
---|
42 | _asNew.extend(_asVBoxPythons);
|
---|
43 | _asVBoxPythons = _asNew;
|
---|
44 | del _asNew;
|
---|
45 |
|
---|
46 | # On Darwin (aka Mac OS X) we know exactly where things are in a normal
|
---|
47 | # VirtualBox installation.
|
---|
48 | ## @todo Edit this at build time to the actual VBox location set in the make files.
|
---|
49 | ## @todo We know the location for most hardened builds, not just darwin!
|
---|
50 | if platform.system() == 'Darwin':
|
---|
51 | sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
52 |
|
---|
53 | _oVBoxPythonMod = None
|
---|
54 | for m in _asVBoxPythons:
|
---|
55 | try:
|
---|
56 | _oVBoxPythonMod = __import__(m)
|
---|
57 | break
|
---|
58 | except Exception as x:
|
---|
59 | print('m=%s x=%s' % (m, x))
|
---|
60 | #except:
|
---|
61 | # pass
|
---|
62 |
|
---|
63 | if platform.system() == 'Darwin':
|
---|
64 | sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
65 |
|
---|
66 | if _oVBoxPythonMod == None:
|
---|
67 | raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),));
|
---|
68 |
|
---|
69 | sys.modules['xpcom._xpcom'] = _oVBoxPythonMod;
|
---|
70 | xpcom._xpcom = _oVBoxPythonMod;
|
---|
71 |
|
---|