VirtualBox

Changeset 67049 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 23, 2017 5:48:32 PM (8 years ago)
Author:
vboxsync
Message:

Main/glue/vboxapi.py: clean up, remove vbox attribute, eliminate unnecessary parameter of getSessionObject (it is a completely ignored parameter with a default parameter to make life a little simpler for API clients in Python to deal with the previous version still)
Frontends/VBoxShell: adapt to the cleanup, reduce the unnecessary variations in the code dealing with sessions
ValidationKit etc.: adapt to the cleanup

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r63231 r67049  
    267267    vbox = ctx['vb']
    268268    perf = ctx['perf']
    269     session = ctx['global'].getSessionObject(vbox)
     269    session = ctx['global'].getSessionObject()
    270270    progress = mach.launchVMProcess(session, vmtype, "")
    271271    if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
     
    700700    try:
    701701        vbox = ctx['vb']
    702         session = ctx['global'].getSessionObject(vbox)
    703         mach.lockMachine(session, ctx['global'].constants.LockType_Shared)
     702        session = ctx['global'].openMachineSession(mach, fPermitSharing=True)
    704703    except Exception as e:
    705704        printErr(ctx, "Session to '%s' not open: %s" % (mach.name, str(e)))
     
    747746
    748747def cmdClosedVm(ctx, mach, cmd, args=[], save=True):
    749     session = ctx['global'].openMachineSession(mach, True)
     748    session = ctx['global'].openMachineSession(mach, fPermitSharing=True)
    750749    mach = session.machine
    751750    try:
     
    767766
    768767def cmdAnyVm(ctx, mach, cmd, args=[], save=False):
    769     session = ctx['global'].openMachineSession(mach)
     768    session = ctx['global'].openMachineSession(mach, fPermitSharing=True)
    770769    mach = session.machine
    771770    try:
     
    16701669    guestPort = int(args[4])
    16711670    proto = "TCP"
    1672     session = ctx['global'].openMachineSession(mach)
     1671    session = ctx['global'].openMachineSession(mach, fPermitSharing=True)
    16731672    mach = session.machine
    16741673
     
    18791878
    18801879    ctx['wsinfo'] = [url, user, passwd]
    1881     vbox = ctx['global'].platform.connect(url, user, passwd)
    1882     ctx['vb'] = vbox
     1880    ctx['vb'] = ctx['global'].platform.connect(url, user, passwd)
    18831881    try:
    1884         print("Running VirtualBox version %s" % (vbox.version))
     1882        print("Running VirtualBox version %s" % (ctx['vb'].version))
    18851883    except Exception as e:
    18861884        printErr(ctx, e)
     
    19261924        if g_fVerbose:
    19271925            traceback.print_exc()
     1926    ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb'])
    19281927    return 0
    19291928
     
    29062905    if len(cmdargs) > 1:
    29072906        rosession = 0
    2908         session = ctx['global'].openMachineSession(mach, False)
     2907        session = ctx['global'].openMachineSession(mach, fPermitSharing=False)
    29092908        mach = session.machine
    29102909
     
    30843083    func = args[3]
    30853084    session = None
    3086     session = ctx['global'].openMachineSession(vm)
     3085    session = ctx['global'].openMachineSession(vm, fPermitSharing=True)
    30873086    vm = session.machine
    30883087    adapter = vm.getNetworkAdapter(nicnum)
     
    35403539        asLocations = [ os.getcwd(), ]
    35413540        try:    sScriptDir = os.path.dirname(os.path.abspath(__file__))
    3542         except: pass; # In case __file__ isn't there.
     3541        except: pass # In case __file__ isn't there.
    35433542        else:
    35443543            if platform.system() in [ 'SunOS', ]:
     
    35843583    ctx = {
    35853584        'global':       oVBoxMgr,
    3586         'vb':           oVBoxMgr.vbox,
     3585        'vb':           oVBoxMgr.getVirtualBox(),
    35873586        'const':        oVBoxMgr.constants,
    35883587        'remote':       oVBoxMgr.remote,
     
    36053604    #
    36063605    for sKey in list(ctx.keys()):
    3607         del ctx[sKey];
    3608     ctx = None;
    3609     gc.collect();
     3606        del ctx[sKey]
     3607    ctx = None
     3608    gc.collect()
    36103609
    36113610    oVBoxMgr.deinit()
  • trunk/src/VBox/Main/glue/vboxapi.py

    r66630 r67049  
    4545# Globals, environment and sys.path changes.
    4646#
    47 import platform;
     47import platform
    4848VBoxBinDir = os.environ.get("VBOX_PROGRAM_PATH", None)
    4949VBoxSdkDir = os.environ.get("VBOX_SDK_PATH", None)
     
    210210        return None
    211211
    212     def getSessionObject(self, oIVBox):
     212    def getSessionObject(self):
    213213        """
    214214        Get a session object that can be used for opening machine sessions.
     
    219219        See also openMachineSession.
    220220        """
    221         _ = oIVBox
    222221        return None
    223222
     
    514513        return oGenCache.EnsureModule(self.VBOX_TLB_GUID, self.VBOX_TLB_LCID, self.VBOX_TLB_MAJOR, self.VBOX_TLB_MINOR)
    515514
    516     def getSessionObject(self, oIVBox):
    517         _ = oIVBox
     515    def getSessionObject(self):
    518516        import win32com
    519517        from win32com.client import Dispatch
     
    545543        # the missing type information from the getter.
    546544        #
    547         oOleObj     = getattr(oInterface, '_oleobj_');
    548         aPropMapGet = getattr(oInterface, '_prop_map_get_');
    549         aPropMapPut = getattr(oInterface, '_prop_map_put_');
    550         sComAttrib  = sAttrib if sAttrib in aPropMapGet else ComifyName(sAttrib);
     545        oOleObj     = getattr(oInterface, '_oleobj_')
     546        aPropMapGet = getattr(oInterface, '_prop_map_get_')
     547        aPropMapPut = getattr(oInterface, '_prop_map_put_')
     548        sComAttrib  = sAttrib if sAttrib in aPropMapGet else ComifyName(sAttrib)
    551549        try:
    552             aArgs, aDefaultArgs = aPropMapPut[sComAttrib];
    553             aGetArgs            = aPropMapGet[sComAttrib];
     550            aArgs, aDefaultArgs = aPropMapPut[sComAttrib]
     551            aGetArgs            = aPropMapGet[sComAttrib]
    554552        except KeyError: # fallback.
    555             return oInterface.__setattr__(sAttrib, aoArray);
    556 
    557         import pythoncom;
     553            return oInterface.__setattr__(sAttrib, aoArray)
     554
     555        import pythoncom
    558556        oOleObj.InvokeTypes(aArgs[0],                   # dispid
    559557                            aArgs[1],                   # LCID
     
    561559                            (pythoncom.VT_HRESULT, 0),  # retType - or void?
    562560                            (aGetArgs[2],),             # argTypes - trick: we get the type from the getter.
    563                             aoArray,);                  # The array
     561                            aoArray,)                   # The array
    564562
    565563    def initPerThread(self):
     
    753751        _ = dParams
    754752
    755     def getSessionObject(self, oIVBox):
    756         _ = oIVBox
     753    def getSessionObject(self):
    757754        import xpcom.components
    758755        return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
     
    881878    #
    882879
    883     def getSessionObject(self, oIVBox):
    884         return self.wsmgr.getSessionObject(oIVBox)
     880    def getSessionObject(self):
     881        return self.wsmgr.getSessionObject(self.vbox)
    885882
    886883    def getVirtualBox(self):
     
    10141011        # Get the virtualbox singleton.
    10151012        try:
    1016             self.vbox = self.platform.getVirtualBox()
     1013            vbox = self.platform.getVirtualBox()
    10171014        except NameError:
    10181015            print("Installation problem: check that appropriate libs in place")
     
    10231020            print("init exception: ", e)
    10241021            traceback.print_exc()
    1025             if self.remote:
    1026                 self.vbox = None
    1027             else:
    1028                 raise e
    10291022
    10301023    def __del__(self):
     
    10441037        only one method called getSessionObject. It moved into this class.
    10451038        """
    1046         return self;
     1039        return self
    10471040
    10481041    #
     
    10531046        return self.platform.getVirtualBox()
    10541047
    1055     def getSessionObject(self, oIVBox):
     1048    def getSessionObject(self, oIVBox = None):
    10561049        """ See PlatformBase::getSessionObject(). """
    1057         return self.platform.getSessionObject(oIVBox)
     1050        # ignore parameter which was never needed
     1051        _ = oIVBox
     1052        return self.platform.getSessionObject()
    10581053
    10591054    def getArray(self, oInterface, sAttrib):
     
    10971092        Do not access it after calling this method.
    10981093        """
    1099         if hasattr(self, "vbox") and self.vbox is not None:
    1100             del self.vbox
    1101             self.vbox = None
    11021094        if hasattr(self, "platform") and self.platform is not None:
    11031095            self.platform.deinit()
     
    11141106        Raises exception on failure.
    11151107        """
    1116         oSession = self.getSessionObject(self.vbox);
     1108        oSession = self.getSessionObject()
    11171109        if fPermitSharing:
    11181110            eType = self.constants.LockType_Shared
  • trunk/src/VBox/Main/webservice/samples/python/clienttest.py

    r62485 r67049  
    3939    from vboxapi import VirtualBoxManager
    4040    # This is a VirtualBox COM/XPCOM API client, no data needed.
    41     wrapper = VirtualBoxManager(None, None)
     41    mgr = VirtualBoxManager(None, None)
    4242
    43     # Get the VirtualBox manager
    44     mgr  = wrapper.mgr
    4543    # Get the global VirtualBox object
    46     vbox = wrapper.vbox
     44    vbox = mgr.getVirtualBox()
    4745
    4846    print "Running VirtualBox version %s" %(vbox.version)
    4947
    50     # Get all constants through the Python wrapper code
    51     vboxConstants = wrapper.constants
     48    # Get all constants through the Python manager code
     49    vboxConstants = mgr.constants
    5250
    5351    # Enumerate all defined machines
    54     for mach in wrapper.getArray(vbox, 'machines'):
     52    for mach in mgr.getArray(vbox, 'machines'):
    5553
    5654        try:
     
    8078
    8179                # Get the session object
    82                 session = mgr.getSessionObject(vbox)
     80                session = mgr.getSessionObject()
    8381
    8482                 # Lock the current machine (shared mode, since we won't modify the machine)
     
    111109            traceback.print_exc()
    112110
    113     # Call destructor and delete wrapper
    114     del wrapper
     111    # Call destructor and delete manager
     112    del mgr
    115113
    116114if __name__ == '__main__':
  • trunk/src/VBox/ValidationKit/testdriver/vbox.py

    r67048 r67049  
    25102510                      or (self.fpApiVer == 4.3 and not hasattr(self.oVBoxMgr, 'getSessionObject')):
    25112511                        oSession = self.oVBoxMgr.mgr.getSessionObject(self.oVBox);  # pylint: disable=E1101
     2512                    elif self.fpApiVer < 5.2 \
     2513                      or (self.fpApiVer == 5.2 and hasattr(self.oVBoxMgr, 'vbox')):
     2514                        oSession = self.oVBoxMgr.getSessionObject(self.oVBox);      # pylint: disable=E1101
    25122515                    else:
    2513                         oSession = self.oVBoxMgr.getSessionObject(self.oVBox);      # pylint: disable=E1101
     2516                        oSession = self.oVBoxMgr.getSessionObject();                # pylint: disable=E1101
    25142517                    if self.fpApiVer < 3.3:
    25152518                        oProgress = self.oVBox.openRemoteSession(oSession, sUuid, sType, sEnv);
Note: See TracChangeset for help on using the changeset viewer.

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