VirtualBox

source: vbox/trunk/src/VBox/Main/glue/vboxapi.py@ 19859

Last change on this file since 19859 was 19859, checked in by vboxsync, 16 years ago

Python: copyrights, removed stalled code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1#
2# Copyright (C) 2009 Sun Microsystems, Inc.
3#
4# This file is part of VirtualBox Open Source Edition (OSE), as
5# available from http://www.215389.xyz. 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# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
13# Clara, CA 95054 USA or visit http://www.sun.com if you need
14# additional information or have any questions.
15#
16import sys,os
17import traceback
18
19VboxBinDir = os.environ.get("VBOX_PROGRAM_PATH", None)
20VboxSdkDir = os.environ.get("VBOX_SDK_PATH", None)
21
22if VboxBinDir is None:
23 # @todo: To be set by installer
24 VboxBinDir = "/home/nike/work/ws/out/linux.amd64/debug/bin/"
25
26if VboxSdkDir is None:
27 VboxSdkDir = VboxBinDir+"/sdk"
28
29os.environ["VBOX_PROGRAM_PATH"] = VboxBinDir
30os.environ["VBOX_SDK_PATH"] = VboxSdkDir
31sys.path.append(VboxBinDir)
32sys.path.append(VboxSdkDir+"/bindings/glue/python")
33
34class PlatformMSCOM:
35 class ConstantFake:
36 def __init__(self, parent, name):
37 self.__dict__['_parent'] = parent
38 self.__dict__['_name'] = name
39 self.__dict__['_consts'] = {}
40 try:
41 self.__dict__['_depth']=parent.__dict__['_depth']+1
42 except:
43 self.__dict__['_depth']=0
44 if self.__dict__['_depth'] > 4:
45 raise AttributeError
46
47 def __getattr__(self, attr):
48 if attr.startswith("__"):
49 raise AttributeError
50
51 consts = self.__dict__['_consts']
52 fake = consts.get(attr, None)
53 if fake != None:
54 return fake
55 try:
56 name = makeFullName(self, attr)
57 return win32com.client.constants.__getattr__(name)
58 except AttributeError,e:
59 fake = ConstantFake(self, attr)
60 consts[attr] = fake
61 return fake
62
63 class InterfacesWrapper:
64 def __init__(self):
65 self.__dict__['_rootFake'] = PlatformMSCOM.ConstantFake(None, None)
66
67 def __getattr__(self, a):
68 if a.startswith("__"):
69 raise AttributeError
70 try:
71 return win32com.client.constants.__getattr__(a)
72 except AttributeError,e:
73 return self.__dict__['_rootFake'].__getattr__(a)
74
75 def makeFullName(fake, attr):
76 name = fake._name
77 parent = fake._parent
78 while parent != None:
79 if parent._name is not None:
80 name = parent._name+'_'+name
81 parent = parent._parent
82
83 if name is not None:
84 name += "_" + attr
85 else:
86 name = attr
87 return name
88
89 def __init__(self, params):
90 sys.path.append(VboxSdkDir+'/bindings/mscom/python/')
91 from win32com import universal
92 from win32com.client import gencache, DispatchWithEvents, Dispatch
93 from win32com.client import constants, getevents
94 import win32com.server.register
95 import win32com
96 import pythoncom
97 import win32api
98 self.constants = PlatformMSCOM.InterfacesWrapper()
99 #win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
100 #win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
101
102 def getSessionObject(self):
103 import win32com
104 from win32com.client import Dispatch
105 return win32com.client.Dispatch("VirtualBox.Session")
106
107 def getVirtualBox(self):
108 import win32com
109 from win32com.client import Dispatch
110 return win32com.client.Dispatch("VirtualBox.VirtualBox")
111
112 def getConstants(self):
113 return self.constants
114
115 def getType(self):
116 return 'MSCOM'
117
118 def getRemote(self):
119 return False
120
121 def getArray(self, obj, field):
122 return obj.__getattr__(field)
123
124
125class PlatformXPCOM:
126 def __init__(self, params):
127 sys.path.append(VboxSdkDir+'/bindings/xpcom/python/')
128 import xpcom.vboxxpcom
129 import xpcom
130 import xpcom.components
131
132 def getSessionObject(self):
133 import xpcom.components
134 return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
135
136 def getVirtualBox(self):
137 import xpcom.components
138 return xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
139
140 def getConstants(self):
141 import xpcom.components
142 return xpcom.components.interfaces
143
144 def getType(self):
145 return 'XPCOM'
146
147 def getRemote(self):
148 return False
149
150 def getArray(self, obj, field):
151 return obj.__getattr__('get'+field.capitalize())()
152
153class PlatformWEBSERVICE:
154 def __init__(self, params):
155 sys.path.append(VboxSdkDir+'/bindings/webservice/python/lib')
156 import VirtualBox_services
157 import VirtualBox_wrappers
158 from VirtualBox_wrappers import IWebsessionManager
159 from VirtualBox_wrappers import g_port
160 from VirtualBox_wrappers import g_reflectionInfo
161 self.wsmgr = IWebsessionManager()
162 self.port = g_port
163 self.constants = g_reflectionInfo
164 self.user = ""
165 self.password = ""
166
167 def getSessionObject(self):
168 return self.wsmgr.getSessionObject()
169
170 def getVirtualBox(self):
171 return self.wsmgr.logon(self.user, self.password)
172
173 def getConstants(self):
174 from VirtualBox_wrappers import g_reflectionInfo
175 return g_reflectionInfo
176
177 def getType(self):
178 return 'WEBSERVICE'
179
180 def getRemote(self):
181 return True
182
183 def getArray(self, obj, field):
184 return obj.__getattr__(field)
185
186
187class SessionManager:
188 def __init__(self, mgr):
189 self.mgr = mgr
190
191 def getSessionObject(self, vbox):
192 return self.mgr.platform.getSessionObject()
193
194class VirtualBoxManager:
195 def __init__(self, style, platparams):
196 if style is None:
197 if sys.platform == 'win32':
198 style = "MSCOM"
199 else:
200 style = "XPCOM"
201 try:
202 exec "self.platform = Platform"+style+"(platparams)"
203 self.vbox = self.platform.getVirtualBox()
204 self.mgr = SessionManager(self)
205 self.constants = self.platform.getConstants()
206 self.type = self.platform.getType()
207 self.remote = self.platform.getRemote()
208 except Exception,e:
209 print "init exception: ",e
210 traceback.print_exc()
211 raise e
212
213 def getArray(self, obj, field):
214 return self.platform.getArray(obj, field)
215
216 def getVirtualBox(self):
217 return self.platform.getVirtualBox()
218
219 def __del__(self):
220 if hasattr(self, "vbox"):
221 del self.vbox
Note: See TracBrowser for help on using the repository browser.

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