VirtualBox

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

Last change on this file since 59795 was 59795, checked in by vboxsync, 9 years ago

temporarily back out the recent Python 3 changes (r105649, r105645, r105644, r105643, r105641)

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1"""
2Copyright (C) 2008-2012 Oracle Corporation
3
4This file is part of VirtualBox Open Source Edition (OSE), as
5available from http://www.virtualbox.org. This file is free software;
6you can redistribute it and/or modify it under the terms of the GNU
7General Public License (GPL) as published by the Free Software
8Foundation, in version 2 as it comes in the "COPYING" file of the
9VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11"""
12
13import xpcom
14import sys
15import 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.
31if 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!
41if platform.system() == 'Darwin':
42 sys.path.append('/Applications/VirtualBox.app/Contents/MacOS')
43
44_oVBoxPythonMod = None
45for 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
54if platform.system() == 'Darwin':
55 sys.path.remove('/Applications/VirtualBox.app/Contents/MacOS')
56
57if _oVBoxPythonMod == None:
58 raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),));
59
60sys.modules['xpcom._xpcom'] = _oVBoxPythonMod;
61xpcom._xpcom = _oVBoxPythonMod;
62
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