1 | """
|
---|
2 | Copyright (C) 2008-2012 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 |
|
---|
13 | import xpcom
|
---|
14 | import sys
|
---|
15 | import platform
|
---|
16 |
|
---|
17 | #
|
---|
18 | # This code overcomes somewhat unlucky feature of Python, where it searches
|
---|
19 | # for binaries in the same place as platfom independent modules, while
|
---|
20 | # rest of Python bindings expect _xpcom to be inside xpcom module
|
---|
21 | #
|
---|
22 |
|
---|
23 | _asVBoxPythons = [
|
---|
24 | 'VBoxPython' + str(sys.version_info[0]) + '_' + str(sys.version_info[1]),
|
---|
25 | 'VBoxPython' + str(sys.version_info[0]),
|
---|
26 | 'VBoxPython'
|
---|
27 | ];
|
---|
28 |
|
---|
29 | # On platforms where we ship both 32-bit and 64-bit API bindings, we have to
|
---|
30 | # look for the right set if we're a 32-bit process.
|
---|
31 | if platform.system() in [ 'SunOS', ] and sys.maxsize <= 2**32:
|
---|
32 | _asNew = [ sCandidate + '_x86' for sCandidate in _asVBoxPythons ];
|
---|
33 | _asNew.extend(_asVBoxPythons);
|
---|
34 | _asVBoxPythons = _asNew;
|
---|
35 | del _asNew;
|
---|
36 |
|
---|
37 | # On Darwin (aka Mac OS X) we know exactly where things are in a normal
|
---|
38 | # VirtualBox installation.
|
---|
39 | ## @todo Edit this at build time to the actual VBox location set in the make files.
|
---|
40 | ## @todo We know the location for most hardened builds, not just darwin!
|
---|
41 | if platform.system() == 'Darwin':
|
---|
42 | sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
43 |
|
---|
44 | _oVBoxPythonMod = None
|
---|
45 | for m in _asVBoxPythons:
|
---|
46 | try:
|
---|
47 | _oVBoxPythonMod = __import__(m)
|
---|
48 | break
|
---|
49 | except Exception, x:
|
---|
50 | print 'm=%s x=%s' % (m, x);
|
---|
51 | #except:
|
---|
52 | # pass
|
---|
53 |
|
---|
54 | if platform.system() == 'Darwin':
|
---|
55 | sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
|
---|
56 |
|
---|
57 | if _oVBoxPythonMod == None:
|
---|
58 | raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),));
|
---|
59 |
|
---|
60 | sys.modules['xpcom._xpcom'] = _oVBoxPythonMod;
|
---|
61 | xpcom._xpcom = _oVBoxPythonMod;
|
---|
62 |
|
---|