2222import copy
2323import atexit
2424from multiprocessing import current_process
25- from threading import current_thread
2625
2726from virtualbox .library_ext import library
2827
3433VirtualBox = library .IVirtualBox
3534Session = library .ISession
3635
36+
3737@contextmanager
3838def import_vboxapi ():
3939 """This import is designed to help when loading vboxapi inside of
@@ -47,28 +47,26 @@ def import_vboxapi():
4747 system = platform .system ()
4848 py_mm_ver = sys .version_info [:2 ]
4949 packages = ['vboxapi' ]
50+
5051 if system == 'Windows' :
5152 packages .extend (['win32com' , 'win32' , 'win32api' , 'pywintypes' , 'win32comext' ])
52- search = [
53- 'C:\\ Python%s%s\\ Lib\\ site-packages' % py_mm_ver ,
54- 'C:\\ Python%s%s\\ Lib\\ site-packages\\ win32' % py_mm_ver ,
55- 'C:\\ Python%s%s\\ Lib\\ site-packages\\ win32\\ lib' % py_mm_ver ,
56- 'C:\\ Program Files\\ Oracle\\ VirtualBox\\ sdk\\ install' ,
57- 'C:\\ Program Files (x86)\\ Oracle\\ VirtualBox\\ sdk\\ install' ,
58- ]
53+ search = ['C:\\ Python%s%s\\ Lib\\ site-packages' % py_mm_ver ,
54+ 'C:\\ Python%s%s\\ Lib\\ site-packages\\ win32' % py_mm_ver ,
55+ 'C:\\ Python%s%s\\ Lib\\ site-packages\\ win32\\ lib' % py_mm_ver ,
56+ 'C:\\ Program Files\\ Oracle\\ VirtualBox\\ sdk\\ install' ,
57+ 'C:\\ Program Files (x86)\\ Oracle\\ VirtualBox\\ sdk\\ install' ]
58+
5959 elif system == 'Linux' :
60- search = [
61- '/usr/lib/python%s.%s/dist-packages' % py_mm_ver ,
62- '/usr/lib/python%s.%s/site-packages' % py_mm_ver ,
63- '/usr/share/pyshared' ,
64- ]
60+ search = ['/usr/lib/python%s.%s/dist-packages' % py_mm_ver ,
61+ '/usr/lib/python%s.%s/site-packages' % py_mm_ver ,
62+ '/usr/share/pyshared' ]
63+
6564 elif system == 'Darwin' :
66- search = [
67- '/Library/Python/%s.%s/site-packages' % py_mm_ver ,
68- ]
65+ search = ['/Library/Python/%s.%s/site-packages' % py_mm_ver ]
6966 else :
7067 # No idea where to look...
7168 raise
69+
7270 packages = set (packages )
7371 original_path = copy .copy (sys .path )
7472 for path in search :
@@ -81,7 +79,7 @@ def import_vboxapi():
8179 if not packages :
8280 break
8381 else :
84- # After search each path we still failed to find
82+ # After search each path we still failed to find
8583 # the required set of packages.
8684 raise
8785 import vboxapi
@@ -93,13 +91,15 @@ def import_vboxapi():
9391 yield vboxapi
9492
9593
96- _managers = {}
94+ _managers = {}
95+
96+
9797class Manager (object ):
9898 """The Manager maintains a single point of entry into vboxapi.
99-
99+
100100 This object is responsible for the construction of
101101 :py:class:`virtualbox.library_ext.ISession` and
102- :py:class:`virtualbox.library_ext.IVirtualBox`.
102+ :py:class:`virtualbox.library_ext.IVirtualBox`.
103103
104104 :param mtype: Type of manager i.e. WEBSERVICE.
105105 :type mtype: str (Default None)
@@ -117,12 +117,12 @@ def __init__(self, mtype=None, mparams=None):
117117 @property
118118 def manager (self ):
119119 """Create a default Manager object
120-
120+
121121 Builds a singleton VirtualBoxManager object.
122122
123123 Note: It is not necessary to build this object when defining a
124124 Session or VirtualBox object as both of these classes will default
125- to this object's global singleton during construction.
125+ to this object's global singleton during construction.
126126 """
127127 if _managers is None :
128128 raise RuntimeError ("Can not get the manager following a system exit." )
@@ -135,20 +135,20 @@ def manager(self, value):
135135 if _managers is None :
136136 raise RuntimeError ("Can not set the manager following a system exit." )
137137 if pid not in _managers :
138- _managers [pid ] = value
138+ _managers [pid ] = value
139139 else :
140140 raise Exception ("Manager already set for pid %s" % pid )
141141
142142 def get_virtualbox (self ):
143143 """Return a VirtualBox interface
144-
144+
145145 :rtype: library.IVirtualBox
146146 """
147147 return VirtualBox (interface = self .manager .getVirtualBox ())
148148
149149 def get_session (self ):
150150 """Return a Session interface
151-
151+
152152 :rtype: library.ISession
153153 """
154154 # The inconsistent vboxapi implementation makes this annoying...
@@ -160,7 +160,7 @@ def get_session(self):
160160
161161 def cast_object (self , interface_object , interface_class ):
162162 """Cast the obj to the interface class
163-
163+
164164 :rtype: interface_class(interface_object)
165165 """
166166 name = interface_class .__name__
@@ -170,17 +170,17 @@ def cast_object(self, interface_object, interface_class):
170170 @property
171171 def bin_path (self ):
172172 """return the virtualbox install directory
173-
173+
174174 :rtype: str
175175 """
176176 return self .manager .getBinDir ()
177177
178178
179- # Attempt to close left over manager objects cleanly.
179+ # Attempt to close left over manager objects cleanly.
180180def _cleanup_managers ():
181181 global _managers
182182 managers = _managers
183- _managers = None
183+ _managers = None
184184 for manager in managers .values ():
185185 try :
186186 del manager
@@ -198,9 +198,9 @@ class WebServiceManager(Manager):
198198 """
199199 def __init__ (self , url = 'http://localhost/' , user = '' , password = '' ):
200200 """Create a VirtualBoxManager WEBSERVICE manager for IVirtualBox
201-
201+
202202 Options:
203- url - url to connect with the VirtualBox server
203+ url - url to connect with the VirtualBox server
204204 user - username used to auth to the VirtualBox server service
205205 password - password used to auth to the VirtualBox server service
206206
@@ -209,11 +209,11 @@ def __init__(self, url='http://localhost/', user='', password=''):
209209 vbox = VirtualBox(manager=manager)
210210 ...
211211 """
212- params = {"url" :url , "user" :user , "password" :password }
212+ params = {"url" : url , "user" : user , "password" : password }
213213 super (WebServiceManager , self ).__init__ ("WEBSERVICE" , params )
214214
215215
216216# Lazy include...
217- from virtualbox import pool
218- from virtualbox import events
219- from virtualbox import version
217+ from virtualbox import pool # noqa: F401
218+ from virtualbox import events # noqa: F401
219+ from virtualbox import version # noqa: F401
0 commit comments