VirtualBox

Ignore:
Timestamp:
Feb 24, 2016 9:13:27 AM (9 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

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

    r59777 r59795  
    22# -*- coding: utf-8 -*-
    33# $Id$
    4 
    54"""
    65VirtualBox Python Shell.
     
    2019"""
    2120
    22 from __future__ import print_function
    23 
    2421__copyright__ = \
    2522"""
    26 Copyright (C) 2009-2016 Oracle Corporation
     23Copyright (C) 2009-2015 Oracle Corporation
    2724
    2825This file is part of VirtualBox Open Source Edition (OSE), as
     
    3734
    3835
    39 import os
    40 import sys
     36import os, sys
    4137import traceback
    4238import shlex
     
    4642from optparse import OptionParser
    4743from pprint import pprint
     44
    4845
    4946
     
    155152                            matches.append(word)
    156153
    157             except Exception as e:
     154            except Exception, e:
    158155                printErr(self.ctx, e)
    159156                if g_fVerbose:
     
    167164
    168165    comps = {}
    169     for (key, _value) in list(cmds.items()):
     166    for (key, _value) in cmds.items():
    170167        comps[key] = None
    171168    completer = CompleterNG(comps, ctx)
     
    192189    try:
    193190        while not progress.completed:
    194             print("%s %%\r" % (colored(str(progress.percent), 'red')), end="")
     191            print "%s %%\r" % (colored(str(progress.percent), 'red')),
    195192            sys.stdout.flush()
    196193            progress.waitForCompletion(wait)
     
    200197        return 1
    201198    except KeyboardInterrupt:
    202         print("Interrupted.")
     199        print "Interrupted."
    203200        ctx['interrupt'] = True
    204201        if progress.cancelable:
    205             print("Canceling task...")
     202            print "Canceling task..."
    206203            progress.cancel()
    207204        return 0
    208205
    209206def printErr(_ctx, e):
    210     oVBoxMgr = _ctx['global']
     207    oVBoxMgr = _ctx['global'];
    211208    if oVBoxMgr.errIsOurXcptKind(e):
    212         print(colored('%s: %s' % (oVBoxMgr.xcptToString(e), oVBoxMgr.xcptGetMessage(e)), 'red'))
    213     else:
    214         print(colored(str(e), 'red'))
     209        print colored('%s: %s' % (oVBoxMgr.xcptToString(e), oVBoxMgr.xcptGetMessage(e)), 'red');
     210    else:
     211        print colored(str(e), 'red')
    215212
    216213def reportError(_ctx, progress):
    217214    errorinfo = progress.errorInfo
    218215    if errorinfo:
    219         print(colored("Error in module '%s': %s" % (errorinfo.component, errorinfo.text), 'red'))
     216        print colored("Error in module '%s': %s" % (errorinfo.component, errorinfo.text), 'red')
    220217
    221218def colCat(_ctx, strg):
     
    244241    mach = vbox.createMachine("", name, [], kind, "")
    245242    mach.saveSettings()
    246     print("created machine with UUID", mach.id)
     243    print "created machine with UUID", mach.id
    247244    vbox.registerMachine(mach)
    248245    # update cache
     
    251248def removeVm(ctx, mach):
    252249    uuid = mach.id
    253     print("removing machine ", mach.name, "with UUID", uuid)
     250    print "removing machine ", mach.name, "with UUID", uuid
    254251    cmdClosedVm(ctx, mach, detachVmDevice, ["ALL"])
    255252    disks = mach.unregister(ctx['global'].constants.CleanupMode_Full)
     
    257254        progress = mach.deleteConfig(disks)
    258255        if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
    259             print("Success!")
     256            print "Success!"
    260257        else:
    261258            reportError(ctx, progress)
     
    274271            try:
    275272                perf.setup(['*'], [mach], 10, 15)
    276             except Exception as e:
     273            except Exception, e:
    277274                printErr(ctx, e)
    278275                if g_fVerbose:
     
    327324        return
    328325    for metric in ctx['perf'].query(["*"], [mach]):
    329         print(metric['name'], metric['values_as_string'])
     326        print metric['name'], metric['values_as_string']
    330327
    331328def guestExec(ctx, machine, console, cmds):
    332     exec(cmds)
     329    exec cmds
    333330
    334331def printMouseEvent(_ctx, mev):
    335     print("Mouse : mode=%d x=%d y=%d z=%d w=%d buttons=%x" % (mev.mode, mev.x, mev.y, mev.z, mev.w, mev.buttons))
     332    print "Mouse : mode=%d x=%d y=%d z=%d w=%d buttons=%x" % (mev.mode, mev.x, mev.y, mev.z, mev.w, mev.buttons)
    336333
    337334def printKbdEvent(ctx, kev):
    338     print("Kbd: ", ctx['global'].getArray(kev, 'scancodes'))
     335    print "Kbd: ", ctx['global'].getArray(kev, 'scancodes')
    339336
    340337def printMultiTouchEvent(ctx, mtev):
    341     print("MultiTouch : contacts=%d time=%d" % (mtev.contactCount, mtev.scanTime))
     338    print "MultiTouch : contacts=%d time=%d" % (mtev.contactCount, mtev.scanTime)
    342339    xPositions = ctx['global'].getArray(mtev, 'xPositions')
    343340    yPositions = ctx['global'].getArray(mtev, 'yPositions')
     
    346343
    347344    for i in range(0, mtev.contactCount):
    348         print("  [%d] %d,%d %d %d" % (i, xPositions[i], yPositions[i], contactIds[i], contactFlags[i]))
     345        print "  [%d] %d,%d %d %d" % (i, xPositions[i], yPositions[i], contactIds[i], contactFlags[i])
    349346
    350347def monitorSource(ctx, eventSource, active, dur):
    351348    def handleEventImpl(event):
    352349        evtype = event.type
    353         print("got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype)))
     350        print "got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))
    354351        if evtype == ctx['global'].constants.VBoxEventType_OnMachineStateChanged:
    355352            scev = ctx['global'].queryInterface(event, 'IMachineStateChangedEvent')
    356353            if scev:
    357                 print("machine state event: mach=%s state=%s" % (scev.machineId, scev.state))
     354                print "machine state event: mach=%s state=%s" % (scev.machineId, scev.state)
    358355        elif  evtype == ctx['global'].constants.VBoxEventType_OnSnapshotTaken:
    359356            stev = ctx['global'].queryInterface(event, 'ISnapshotTakenEvent')
    360357            if stev:
    361                 print("snapshot taken event: mach=%s snap=%s" % (stev.machineId, stev.snapshotId))
     358                print "snapshot taken event: mach=%s snap=%s" % (stev.machineId, stev.snapshotId)
    362359        elif  evtype == ctx['global'].constants.VBoxEventType_OnGuestPropertyChanged:
    363360            gpcev = ctx['global'].queryInterface(event, 'IGuestPropertyChangedEvent')
    364361            if gpcev:
    365                 print("guest property change: name=%s value=%s" % (gpcev.name, gpcev.value))
     362                print "guest property change: name=%s value=%s" % (gpcev.name, gpcev.value)
    366363        elif  evtype == ctx['global'].constants.VBoxEventType_OnMousePointerShapeChanged:
    367364            psev = ctx['global'].queryInterface(event, 'IMousePointerShapeChangedEvent')
     
    369366                shape = ctx['global'].getArray(psev, 'shape')
    370367                if shape is None:
    371                     print("pointer shape event - empty shape")
     368                    print "pointer shape event - empty shape"
    372369                else:
    373                     print("pointer shape event: w=%d h=%d shape len=%d" % (psev.width, psev.height, len(shape)))
     370                    print "pointer shape event: w=%d h=%d shape len=%d" % (psev.width, psev.height, len(shape))
    374371        elif evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse:
    375372            mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent')
     
    444441    def handleEventImpl(event):
    445442        evtype = event.type
    446         #print("got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype)))
     443        #print "got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))
    447444        if evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse:
    448445            mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent')
     
    492489
    493490    header = demo.readline()
    494     print("Header is", header)
     491    print "Header is", header
    495492    basere = re.compile(r'(?P<s>\d+): (?P<t>[km]) (?P<p>.*)')
    496493    mre = re.compile(r'(?P<a>\d+) (?P<x>-*\d+) (?P<y>-*\d+) (?P<z>-*\d+) (?P<w>-*\d+) (?P<b>-*\d+)')
     
    518515            if rtype == 'k':
    519516                codes = kre.findall(params)
    520                 #print("KBD:", codes)
     517                #print "KBD:", codes
    521518                kbd.putScancodes(codes)
    522519            elif rtype == 'm':
     
    526523                    if mdict['a'] == '1':
    527524                        # absolute
    528                         #print("MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b'])
     525                        #print "MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b']
    529526                        mouse.putMouseEventAbsolute(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b']))
    530527                    else:
    531                         #print("MR: ", mdict['x'], mdict['y'], mdict['b'])
     528                        #print "MR: ", mdict['x'], mdict['y'], mdict['b']
    532529                        mouse.putMouseEvent(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b']))
    533530
     
    562559        h = fbh
    563560
    564     print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f))
     561    print "Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)
    565562    data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_RGBA)
    566563    size = (w, h)
     
    589586        h = fbh
    590587
    591     print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f))
     588    print "Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)
    592589    data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_PNG)
    593590    pngfile = open(f, 'wb')
     
    597594def teleport(ctx, _session, console, args):
    598595    if args[0].find(":") == -1:
    599         print("Use host:port format for teleport target")
     596        print "Use host:port format for teleport target"
    600597        return
    601598    (host, port) = args[0].split(":")
     
    611608
    612609    port = int(port)
    613     print("Teleporting to %s:%d..." % (host, port))
     610    print "Teleporting to %s:%d..." % (host, port)
    614611    progress = console.teleport(host, port, passwd, maxDowntime)
    615612    if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
    616         print("Success!")
     613        print "Success!"
    617614    else:
    618615        reportError(ctx, progress)
     
    635632    all_stats = ctx['const'].all_values('GuestStatisticType')
    636633    cpu = 0
    637     for s in list(all_stats.keys()):
     634    for s in all_stats.keys():
    638635        try:
    639636            val = guest.getStatistic( cpu, all_stats[s])
    640             print("%s: %d" % (s, val))
     637            print "%s: %d" % (s, val)
    641638        except:
    642639            # likely not implemented
     
    645642def plugCpu(_ctx, machine, _session, args):
    646643    cpu = int(args[0])
    647     print("Adding CPU %d..." % (cpu))
     644    print "Adding CPU %d..." % (cpu)
    648645    machine.hotPlugCPU(cpu)
    649646
    650647def unplugCpu(_ctx, machine, _session, args):
    651648    cpu = int(args[0])
    652     print("Removing CPU %d..." % (cpu))
     649    print "Removing CPU %d..." % (cpu)
    653650    machine.hotUnplugCPU(cpu)
    654651
     
    664661
    665662def printHostUsbDev(ctx, ud):
    666     print("  %s: %s (vendorId=%d productId=%d serial=%s) %s" % (ud.id, colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber, asEnumElem(ctx, 'USBDeviceState', ud.state)))
     663    print "  %s: %s (vendorId=%d productId=%d serial=%s) %s" % (ud.id, colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber, asEnumElem(ctx, 'USBDeviceState', ud.state))
    667664
    668665def printUsbDev(_ctx, ud):
    669     print("  %s: %s (vendorId=%d productId=%d serial=%s)" % (ud.id,  colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber))
     666    print "  %s: %s (vendorId=%d productId=%d serial=%s)" % (ud.id,  colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber)
    670667
    671668def printSf(ctx, sf):
    672     print("    name=%s host=%s %s %s" % (sf.name, colPath(ctx, sf.hostPath), cond(sf.accessible, "accessible", "not accessible"), cond(sf.writable, "writable", "read-only")))
     669    print "    name=%s host=%s %s %s" % (sf.name, colPath(ctx, sf.hostPath), cond(sf.accessible, "accessible", "not accessible"), cond(sf.writable, "writable", "read-only"))
    673670
    674671def ginfo(ctx, console, _args):
    675672    guest = console.guest
    676673    if guest.additionsRunLevel != ctx['const'].AdditionsRunLevelType_None:
    677         print("Additions active, version %s" % (guest.additionsVersion))
    678         print("Support seamless: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Seamless)))
    679         print("Support graphics: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Graphics)))
    680         print("Balloon size: %d" % (guest.memoryBalloonSize))
    681         print("Statistic update interval: %d" % (guest.statisticsUpdateInterval))
    682     else:
    683         print("No additions")
     674        print "Additions active, version %s" % (guest.additionsVersion)
     675        print "Support seamless: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Seamless))
     676        print "Support graphics: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Graphics))
     677        print "Balloon size: %d" % (guest.memoryBalloonSize)
     678        print "Statistic update interval: %d" % (guest.statisticsUpdateInterval)
     679    else:
     680        print "No additions"
    684681    usbs = ctx['global'].getArray(console, 'USBDevices')
    685     print("Attached USB:")
     682    print "Attached USB:"
    686683    for ud in usbs:
    687684        printUsbDev(ctx, ud)
    688685    rusbs = ctx['global'].getArray(console, 'remoteUSBDevices')
    689     print("Remote USB:")
     686    print "Remote USB:"
    690687    for ud in rusbs:
    691688        printHostUsbDev(ctx, ud)
    692     print("Transient shared folders:")
     689    print "Transient shared folders:"
    693690    sfs = rusbs = ctx['global'].getArray(console, 'sharedFolders')
    694691    for sf in sfs:
     
    701698        session = ctx['global'].getSessionObject(vbox)
    702699        mach.lockMachine(session, ctx['global'].constants.LockType_Shared)
    703     except Exception as e:
     700    except Exception, e:
    704701        printErr(ctx, "Session to '%s' not open: %s" % (mach.name, str(e)))
    705702        if g_fVerbose:
     
    707704        return
    708705    if session.state != ctx['const'].SessionState_Locked:
    709         print("Session to '%s' in wrong state: %s" % (mach.name, session.state))
     706        print "Session to '%s' in wrong state: %s" % (mach.name, session.state)
    710707        session.unlockMachine()
    711708        return
     
    713710    # in Webservices) functionality
    714711    if ctx['remote'] and cmd == 'some_local_only_command':
    715         print('Trying to use local only functionality, ignored')
     712        print 'Trying to use local only functionality, ignored'
    716713        session.unlockMachine()
    717714        return
     
    737734    except KeyboardInterrupt:
    738735        ctx['interrupt'] = True
    739     except Exception as e:
     736    except Exception, e:
    740737        printErr(ctx, e)
    741738        if g_fVerbose:
     
    750747    try:
    751748        cmd(ctx, mach, args)
    752     except Exception as e:
     749    except Exception, e:
    753750        save = False
    754751        printErr(ctx, e)
     
    758755        try:
    759756            mach.saveSettings()
    760         except Exception as e:
     757        except Exception, e:
    761758            printErr(ctx, e)
    762759            if g_fVerbose:
     
    770767    try:
    771768        cmd(ctx, mach, session.console, args)
    772     except Exception as e:
     769    except Exception, e:
    773770        save = False
    774771        printErr(ctx, e)
     
    780777
    781778def machById(ctx, uuid):
    782     mach = ctx['vb'].findMachine(uuid)
     779    try:
     780        mach = ctx['vb'].getMachine(uuid)
     781    except:
     782        mach = ctx['vb'].findMachine(uuid)
    783783    return mach
    784784
     
    899899def argsToMach(ctx, args):
    900900    if len(args) < 2:
    901         print("usage: %s [vmname|uuid]" % (args[0]))
     901        print "usage: %s [vmname|uuid]" % (args[0])
    902902        return None
    903903    uuid = args[1]
    904904    mach = machById(ctx, uuid)
    905905    if mach == None:
    906         print("Machine '%s' is unknown, use list command to find available machines" % (uuid))
     906        print "Machine '%s' is unknown, use list command to find available machines" % (uuid)
    907907    return mach
    908908
     
    912912    else:
    913913        spec = ""
    914     print("    %s: %s%s" % (colored(cmd, 'blue'), h, spec))
     914    print "    %s: %s%s" % (colored(cmd, 'blue'), h, spec)
    915915
    916916def helpCmd(_ctx, args):
    917917    if len(args) == 1:
    918         print("Help page:")
    919         names = list(commands.keys())
     918        print "Help page:"
     919        names = commands.keys()
    920920        names.sort()
    921921        for i in names:
     
    925925        c = commands.get(cmd)
    926926        if c == None:
    927             print("Command '%s' not known" % (cmd))
     927            print "Command '%s' not known" % (cmd)
    928928        else:
    929929            helpSingleCmd(cmd, c[0], c[2])
     
    932932def asEnumElem(ctx, enum, elem):
    933933    enumVals = ctx['const'].all_values(enum)
    934     for e in list(enumVals.keys()):
     934    for e in enumVals.keys():
    935935        if str(elem) == str(enumVals[e]):
    936936            return colored(e, 'green')
     
    948948            else:
    949949                tele = "    "
    950                 print("%sMachine '%s' [%s], machineState=%s, sessionState=%s" % (tele, colVm(ctx, mach.name), mach.id, asEnumElem(ctx, "MachineState", mach.state), asEnumElem(ctx, "SessionState", mach.sessionState)))
    951         except Exception as e:
     950                print "%sMachine '%s' [%s], machineState=%s, sessionState=%s" % (tele, colVm(ctx, mach.name), mach.id, asEnumElem(ctx, "MachineState", mach.state), asEnumElem(ctx, "SessionState", mach.sessionState))
     951        except Exception, e:
    952952            printErr(ctx, e)
    953953            if g_fVerbose:
     
    956956
    957957def infoCmd(ctx, args):
    958     if len(args) < 2:
    959         print("usage: info [vmname|uuid]")
     958    if (len(args) < 2):
     959        print "usage: info [vmname|uuid]"
    960960        return 0
    961961    mach = argsToMach(ctx, args)
     
    963963        return 0
    964964    vmos = ctx['vb'].getGuestOSType(mach.OSTypeId)
    965     print(" One can use setvar <mach> <var> <value> to change variable, using name in [].")
    966     print("  Name [name]: %s" % (colVm(ctx, mach.name)))
    967     print("  Description [description]: %s" % (mach.description))
    968     print("  ID [n/a]: %s" % (mach.id))
    969     print("  OS Type [via OSTypeId]: %s" % (vmos.description))
    970     print("  Firmware [firmwareType]: %s (%s)" % (asEnumElem(ctx, "FirmwareType", mach.firmwareType), mach.firmwareType))
    971     print()
    972     print("  CPUs [CPUCount]: %d" % (mach.CPUCount))
    973     print("  RAM [memorySize]: %dM" % (mach.memorySize))
    974     print("  VRAM [VRAMSize]: %dM" % (mach.VRAMSize))
    975     print("  Monitors [monitorCount]: %d" % (mach.monitorCount))
    976     print("  Chipset [chipsetType]: %s (%s)" % (asEnumElem(ctx, "ChipsetType", mach.chipsetType), mach.chipsetType))
    977     print()
    978     print("  Clipboard mode [clipboardMode]: %s (%s)" % (asEnumElem(ctx, "ClipboardMode", mach.clipboardMode), mach.clipboardMode))
    979     print("  Machine status [n/a]: %s (%s)" % (asEnumElem(ctx, "SessionState", mach.sessionState), mach.sessionState))
    980     print()
     965    print " One can use setvar <mach> <var> <value> to change variable, using name in []."
     966    print "  Name [name]: %s" % (colVm(ctx, mach.name))
     967    print "  Description [description]: %s" % (mach.description)
     968    print "  ID [n/a]: %s" % (mach.id)
     969    print "  OS Type [via OSTypeId]: %s" % (vmos.description)
     970    print "  Firmware [firmwareType]: %s (%s)" % (asEnumElem(ctx, "FirmwareType", mach.firmwareType), mach.firmwareType)
     971    print
     972    print "  CPUs [CPUCount]: %d" % (mach.CPUCount)
     973    print "  RAM [memorySize]: %dM" % (mach.memorySize)
     974    print "  VRAM [VRAMSize]: %dM" % (mach.VRAMSize)
     975    print "  Monitors [monitorCount]: %d" % (mach.monitorCount)
     976    print "  Chipset [chipsetType]: %s (%s)" % (asEnumElem(ctx, "ChipsetType", mach.chipsetType), mach.chipsetType)
     977    print
     978    print "  Clipboard mode [clipboardMode]: %s (%s)" % (asEnumElem(ctx, "ClipboardMode", mach.clipboardMode), mach.clipboardMode)
     979    print "  Machine status [n/a]: %s (%s)" % (asEnumElem(ctx, "SessionState", mach.sessionState), mach.sessionState)
     980    print
    981981    if mach.teleporterEnabled:
    982         print("  Teleport target on port %d (%s)" % (mach.teleporterPort, mach.teleporterPassword))
    983         print()
     982        print "  Teleport target on port %d (%s)" % (mach.teleporterPort, mach.teleporterPassword)
     983        print
    984984    bios = mach.BIOSSettings
    985     print("  ACPI [BIOSSettings.ACPIEnabled]: %s" % (asState(bios.ACPIEnabled)))
    986     print("  APIC [BIOSSettings.IOAPICEnabled]: %s" % (asState(bios.IOAPICEnabled)))
     985    print "  ACPI [BIOSSettings.ACPIEnabled]: %s" % (asState(bios.ACPIEnabled))
     986    print "  APIC [BIOSSettings.IOAPICEnabled]: %s" % (asState(bios.IOAPICEnabled))
    987987    hwVirtEnabled = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled)
    988     print("  Hardware virtualization [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_Enabled, value)]: " + asState(hwVirtEnabled))
     988    print "  Hardware virtualization [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_Enabled, value)]: " + asState(hwVirtEnabled)
    989989    hwVirtVPID = mach.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_VPID)
    990     print("  VPID support [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_VPID, value)]: " + asState(hwVirtVPID))
     990    print "  VPID support [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_VPID, value)]: " + asState(hwVirtVPID)
    991991    hwVirtNestedPaging = mach.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_NestedPaging)
    992     print("  Nested paging [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_NestedPaging, value)]: " + asState(hwVirtNestedPaging))
    993 
    994     print("  Hardware 3d acceleration [accelerate3DEnabled]: " + asState(mach.accelerate3DEnabled))
    995     print("  Hardware 2d video acceleration [accelerate2DVideoEnabled]: " + asState(mach.accelerate2DVideoEnabled))
    996 
    997     print("  Use universal time [RTCUseUTC]: %s" % (asState(mach.RTCUseUTC)))
    998     print("  HPET [HPETEnabled]: %s" % (asState(mach.HPETEnabled)))
     992    print "  Nested paging [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_NestedPaging, value)]: " + asState(hwVirtNestedPaging)
     993
     994    print "  Hardware 3d acceleration [accelerate3DEnabled]: " + asState(mach.accelerate3DEnabled)
     995    print "  Hardware 2d video acceleration [accelerate2DVideoEnabled]: " + asState(mach.accelerate2DVideoEnabled)
     996
     997    print "  Use universal time [RTCUseUTC]: %s" % (asState(mach.RTCUseUTC))
     998    print "  HPET [HPETEnabled]: %s" % (asState(mach.HPETEnabled))
    999999    if mach.audioAdapter.enabled:
    1000         print("  Audio [via audioAdapter]: chip %s; host driver %s" % (asEnumElem(ctx, "AudioControllerType", mach.audioAdapter.audioController), asEnumElem(ctx, "AudioDriverType",  mach.audioAdapter.audioDriver)))
    1001     print("  CPU hotplugging [CPUHotPlugEnabled]: %s" % (asState(mach.CPUHotPlugEnabled)))
    1002 
    1003     print("  Keyboard [keyboardHIDType]: %s (%s)" % (asEnumElem(ctx, "KeyboardHIDType", mach.keyboardHIDType), mach.keyboardHIDType))
    1004     print("  Pointing device [pointingHIDType]: %s (%s)" % (asEnumElem(ctx, "PointingHIDType", mach.pointingHIDType), mach.pointingHIDType))
    1005     print("  Last changed [n/a]: " + time.asctime(time.localtime(mach.lastStateChange/1000)))
     1000        print "  Audio [via audioAdapter]: chip %s; host driver %s" % (asEnumElem(ctx, "AudioControllerType", mach.audioAdapter.audioController), asEnumElem(ctx, "AudioDriverType",  mach.audioAdapter.audioDriver))
     1001    print "  CPU hotplugging [CPUHotPlugEnabled]: %s" % (asState(mach.CPUHotPlugEnabled))
     1002
     1003    print "  Keyboard [keyboardHIDType]: %s (%s)" % (asEnumElem(ctx, "KeyboardHIDType", mach.keyboardHIDType), mach.keyboardHIDType)
     1004    print "  Pointing device [pointingHIDType]: %s (%s)" % (asEnumElem(ctx, "PointingHIDType", mach.pointingHIDType), mach.pointingHIDType)
     1005    print "  Last changed [n/a]: " + time.asctime(time.localtime(long(mach.lastStateChange)/1000))
    10061006    # OSE has no VRDE
    10071007    try:
    1008         print("  VRDE server [VRDEServer.enabled]: %s" % (asState(mach.VRDEServer.enabled)))
     1008        print "  VRDE server [VRDEServer.enabled]: %s" % (asState(mach.VRDEServer.enabled))
    10091009    except:
    10101010        pass
    10111011
    1012     print()
    1013     print(colCat(ctx, "  USB Controllers:"))
     1012    print
     1013    print colCat(ctx, "  USB Controllers:")
    10141014    for oUsbCtrl in ctx['global'].getArray(mach, 'USBControllers'):
    1015         print("    '%s': type %s  standard: %#x" \
    1016             % (oUsbCtrl.name, asEnumElem(ctx, "USBControllerType", oUsbCtrl.type), oUsbCtrl.USBStandard))
    1017 
    1018     print()
    1019     print(colCat(ctx, "  I/O subsystem info:"))
    1020     print("   Cache enabled [IOCacheEnabled]: %s" % (asState(mach.IOCacheEnabled)))
    1021     print("   Cache size [IOCacheSize]: %dM" % (mach.IOCacheSize))
     1015        print "    '%s': type %s  standard: %#x" \
     1016            % (oUsbCtrl.name, asEnumElem(ctx, "USBControllerType", oUsbCtrl.type), oUsbCtrl.USBStandard);
     1017
     1018    print
     1019    print colCat(ctx, "  I/O subsystem info:")
     1020    print "   Cache enabled [IOCacheEnabled]: %s" % (asState(mach.IOCacheEnabled))
     1021    print "   Cache size [IOCacheSize]: %dM" % (mach.IOCacheSize)
    10221022
    10231023    controllers = ctx['global'].getArray(mach, 'storageControllers')
    10241024    if controllers:
    1025         print()
    1026         print(colCat(ctx, "  Storage Controllers:"))
     1025        print
     1026        print colCat(ctx, "  Storage Controllers:")
    10271027    for controller in controllers:
    1028         print("    '%s': bus %s type %s" % (controller.name, asEnumElem(ctx, "StorageBus", controller.bus), asEnumElem(ctx, "StorageControllerType", controller.controllerType)))
     1028        print "    '%s': bus %s type %s" % (controller.name, asEnumElem(ctx, "StorageBus", controller.bus), asEnumElem(ctx, "StorageControllerType", controller.controllerType))
    10291029
    10301030    attaches = ctx['global'].getArray(mach, 'mediumAttachments')
    10311031    if attaches:
    1032         print()
    1033         print(colCat(ctx, "  Media:"))
     1032        print
     1033        print colCat(ctx, "  Media:")
    10341034    for a in attaches:
    1035         print("   Controller: '%s' port/device: %d:%d type: %s (%s):" % (a.controller, a.port, a.device, asEnumElem(ctx, "DeviceType", a.type), a.type))
     1035        print "   Controller: '%s' port/device: %d:%d type: %s (%s):" % (a.controller, a.port, a.device, asEnumElem(ctx, "DeviceType", a.type), a.type)
    10361036        medium = a.medium
    10371037        if a.type == ctx['global'].constants.DeviceType_HardDisk:
    1038             print("   HDD:")
    1039             print("    Id: %s" % (medium.id))
    1040             print("    Location: %s" % (colPath(ctx, medium.location)))
    1041             print("    Name: %s" % (medium.name))
    1042             print("    Format: %s" % (medium.format))
     1038            print "   HDD:"
     1039            print "    Id: %s" % (medium.id)
     1040            print "    Location: %s" % (colPath(ctx, medium.location))
     1041            print "    Name: %s" % (medium.name)
     1042            print "    Format: %s" % (medium.format)
    10431043
    10441044        if a.type == ctx['global'].constants.DeviceType_DVD:
    1045             print("   DVD:")
     1045            print "   DVD:"
    10461046            if medium:
    1047                 print("    Id: %s" % (medium.id))
    1048                 print("    Name: %s" % (medium.name))
     1047                print "    Id: %s" % (medium.id)
     1048                print "    Name: %s" % (medium.name)
    10491049                if medium.hostDrive:
    1050                     print("    Host DVD %s" % (colPath(ctx, medium.location)))
     1050                    print "    Host DVD %s" % (colPath(ctx, medium.location))
    10511051                    if a.passthrough:
    1052                         print("    [passthrough mode]")
     1052                        print "    [passthrough mode]"
    10531053                else:
    1054                     print("    Virtual image at %s" % (colPath(ctx, medium.location)))
    1055                     print("    Size: %s" % (medium.size))
     1054                    print "    Virtual image at %s" % (colPath(ctx, medium.location))
     1055                    print "    Size: %s" % (medium.size)
    10561056
    10571057        if a.type == ctx['global'].constants.DeviceType_Floppy:
    1058             print("   Floppy:")
     1058            print "   Floppy:"
    10591059            if medium:
    1060                 print("    Id: %s" % (medium.id))
    1061                 print("    Name: %s" % (medium.name))
     1060                print "    Id: %s" % (medium.id)
     1061                print "    Name: %s" % (medium.name)
    10621062                if medium.hostDrive:
    1063                     print("    Host floppy %s" % (colPath(ctx, medium.location)))
     1063                    print "    Host floppy %s" % (colPath(ctx, medium.location))
    10641064                else:
    1065                     print("    Virtual image at %s" % (colPath(ctx, medium.location)))
    1066                     print("    Size: %s" % (medium.size))
    1067 
    1068     print()
    1069     print(colCat(ctx, "  Shared folders:"))
     1065                    print "    Virtual image at %s" % (colPath(ctx, medium.location))
     1066                    print "    Size: %s" % (medium.size)
     1067
     1068    print
     1069    print colCat(ctx, "  Shared folders:")
    10701070    for sf in ctx['global'].getArray(mach, 'sharedFolders'):
    10711071        printSf(ctx, sf)
     
    10751075def startCmd(ctx, args):
    10761076    if len(args) < 2:
    1077         print("usage: start name <frontend>")
     1077        print "usage: start name <frontend>"
    10781078        return 0
    10791079    mach = argsToMach(ctx, args)
     
    10881088
    10891089def createVmCmd(ctx, args):
    1090     if len(args) != 3:
    1091         print("usage: createvm name ostype")
     1090    if (len(args) != 3):
     1091        print "usage: createvm name ostype"
    10921092        return 0
    10931093    name = args[1]
     
    10961096        ctx['vb'].getGuestOSType(oskind)
    10971097    except Exception:
    1098         print('Unknown OS type:', oskind)
     1098        print 'Unknown OS type:', oskind
    10991099        return 0
    11001100    createVm(ctx, name, oskind)
     
    11021102
    11031103def ginfoCmd(ctx, args):
    1104     if len(args) < 2:
    1105         print("usage: ginfo [vmname|uuid]")
     1104    if (len(args) < 2):
     1105        print "usage: ginfo [vmname|uuid]"
    11061106        return 0
    11071107    mach = argsToMach(ctx, args)
     
    11131113def execInGuest(ctx, console, args, env, user, passwd, tmo, inputPipe=None, outputPipe=None):
    11141114    if len(args) < 1:
    1115         print("exec in guest needs at least program name")
     1115        print "exec in guest needs at least program name"
    11161116        return
    11171117    guest = console.guest
     
    11191119    # shall contain program name as argv[0]
    11201120    gargs = args
    1121     print("executing %s with args %s as %s" % (args[0], gargs, user))
     1121    print "executing %s with args %s as %s" % (args[0], gargs, user)
    11221122    flags = 0
    11231123    if inputPipe is not None:
    11241124        flags = 1 # set WaitForProcessStartOnly
    1125     print(args[0])
     1125    print args[0]
    11261126    process = guestSession.processCreate(args[0], gargs, env, [], tmo)
    1127     print("executed with pid %d" % (process.PID))
     1127    print "executed with pid %d" % (process.PID)
    11281128    if pid != 0:
    11291129        try:
     
    11611161
    11621162        except KeyboardInterrupt:
    1163             print("Interrupted.")
     1163            print "Interrupted."
    11641164            ctx['interrupt'] = True
    11651165            if progress.cancelable:
    11661166                progress.cancel()
    11671167        (_reason, code, _flags) = guest.getProcessStatus(pid)
    1168         print("Exit code: %d" % (code))
     1168        print "Exit code: %d" % (code)
    11691169        return 0
    11701170    else:
     
    11751175    dst = args[1]
    11761176    flags = 0
    1177     print("Copying host %s to guest %s" % (src, dst))
     1177    print "Copying host %s to guest %s" % (src, dst)
    11781178    progress = console.guest.copyToGuest(src, dst, user, passwd, flags)
    11791179    progressBar(ctx, progress)
     
    11961196    user = getpass.getuser()
    11971197    user_inp = nh_raw_input("User (%s): " % (user))
    1198     if len(user_inp) > 0:
     1198    if len (user_inp) > 0:
    11991199        user = user_inp
    12001200    passwd = getpass.getpass()
     
    12031203
    12041204def gexecCmd(ctx, args):
    1205     if len(args) < 2:
    1206         print("usage: gexec [vmname|uuid] command args")
     1205    if (len(args) < 2):
     1206        print "usage: gexec [vmname|uuid] command args"
    12071207        return 0
    12081208    mach = argsToMach(ctx, args)
     
    12171217
    12181218def gcopyCmd(ctx, args):
    1219     if len(args) < 2:
    1220         print("usage: gcopy [vmname|uuid] host_path guest_path")
     1219    if (len(args) < 2):
     1220        print "usage: gcopy [vmname|uuid] host_path guest_path"
    12211221        return 0
    12221222    mach = argsToMach(ctx, args)
     
    12361236
    12371237def gpipeCmd(ctx, args):
    1238     if len(args) < 4:
    1239         print("usage: gpipe [vmname|uuid] hostProgram guestProgram, such as gpipe linux  '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'")
     1238    if (len(args) < 4):
     1239        print "usage: gpipe [vmname|uuid] hostProgram guestProgram, such as gpipe linux  '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'"
    12401240        return 0
    12411241    mach = argsToMach(ctx, args)
     
    13091309
    13101310def guestCmd(ctx, args):
    1311     if len(args) < 3:
    1312         print("usage: guest name commands")
     1311    if (len(args) < 3):
     1312        print "usage: guest name commands"
    13131313        return 0
    13141314    mach = argsToMach(ctx, args)
     
    13221322
    13231323def screenshotCmd(ctx, args):
    1324     if len(args) < 2:
    1325         print("usage: screenshot vm <file> <width> <height> <monitor>")
     1324    if (len(args) < 2):
     1325        print "usage: screenshot vm <file> <width> <height> <monitor>"
    13261326        return 0
    13271327    mach = argsToMach(ctx, args)
     
    13321332
    13331333def teleportCmd(ctx, args):
    1334     if len(args) < 3:
    1335         print("usage: teleport name host:port <password>")
     1334    if (len(args) < 3):
     1335        print "usage: teleport name host:port <password>"
    13361336        return 0
    13371337    mach = argsToMach(ctx, args)
     
    13511351
    13521352def openportalCmd(ctx, args):
    1353     if len(args) < 3:
    1354         print("usage: openportal name port <password>")
     1353    if (len(args) < 3):
     1354        print "usage: openportal name port <password>"
    13551355        return 0
    13561356    mach = argsToMach(ctx, args)
     
    13581358        return 0
    13591359    port = int(args[2])
    1360     if len(args) > 3:
     1360    if (len(args) > 3):
    13611361        passwd = args[3]
    13621362    else:
     
    13681368
    13691369def closeportalCmd(ctx, args):
    1370     if len(args) < 2:
    1371         print("usage: closeportal name")
     1370    if (len(args) < 2):
     1371        print "usage: closeportal name"
    13721372        return 0
    13731373    mach = argsToMach(ctx, args)
     
    13791379
    13801380def gueststatsCmd(ctx, args):
    1381     if len(args) < 2:
    1382         print("usage: gueststats name <check interval>")
     1381    if (len(args) < 2):
     1382        print "usage: gueststats name <check interval>"
    13831383        return 0
    13841384    mach = argsToMach(ctx, args)
     
    13921392    cpu = args[1]
    13931393    if plug:
    1394         print("Adding CPU %d..." % (cpu))
     1394        print "Adding CPU %d..." % (cpu)
    13951395        mach.hotPlugCPU(cpu)
    13961396    else:
    1397         print("Removing CPU %d..." % (cpu))
     1397        print "Removing CPU %d..." % (cpu)
    13981398        mach.hotUnplugCPU(cpu)
    13991399
    14001400def plugcpuCmd(ctx, args):
    1401     if len(args) < 2:
    1402         print("usage: plugcpu name cpuid")
     1401    if (len(args) < 2):
     1402        print "usage: plugcpu name cpuid"
    14031403        return 0
    14041404    mach = argsToMach(ctx, args)
     
    14131413
    14141414def unplugcpuCmd(ctx, args):
    1415     if len(args) < 2:
    1416         print("usage: unplugcpu name cpuid")
     1415    if (len(args) < 2):
     1416        print "usage: unplugcpu name cpuid"
    14171417        return 0
    14181418    mach = argsToMach(ctx, args)
     
    14281428def setvar(_ctx, _mach, args):
    14291429    expr = 'mach.'+args[0]+' = '+args[1]
    1430     print("Executing", expr)
    1431     exec(expr)
     1430    print "Executing", expr
     1431    exec expr
    14321432
    14331433def setvarCmd(ctx, args):
    1434     if len(args) < 4:
    1435         print("usage: setvar [vmname|uuid] expr value")
     1434    if (len(args) < 4):
     1435        print "usage: setvar [vmname|uuid] expr value"
    14361436        return 0
    14371437    mach = argsToMach(ctx, args)
     
    14441444    key = args[0]
    14451445    value = args[1]
    1446     print("%s: setting %s to %s" % (mach.name, key, value if value else None))
     1446    print "%s: setting %s to %s" % (mach.name, key, value if value else None)
    14471447    mach.setExtraData(key, value)
    14481448
    14491449def setExtraDataCmd(ctx, args):
    1450     if len(args) < 3:
    1451         print("usage: setextra [vmname|uuid|global] key <value>")
     1450    if (len(args) < 3):
     1451        print "usage: setextra [vmname|uuid|global] key <value>"
    14521452        return 0
    14531453    key = args[2]
     
    14671467
    14681468def printExtraKey(obj, key, value):
    1469     print("%s: '%s' = '%s'" % (obj, key, value))
     1469    print "%s: '%s' = '%s'" % (obj, key, value)
    14701470
    14711471def getExtraDataCmd(ctx, args):
    1472     if len(args) < 2:
    1473         print("usage: getextra [vmname|uuid|global] <key>")
     1472    if (len(args) < 2):
     1473        print "usage: getextra [vmname|uuid|global] <key>"
    14741474        return 0
    14751475    if len(args) == 3:
     
    14981498
    14991499def aliasCmd(ctx, args):
    1500     if len(args) == 3:
     1500    if (len(args) == 3):
    15011501        aliases[args[1]] = args[2]
    15021502        return 0
    15031503
    1504     for (key, value) in list(aliases.items()):
    1505         print("'%s' is an alias for '%s'" % (key, value))
     1504    for (key, value) in aliases.items():
     1505        print "'%s' is an alias for '%s'" % (key, value)
    15061506    return 0
    15071507
    15081508def verboseCmd(ctx, args):
    15091509    global g_fVerbose
    1510     if len(args) > 1:
     1510    if (len(args) > 1):
    15111511        g_fVerbose = (args[1]=='on')
    15121512    else:
     
    15161516def colorsCmd(ctx, args):
    15171517    global g_fHasColors
    1518     if len(args) > 1:
     1518    if (len(args) > 1):
    15191519        g_fHasColors = (args[1] == 'on')
    15201520    else:
     
    15251525    vbox = ctx['vb']
    15261526    try:
    1527         print("VirtualBox version %s" % (colored(vbox.version, 'blue')))
    1528     except Exception as e:
     1527        print "VirtualBox version %s" % (colored(vbox.version, 'blue'))
     1528    except Exception, e:
    15291529        printErr(ctx, e)
    15301530        if g_fVerbose:
    15311531            traceback.print_exc()
    15321532    props = vbox.systemProperties
    1533     print("Machines: %s" % (colPath(ctx, props.defaultMachineFolder)))
    1534 
    1535     #print("Global shared folders:")
     1533    print "Machines: %s" % (colPath(ctx, props.defaultMachineFolder))
     1534
     1535    #print "Global shared folders:"
    15361536    #for ud in ctx['global'].getArray(vbox, 'sharedFolders'):
    15371537    #    printSf(ctx, sf)
    15381538    host = vbox.host
    15391539    cnt = host.processorCount
    1540     print(colCat(ctx, "Processors:"))
    1541     print("  available/online: %d/%d " % (cnt, host.processorOnlineCount))
     1540    print colCat(ctx, "Processors:")
     1541    print "  available/online: %d/%d " % (cnt, host.processorOnlineCount)
    15421542    for i in range(0, cnt):
    1543         print("  processor #%d speed: %dMHz %s" % (i, host.getProcessorSpeed(i), host.getProcessorDescription(i)))
    1544 
    1545     print(colCat(ctx, "RAM:"))
    1546     print("  %dM (free %dM)" % (host.memorySize, host.memoryAvailable))
    1547     print(colCat(ctx, "OS:"))
    1548     print("  %s (%s)" % (host.operatingSystem, host.OSVersion))
     1543        print "  processor #%d speed: %dMHz %s" % (i, host.getProcessorSpeed(i), host.getProcessorDescription(i))
     1544
     1545    print colCat(ctx, "RAM:")
     1546    print "  %dM (free %dM)" % (host.memorySize, host.memoryAvailable)
     1547    print colCat(ctx, "OS:")
     1548    print "  %s (%s)" % (host.operatingSystem, host.OSVersion)
    15491549    if host.acceleration3DAvailable:
    1550         print(colCat(ctx, "3D acceleration available"))
    1551     else:
    1552         print(colCat(ctx, "3D acceleration NOT available"))
    1553 
    1554     print(colCat(ctx, "Network interfaces:"))
     1550        print colCat(ctx, "3D acceleration available")
     1551    else:
     1552        print colCat(ctx, "3D acceleration NOT available")
     1553
     1554    print colCat(ctx, "Network interfaces:")
    15551555    for ni in ctx['global'].getArray(host, 'networkInterfaces'):
    1556         print("  %s (%s)" % (ni.name, ni.IPAddress))
    1557 
    1558     print(colCat(ctx, "DVD drives:"))
     1556        print "  %s (%s)" % (ni.name, ni.IPAddress)
     1557
     1558    print colCat(ctx, "DVD drives:")
    15591559    for dd in ctx['global'].getArray(host, 'DVDDrives'):
    1560         print("  %s - %s" % (dd.name, dd.description))
    1561 
    1562     print(colCat(ctx, "Floppy drives:"))
     1560        print "  %s - %s" % (dd.name, dd.description)
     1561
     1562    print colCat(ctx, "Floppy drives:")
    15631563    for dd in ctx['global'].getArray(host, 'floppyDrives'):
    1564         print("  %s - %s" % (dd.name, dd.description))
    1565 
    1566     print(colCat(ctx, "USB devices:"))
     1564        print "  %s - %s" % (dd.name, dd.description)
     1565
     1566    print colCat(ctx, "USB devices:")
    15671567    for ud in ctx['global'].getArray(host, 'USBDevices'):
    15681568        printHostUsbDev(ctx, ud)
     
    15701570    if ctx['perf']:
    15711571        for metric in ctx['perf'].query(["*"], [host]):
    1572             print(metric['name'], metric['values_as_string'])
     1572            print metric['name'], metric['values_as_string']
    15731573
    15741574    return 0
    15751575
    15761576def monitorGuestCmd(ctx, args):
    1577     if len(args) < 2:
    1578         print("usage: monitorGuest name (duration)")
     1577    if (len(args) < 2):
     1578        print "usage: monitorGuest name (duration)"
    15791579        return 0
    15801580    mach = argsToMach(ctx, args)
     
    15891589
    15901590def monitorGuestKbdCmd(ctx, args):
    1591     if len(args) < 2:
    1592         print("usage: monitorGuestKbd name (duration)")
     1591    if (len(args) < 2):
     1592        print "usage: monitorGuestKbd name (duration)"
    15931593        return 0
    15941594    mach = argsToMach(ctx, args)
     
    16031603
    16041604def monitorGuestMouseCmd(ctx, args):
    1605     if len(args) < 2:
    1606         print("usage: monitorGuestMouse name (duration)")
     1605    if (len(args) < 2):
     1606        print "usage: monitorGuestMouse name (duration)"
    16071607        return 0
    16081608    mach = argsToMach(ctx, args)
     
    16171617
    16181618def monitorGuestMultiTouchCmd(ctx, args):
    1619     if len(args) < 2:
    1620         print("usage: monitorGuestMultiTouch name (duration)")
     1619    if (len(args) < 2):
     1620        print "usage: monitorGuestMultiTouch name (duration)"
    16211621        return 0
    16221622    mach = argsToMach(ctx, args)
     
    16311631
    16321632def monitorVBoxCmd(ctx, args):
    1633     if len(args) > 2:
    1634         print("usage: monitorVBox (duration)")
     1633    if (len(args) > 2):
     1634        print "usage: monitorVBox (duration)"
    16351635        return 0
    16361636    dur = 5
     
    16591659
    16601660def portForwardCmd(ctx, args):
    1661     if len(args) != 5:
    1662         print("usage: portForward <vm> <adapter> <hostPort> <guestPort>")
     1661    if (len(args) != 5):
     1662        print "usage: portForward <vm> <adapter> <hostPort> <guestPort>"
    16631663        return 0
    16641664    mach = argsToMach(ctx, args)
     
    16901690
    16911691def showLogCmd(ctx, args):
    1692     if len(args) < 2:
    1693         print("usage: showLog vm <num>")
     1692    if (len(args) < 2):
     1693        print "usage: showLog vm <num>"
    16941694        return 0
    16951695    mach = argsToMach(ctx, args)
     
    16981698
    16991699    log = 0
    1700     if len(args) > 2:
     1700    if (len(args) > 2):
    17011701        log = args[2]
    17021702
     
    17041704    while True:
    17051705        data = mach.readLog(log, uOffset, 4096)
    1706         if len(data) == 0:
     1706        if (len(data) == 0):
    17071707            break
    17081708        # print adds either NL or space to chunks not ending with a NL
     
    17131713
    17141714def findLogCmd(ctx, args):
    1715     if len(args) < 3:
    1716         print("usage: findLog vm pattern <num>")
     1715    if (len(args) < 3):
     1716        print "usage: findLog vm pattern <num>"
    17171717        return 0
    17181718    mach = argsToMach(ctx, args)
     
    17211721
    17221722    log = 0
    1723     if len(args) > 3:
     1723    if (len(args) > 3):
    17241724        log = args[3]
    17251725
     
    17291729        # to reduce line splits on buffer boundary
    17301730        data = mach.readLog(log, uOffset, 512*1024)
    1731         if len(data) == 0:
     1731        if (len(data) == 0):
    17321732            break
    17331733        d = str(data).split("\n")
     
    17371737                for mt in match:
    17381738                    s = s.replace(mt, colored(mt, 'red'))
    1739                 print(s)
     1739                print s
    17401740        uOffset += len(data)
    17411741
     
    17441744
    17451745def findAssertCmd(ctx, args):
    1746     if len(args) < 2:
    1747         print("usage: findAssert vm <num>")
     1746    if (len(args) < 2):
     1747        print "usage: findAssert vm <num>"
    17481748        return 0
    17491749    mach = argsToMach(ctx, args)
     
    17521752
    17531753    log = 0
    1754     if len(args) > 2:
     1754    if (len(args) > 2):
    17551755        log = args[2]
    17561756
     
    17621762        # to reduce line splits on buffer boundary
    17631763        data = mach.readLog(log, uOffset, 512*1024)
    1764         if len(data) == 0:
     1764        if (len(data) == 0):
    17651765            break
    17661766        d = str(data).split("\n")
    17671767        for s in d:
    17681768            if active:
    1769                 print(s)
     1769                print s
    17701770                if context == 0:
    17711771                    active = False
     
    17771777                active = True
    17781778                context = 50
    1779                 print(s)
     1779                print s
    17801780        uOffset += len(data)
    17811781
     
    17851785    expr = ' '.join(args[1:])
    17861786    try:
    1787         exec(expr)
    1788     except Exception as e:
     1787        exec expr
     1788    except Exception, e:
    17891789        printErr(ctx, e)
    17901790        if g_fVerbose:
     
    17991799
    18001800def runScriptCmd(ctx, args):
    1801     if len(args) != 2:
    1802         print("usage: runScript <script>")
     1801    if (len(args) != 2):
     1802        print "usage: runScript <script>"
    18031803        return 0
    18041804    try:
    18051805        lf = open(args[1], 'r')
    1806     except IOError as e:
    1807         print("cannot open:", args[1], ":", e)
     1806    except IOError, e:
     1807        print "cannot open:", args[1], ":", e
    18081808        return 0
    18091809
     
    18191819                break
    18201820
    1821     except Exception as e:
     1821    except Exception, e:
    18221822        printErr(ctx, e)
    18231823        if g_fVerbose:
     
    18271827
    18281828def sleepCmd(ctx, args):
    1829     if len(args) != 2:
    1830         print("usage: sleep <secs>")
     1829    if (len(args) != 2):
     1830        print "usage: sleep <secs>"
    18311831        return 0
    18321832
     
    18401840
    18411841def shellCmd(ctx, args):
    1842     if len(args) < 2:
    1843         print("usage: shell <commands>")
     1842    if (len(args) < 2):
     1843        print "usage: shell <commands>"
    18441844        return 0
    18451845    cmd = ' '.join(args[1:])
     
    18541854
    18551855def connectCmd(ctx, args):
    1856     if len(args) > 4:
    1857         print("usage: connect url <username> <passwd>")
     1856    if (len(args) > 4):
     1857        print "usage: connect url <username> <passwd>"
    18581858        return 0
    18591859
    18601860    if ctx['vb'] is not None:
    1861         print("Already connected, disconnect first...")
    1862         return 0
    1863 
    1864     if len(args) > 1:
     1861        print "Already connected, disconnect first..."
     1862        return 0
     1863
     1864    if (len(args) > 1):
    18651865        url = args[1]
    18661866    else:
    18671867        url = None
    18681868
    1869     if len(args) > 2:
     1869    if (len(args) > 2):
    18701870        user = args[2]
    18711871    else:
    18721872        user = ""
    18731873
    1874     if len(args) > 3:
     1874    if (len(args) > 3):
    18751875        passwd = args[3]
    18761876    else:
     
    18811881    ctx['vb'] = vbox
    18821882    try:
    1883         print("Running VirtualBox version %s" % (vbox.version))
    1884     except Exception as e:
     1883        print "Running VirtualBox version %s" % (vbox.version)
     1884    except Exception, e:
    18851885        printErr(ctx, e)
    18861886        if g_fVerbose:
     
    18901890
    18911891def disconnectCmd(ctx, args):
    1892     if len(args) != 1:
    1893         print("usage: disconnect")
     1892    if (len(args) != 1):
     1893        print "usage: disconnect"
    18941894        return 0
    18951895
    18961896    if ctx['vb'] is None:
    1897         print("Not connected yet.")
     1897        print "Not connected yet."
    18981898        return 0
    18991899
     
    19091909def reconnectCmd(ctx, args):
    19101910    if ctx['wsinfo'] is None:
    1911         print("Never connected...")
     1911        print "Never connected..."
    19121912        return 0
    19131913
     
    19201920    ctx['vb'] = ctx['global'].platform.connect(url, user, passwd)
    19211921    try:
    1922         print("Running VirtualBox version %s" % (ctx['vb'].version))
    1923     except Exception as e:
     1922        print "Running VirtualBox version %s" % (ctx['vb'].version)
     1923    except Exception, e:
    19241924        printErr(ctx, e)
    19251925        if g_fVerbose:
     
    19291929def exportVMCmd(ctx, args):
    19301930    if len(args) < 3:
    1931         print("usage: exportVm <machine> <path> <format> <license>")
     1931        print "usage: exportVm <machine> <path> <format> <license>"
    19321932        return 0
    19331933    mach = argsToMach(ctx, args)
     
    19351935        return 0
    19361936    path = args[2]
    1937     if len(args) > 3:
     1937    if (len(args) > 3):
    19381938        fmt = args[3]
    19391939    else:
    19401940        fmt = "ovf-1.0"
    1941     if len(args) > 4:
     1941    if (len(args) > 4):
    19421942        lic = args[4]
    19431943    else:
     
    19491949    progress = app.write(fmt, path)
    19501950    if (progressBar(ctx, progress) and int(progress.resultCode) == 0):
    1951         print("Exported to %s in format %s" % (path, fmt))
     1951        print "Exported to %s in format %s" % (path, fmt)
    19521952    else:
    19531953        reportError(ctx, progress)
     
    20532053    extCode = extScancodes.get(ch, [])
    20542054    if len(extCode) == 0:
    2055         print("bad ext", ch)
     2055        print "bad ext", ch
    20562056    return extCode
    20572057
     
    21252125def typeGuestCmd(ctx, args):
    21262126    if len(args) < 3:
    2127         print("usage: typeGuest <machine> <text> <charDelay>")
     2127        print "usage: typeGuest <machine> <text> <charDelay>"
    21282128        return 0
    21292129    mach = argsToMach(ctx, args)
     
    21612161        verbose = False
    21622162    hdds = ctx['global'].getArray(ctx['vb'], 'hardDisks')
    2163     print(colCat(ctx, "Hard disks:"))
     2163    print colCat(ctx, "Hard disks:")
    21642164    for hdd in hdds:
    21652165        if hdd.state != ctx['global'].constants.MediumState_Created:
    21662166            hdd.refreshState()
    2167         print("   %s (%s)%s %s [logical %s]" % (colPath(ctx, hdd.location), hdd.format, optId(verbose, hdd.id), colSizeM(ctx, asSize(hdd.size, True)), colSizeM(ctx, asSize(hdd.logicalSize, True))))
     2167        print "   %s (%s)%s %s [logical %s]" % (colPath(ctx, hdd.location), hdd.format, optId(verbose, hdd.id), colSizeM(ctx, asSize(hdd.size, True)), colSizeM(ctx, asSize(hdd.logicalSize, True)))
    21682168
    21692169    dvds = ctx['global'].getArray(ctx['vb'], 'DVDImages')
    2170     print(colCat(ctx, "CD/DVD disks:"))
     2170    print colCat(ctx, "CD/DVD disks:")
    21712171    for dvd in dvds:
    21722172        if dvd.state != ctx['global'].constants.MediumState_Created:
    21732173            dvd.refreshState()
    2174         print("   %s (%s)%s %s" % (colPath(ctx, dvd.location), dvd.format, optId(verbose, dvd.id), colSizeM(ctx, asSize(dvd.size, True))))
     2174        print "   %s (%s)%s %s" % (colPath(ctx, dvd.location), dvd.format, optId(verbose, dvd.id), colSizeM(ctx, asSize(dvd.size, True)))
    21752175
    21762176    floppys = ctx['global'].getArray(ctx['vb'], 'floppyImages')
    2177     print(colCat(ctx, "Floppy disks:"))
     2177    print colCat(ctx, "Floppy disks:")
    21782178    for floppy in floppys:
    21792179        if floppy.state != ctx['global'].constants.MediumState_Created:
    21802180            floppy.refreshState()
    2181         print("   %s (%s)%s %s" % (colPath(ctx, floppy.location), floppy.format, optId(verbose, floppy.id), colSizeM(ctx, asSize(floppy.size, True))))
     2181        print "   %s (%s)%s %s" % (colPath(ctx, floppy.location), floppy.format, optId(verbose, floppy.id), colSizeM(ctx, asSize(floppy.size, True)))
    21822182
    21832183    return 0
    21842184
    21852185def listUsbCmd(ctx, args):
    2186     if len(args) > 1:
    2187         print("usage: listUsb")
     2186    if (len(args) > 1):
     2187        print "usage: listUsb"
    21882188        return 0
    21892189
     
    22022202
    22032203def createHddCmd(ctx, args):
    2204     if len(args) < 3:
    2205         print("usage: createHdd sizeM location type")
     2204    if (len(args) < 3):
     2205        print "usage: createHdd sizeM location type"
    22062206        return 0
    22072207
     
    22162216    progress = hdd.createBaseStorage(size, (ctx['global'].constants.MediumVariant_Standard, ))
    22172217    if progressBar(ctx,progress) and hdd.id:
    2218         print("created HDD at %s as %s" % (colPath(ctx,hdd.location), hdd.id))
    2219     else:
    2220        print("cannot create disk (file %s exist?)" % (loc))
     2218        print "created HDD at %s as %s" % (colPath(ctx,hdd.location), hdd.id)
     2219    else:
     2220       print "cannot create disk (file %s exist?)" % (loc)
    22212221       reportError(ctx,progress)
    22222222       return 0
     
    22252225
    22262226def registerHddCmd(ctx, args):
    2227     if len(args) < 2:
    2228         print("usage: registerHdd location")
     2227    if (len(args) < 2):
     2228        print "usage: registerHdd location"
    22292229        return 0
    22302230
     
    22362236    parentId = ""
    22372237    hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
    2238     print("registered HDD as %s" % (hdd.id))
     2238    print "registered HDD as %s" % (hdd.id)
    22392239    return 0
    22402240
     
    22442244
    22452245def attachHddCmd(ctx, args):
    2246     if len(args) < 3:
    2247         print("usage: attachHdd vm hdd controller port:slot")
     2246    if (len(args) < 3):
     2247        print "usage: attachHdd vm hdd controller port:slot"
    22482248        return 0
    22492249
     
    22562256        hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
    22572257    except:
    2258         print("no HDD with path %s registered" % (loc))
     2258        print "no HDD with path %s registered" % (loc)
    22592259        return 0
    22602260    if len(args) > 3:
     
    22792279
    22802280def detachHddCmd(ctx, args):
    2281     if len(args) < 3:
    2282         print("usage: detachHdd vm hdd")
     2281    if (len(args) < 3):
     2282        print "usage: detachHdd vm hdd"
    22832283        return 0
    22842284
     
    22912291        hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
    22922292    except:
    2293         print("no HDD with path %s registered" % (loc))
     2293        print "no HDD with path %s registered" % (loc)
    22942294        return 0
    22952295
     
    22982298
    22992299def unregisterHddCmd(ctx, args):
    2300     if len(args) < 2:
    2301         print("usage: unregisterHdd path <vmunreg>")
     2300    if (len(args) < 2):
     2301        print "usage: unregisterHdd path <vmunreg>"
    23022302        return 0
    23032303
    23042304    vbox = ctx['vb']
    23052305    loc = args[1]
    2306     if len(args) > 2:
     2306    if (len(args) > 2):
    23072307        vmunreg = int(args[2])
    23082308    else:
     
    23112311        hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
    23122312    except:
    2313         print("no HDD with path %s registered" % (loc))
     2313        print "no HDD with path %s registered" % (loc)
    23142314        return 0
    23152315
     
    23182318        try:
    23192319            for mach in machs:
    2320                 print("Trying to detach from %s" % (mach))
     2320                print "Trying to detach from %s" % (mach)
    23212321                detachMedium(ctx, mach, hdd)
    2322         except Exception as e:
    2323             print('failed: ', e)
     2322        except Exception, e:
     2323            print 'failed: ', e
    23242324            return 0
    23252325    hdd.close()
     
    23272327
    23282328def removeHddCmd(ctx, args):
    2329     if len(args) != 2:
    2330         print("usage: removeHdd path")
     2329    if (len(args) != 2):
     2330        print "usage: removeHdd path"
    23312331        return 0
    23322332
     
    23362336        hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
    23372337    except:
    2338         print("no HDD with path %s registered" % (loc))
     2338        print "no HDD with path %s registered" % (loc)
    23392339        return 0
    23402340
     
    23452345
    23462346def registerIsoCmd(ctx, args):
    2347     if len(args) < 2:
    2348         print("usage: registerIso location")
     2347    if (len(args) < 2):
     2348        print "usage: registerIso location"
    23492349        return 0
    23502350
     
    23522352    loc = args[1]
    23532353    iso = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
    2354     print("registered ISO as %s" % (iso.id))
     2354    print "registered ISO as %s" % (iso.id)
    23552355    return 0
    23562356
    23572357def unregisterIsoCmd(ctx, args):
    2358     if len(args) != 2:
    2359         print("usage: unregisterIso path")
     2358    if (len(args) != 2):
     2359        print "usage: unregisterIso path"
    23602360        return 0
    23612361
     
    23652365        dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
    23662366    except:
    2367         print("no DVD with path %s registered" % (loc))
     2367        print "no DVD with path %s registered" % (loc)
    23682368        return 0
    23692369
    23702370    progress = dvd.close()
    2371     print("Unregistered ISO at %s" % (colPath(ctx, loc)))
     2371    print "Unregistered ISO at %s" % (colPath(ctx, loc))
    23722372
    23732373    return 0
    23742374
    23752375def removeIsoCmd(ctx, args):
    2376     if len(args) != 2:
    2377         print("usage: removeIso path")
     2376    if (len(args) != 2):
     2377        print "usage: removeIso path"
    23782378        return 0
    23792379
     
    23832383        dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
    23842384    except:
    2385         print("no DVD with path %s registered" % (loc))
     2385        print "no DVD with path %s registered" % (loc)
    23862386        return 0
    23872387
    23882388    progress = dvd.deleteStorage()
    23892389    if progressBar(ctx, progress):
    2390         print("Removed ISO at %s" % (colPath(ctx, dvd.location)))
     2390        print "Removed ISO at %s" % (colPath(ctx, dvd.location))
    23912391    else:
    23922392        reportError(ctx, progress)
     
    23942394
    23952395def attachIsoCmd(ctx, args):
    2396     if len(args) < 3:
    2397         print("usage: attachIso vm iso controller port:slot")
     2396    if (len(args) < 3):
     2397        print "usage: attachIso vm iso controller port:slot"
    23982398        return 0
    23992399
     
    24062406        dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
    24072407    except:
    2408         print("no DVD with path %s registered" % (loc))
     2408        print "no DVD with path %s registered" % (loc)
    24092409        return 0
    24102410    if len(args) > 3:
     
    24172417
    24182418def detachIsoCmd(ctx, args):
    2419     if len(args) < 3:
    2420         print("usage: detachIso vm iso")
     2419    if (len(args) < 3):
     2420        print "usage: detachIso vm iso"
    24212421        return 0
    24222422
     
    24292429        dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
    24302430    except:
    2431         print("no DVD with path %s registered" % (loc))
     2431        print "no DVD with path %s registered" % (loc)
    24322432        return 0
    24332433
     
    24362436
    24372437def mountIsoCmd(ctx, args):
    2438     if len(args) < 3:
    2439         print("usage: mountIso vm iso controller port:slot")
     2438    if (len(args) < 3):
     2439        print "usage: mountIso vm iso controller port:slot"
    24402440        return 0
    24412441
     
    24482448        dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
    24492449    except:
    2450         print("no DVD with path %s registered" % (loc))
     2450        print "no DVD with path %s registered" % (loc)
    24512451        return 0
    24522452
     
    24632463
    24642464def unmountIsoCmd(ctx, args):
    2465     if len(args) < 2:
    2466         print("usage: unmountIso vm controller port:slot")
     2465    if (len(args) < 2):
     2466        print "usage: unmountIso vm controller port:slot"
    24672467        return 0
    24682468
     
    24902490
    24912491def attachCtrCmd(ctx, args):
    2492     if len(args) < 4:
    2493         print("usage: attachCtr vm cname bus <type>")
     2492    if (len(args) < 4):
     2493        print "usage: attachCtr vm cname bus <type>"
    24942494        return 0
    24952495
     
    24972497        ctrltype = enumFromString(ctx, 'StorageControllerType', args[4])
    24982498        if ctrltype == None:
    2499             print("Controller type %s unknown" % (args[4]))
     2499            print "Controller type %s unknown" % (args[4])
    25002500            return 0
    25012501    else:
     
    25072507    bus = enumFromString(ctx, 'StorageBus', args[3])
    25082508    if bus is None:
    2509         print("Bus type %s unknown" % (args[3]))
     2509        print "Bus type %s unknown" % (args[3])
    25102510        return 0
    25112511    name = args[2]
     
    25142514
    25152515def detachCtrCmd(ctx, args):
    2516     if len(args) < 3:
    2517         print("usage: detachCtr vm name")
     2516    if (len(args) < 3):
     2517        print "usage: detachCtr vm name"
    25182518        return 0
    25192519
     
    25262526
    25272527def usbctr(ctx, mach, console, args):
    2528     if args[0]:
     2528    if (args[0]):
    25292529        console.attachUSBDevice(args[1], "")
    25302530    else:
     
    25322532
    25332533def attachUsbCmd(ctx, args):
    2534     if len(args) < 3:
    2535         print("usage: attachUsb vm deviceuid")
     2534    if (len(args) < 3):
     2535        print "usage: attachUsb vm deviceuid"
    25362536        return 0
    25372537
     
    25442544
    25452545def detachUsbCmd(ctx, args):
    2546     if len(args) < 3:
    2547         print("usage: detachUsb vm deviceuid")
     2546    if (len(args) < 3):
     2547        print "usage: detachUsb vm deviceuid"
    25482548        return 0
    25492549
     
    25572557
    25582558def guiCmd(ctx, args):
    2559     if len(args) > 1:
    2560         print("usage: gui")
     2559    if (len(args) > 1):
     2560        print "usage: gui"
    25612561        return 0
    25622562
     
    25722572
    25732573def shareFolderCmd(ctx, args):
    2574     if len(args) < 4:
    2575         print("usage: shareFolder vm path name <writable> <persistent>")
     2574    if (len(args) < 4):
     2575        print "usage: shareFolder vm path name <writable> <persistent>"
    25762576        return 0
    25772577
     
    25962596
    25972597def unshareFolderCmd(ctx, args):
    2598     if len(args) < 3:
    2599         print("usage: unshareFolder vm name")
     2598    if (len(args) < 3):
     2599        print "usage: unshareFolder vm name"
    26002600        return 0
    26012601
     
    26172617def snapshotCmd(ctx, args):
    26182618    if (len(args) < 2 or args[1] == 'help'):
    2619         print("Take snapshot:    snapshot vm take name <description>")
    2620         print("Restore snapshot: snapshot vm restore name")
    2621         print("Merge snapshot:   snapshot vm merge name")
     2619        print "Take snapshot:    snapshot vm take name <description>"
     2620        print "Restore snapshot: snapshot vm restore name"
     2621        print "Merge snapshot:   snapshot vm merge name"
    26222622        return 0
    26232623
     
    26272627    cmd = args[2]
    26282628    if cmd == 'take':
    2629         if len(args) < 4:
    2630             print("usage: snapshot vm take name <description>")
     2629        if (len(args) < 4):
     2630            print "usage: snapshot vm take name <description>"
    26312631            return 0
    26322632        name = args[3]
    2633         if len(args) > 4:
     2633        if (len(args) > 4):
    26342634            desc = args[4]
    26352635        else:
     
    26392639
    26402640    if cmd == 'restore':
    2641         if len(args) < 4:
    2642             print("usage: snapshot vm restore name")
     2641        if (len(args) < 4):
     2642            print "usage: snapshot vm restore name"
    26432643            return 0
    26442644        name = args[3]
     
    26482648
    26492649    if cmd == 'restorecurrent':
    2650         if len(args) < 4:
    2651             print("usage: snapshot vm restorecurrent")
     2650        if (len(args) < 4):
     2651            print "usage: snapshot vm restorecurrent"
    26522652            return 0
    26532653        snap = mach.currentSnapshot()
     
    26562656
    26572657    if cmd == 'delete':
    2658         if len(args) < 4:
    2659             print("usage: snapshot vm delete name")
     2658        if (len(args) < 4):
     2659            print "usage: snapshot vm delete name"
    26602660            return 0
    26612661        name = args[3]
     
    26642664        return 0
    26652665
    2666     print("Command '%s' is unknown" % (cmd))
     2666    print "Command '%s' is unknown" % (cmd)
    26672667    return 0
    26682668
     
    26832683        first = 0
    26842684        msg = ''
    2685         for aliasmode, aliaskey in list(alias.items()):
     2685        for aliasmode, aliaskey in alias.iteritems():
    26862686            if first == 0:
    26872687                first = 1
     
    26892689                msg += ', '
    26902690            if int(nat.aliasMode) & aliaskey:
    2691                 msg += '%s: %s' % (aliasmode, 'on')
     2691                msg += '%d: %s' % (aliasmode, 'on')
    26922692            else:
    2693                 msg += '%s: %s' % (aliasmode, 'off')
     2693                msg += '%d: %s' % (aliasmode, 'off')
     2694        msg += ')'
    26942695        return (0, [msg])
    26952696    else:
     
    26972698        if 'default' not in args:
    26982699            for a in range(1, len(args)):
    2699                 if args[a] not in alias:
    2700                     print('Invalid alias mode: ' + args[a])
    2701                     print(natAlias.__doc__)
     2700                if not alias.has_key(args[a]):
     2701                    print 'Invalid alias mode: ' + args[a]
     2702                    print natAlias.__doc__
    27022703                    return (1, None)
    27032704                nat.aliasMode = int(nat.aliasMode) | alias[args[a]]
     
    27222723    else:
    27232724        if args[1] < 16000:
    2724             print('invalid mtu value (%s not in range [65 - 16000])' % (args[1]))
     2725            print 'invalid mtu value (%s not in range [65 - 16000])' % (args[1])
    27252726            return (1, None)
    27262727        for i in range(2, len(args)):
    27272728            if not args[i].isdigit() or int(args[i]) < 8 or int(args[i]) > 1024:
    2728                 print('invalid %s parameter (%i not in range [8-1024])' % (i, args[i]))
     2729                print 'invalid %s parameter (%i not in range [8-1024])' % (i, args[i])
    27292730                return (1, None)
    27302731        a = [args[1]]
     
    27342735        else:
    27352736            for i in range(2, len(args)): a.append(args[i])
    2736         #print(a)
     2737        #print a
    27372738        nat.setNetworkSettings(int(a[0]), int(a[1]), int(a[2]), int(a[3]), int(a[4]))
    27382739    return (0, None)
     
    27852786        cmd = args[1]
    27862787        if len(args) != 3:
    2787             print('invalid args:', args)
    2788             print(natTftp.__doc__)
     2788            print 'invalid args:', args
     2789            print natTftp.__doc__
    27892790            return (1, None)
    27902791        if cmd == 'prefix': nat.TFTPPrefix = args[2]
     
    27922793        elif cmd == 'server': nat.TFTPNextServer = args[2]
    27932794        else:
    2794             print("invalid cmd:", cmd)
     2795            print "invalid cmd:", cmd
    27952796            return (1, None)
    27962797    return (0, None)
     
    28172818        pfcmd = {
    28182819            'simple': {
    2819                 'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 5,
     2820                'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 5,
    28202821                'func':lambda: nat.addRedirect('', proto[args[2]], '', int(args[3]), '', int(args[4]))
    28212822            },
    28222823            'no_name': {
    2823                 'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 7,
     2824                'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 7,
    28242825                'func': lambda: nat.addRedirect('', proto[args[2]], args[3], int(args[4]), args[5], int(args[6]))
    28252826            },
    28262827            'ex': {
    2827                 'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 8,
     2828                'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 8,
    28282829                'func': lambda: nat.addRedirect(args[3], proto[args[2]], args[4], int(args[5]), args[6], int(args[7]))
    28292830            },
     
    28352836
    28362837        if not pfcmd[args[1]]['validate']():
    2837             print('invalid port-forwarding or args of sub command ', args[1])
    2838             print(natPortForwarding.__doc__)
     2838            print 'invalid port-forwarding or args of sub command ', args[1]
     2839            print natPortForwarding.__doc__
    28392840            return (1, None)
    28402841
     
    28552856        (addr, mask) = args[1].split('/')
    28562857        if addr.count('.') > 3 or int(mask) < 0 or int(mask) > 32:
    2857             print('Invalid arguments')
     2858            print 'Invalid arguments'
    28582859            return (1, None)
    28592860        nat.network = args[1]
     
    28792880    if len(args) < 2 or args[1] == 'help':
    28802881        if len(args) > 2:
    2881             print(natcommands[args[2]].__doc__)
     2882            print natcommands[args[2]].__doc__
    28822883        else:
    2883             print(natCmd.__doc__)
     2884            print natCmd.__doc__
    28842885        return 0
    28852886    if len(args) == 1 or len(args) < 4 or args[3] not in natcommands:
    2886         print(natCmd.__doc__)
     2887        print natCmd.__doc__
    28872888        return 0
    28882889    mach = ctx['argsToMach'](args)
    28892890    if mach == None:
    2890         print("please specify vm")
    2891         return 0
    2892     if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in list(range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType))):
    2893         print('please specify adapter num %d isn\'t in range [0-%d]' % (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType)))
     2891        print "please specify vm"
     2892        return 0
     2893    if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType)):
     2894        print 'please specify adapter num %d isn\'t in range [0-%d]' % (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType))
    28942895        return 0
    28952896    nicnum = int(args[2])
     
    29182919        for r in report:
    29192920            msg ='%s nic%d %s: %s' % (mach.name, nicnum, func, r)
    2920             print(msg)
     2921            print msg
    29212922    return 0
    29222923
     
    29292930        yesno = {'off' : 0, 'on' : 1}
    29302931        if args[1] not in yesno:
    2931             print('%s isn\'t acceptable, please choose %s' % (args[1], list(yesno.keys())))
     2932            print '%s isn\'t acceptable, please choose %s' % (args[1], yesno.keys())
    29322933            return (1, None)
    29332934        adapter.__setattr__(attr, yesno[args[1]])
     
    29522953    else:
    29532954        if not args[1].isdigit():
    2954             print('%s isn\'t a number' % (args[1]))
    2955             return (1, None)
     2955            print '%s isn\'t a number' % (args[1])
     2956            print (1, None)
    29562957        adapter.lineSpeed = int(args[1])
    29572958    return (0, None)
     
    29752976    if len(args) == 1:
    29762977        nictypes = ctx['const'].all_values('NetworkAdapterType')
    2977         for key in list(nictypes.keys()):
     2978        for key in nictypes.keys():
    29782979            if str(adapter.adapterType) == str(nictypes[key]):
    29792980                return (0, str(key))
     
    29812982    else:
    29822983        nictypes = ctx['const'].all_values('NetworkAdapterType')
    2983         if args[1] not in list(nictypes.keys()):
    2984             print('%s not in acceptable values (%s)' % (args[1], list(nictypes.keys())))
     2984        if args[1] not in nictypes.keys():
     2985            print '%s not in acceptable values (%s)' % (args[1], nictypes.keys())
    29852986            return (1, None)
    29862987        adapter.adapterType = nictypes[args[1]]
     
    30013002            ctx['global'].constants.NetworkAttachmentType_Generic: ('Generic', ''),
    30023003        }
    3003         if type(adapter.attachmentType) != int:
     3004        import types
     3005        if type(adapter.attachmentType) != types.IntType:
    30043006            t = str(adapter.attachmentType)
    30053007        else:
     
    30353037                'f': lambda: ctx['global'].constants.NetworkAttachmentType_Generic}
    30363038        }
    3037         if args[1] not in list(nicAttachmentType.keys()):
    3038             print('%s not in acceptable values (%s)' % (args[1], list(nicAttachmentType.keys())))
     3039        if args[1] not in nicAttachmentType.keys():
     3040            print '%s not in acceptable values (%s)' % (args[1], nicAttachmentType.keys())
    30393041            return (1, None)
    30403042        if not nicAttachmentType[args[1]]['v']():
    3041             print(nicAttachmentType.__doc__)
     3043            print nicAttachmentType.__doc__
    30423044            return (1, None)
    30433045        nicAttachmentType[args[1]]['p']()
     
    30653067        if len(args) == 3 \
    30663068           and args[2] in niccomand:
    3067             print(niccomand[args[2]].__doc__)
     3069            print niccomand[args[2]].__doc__
    30683070        else:
    3069             print(nicCmd.__doc__)
     3071            print nicCmd.__doc__
    30703072        return 0
    30713073
    30723074    vm = ctx['argsToMach'](args)
    30733075    if vm is None:
    3074         print('please specify vm')
     3076        print 'please specify vm'
    30753077        return 0
    30763078
    30773079    if    len(args) < 3 \
    3078        or int(args[2]) not in list(range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType))):
    3079         print('please specify adapter num %d isn\'t in range [0-%d]'% (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType)))
     3080       or int(args[2]) not in range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType)):
     3081        print 'please specify adapter num %d isn\'t in range [0-%d]'% (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType))
    30803082        return 0
    30813083    nicnum = int(args[2])
     
    30903092        vm.saveSettings()
    30913093    if report is not None:
    3092         print('%s nic %d %s: %s' % (vm.name, nicnum, args[3], report))
     3094        print '%s nic %d %s: %s' % (vm.name, nicnum, args[3], report)
    30933095    session.unlockMachine()
    30943096    return 0
     
    30973099def promptCmd(ctx, args):
    30983100    if    len(args) < 2:
    3099         print("Current prompt: '%s'" % (ctx['prompt']))
     3101        print "Current prompt: '%s'" % (ctx['prompt'])
    31003102        return 0
    31013103
     
    31053107def foreachCmd(ctx, args):
    31063108    if len(args) < 3:
    3107         print("usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']")
     3109        print "usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']"
    31083110        return 0
    31093111
     
    31153117            e.apply(cmd)
    31163118    except:
    3117         print("Error executing")
     3119        print "Error executing"
    31183120        traceback.print_exc()
    31193121    return 0
     
    31213123def foreachvmCmd(ctx, args):
    31223124    if len(args) < 2:
    3123         print("foreachvm command <args>")
     3125        print "foreachvm command <args>"
    31243126        return 0
    31253127    cmdargs = args[1:]
     
    31313133
    31323134def recordDemoCmd(ctx, args):
    3133     if len(args) < 3:
    3134         print("usage: recordDemo vm filename (duration)")
     3135    if (len(args) < 3):
     3136        print "usage: recordDemo vm filename (duration)"
    31353137        return 0
    31363138    mach = argsToMach(ctx, args)
     
    31453147
    31463148def playbackDemoCmd(ctx, args):
    3147     if len(args) < 3:
    3148         print("usage: playbackDemo vm filename (duration)")
     3149    if (len(args) < 3):
     3150        print "usage: playbackDemo vm filename (duration)"
    31493151        return 0
    31503152    mach = argsToMach(ctx, args)
     
    31673169    for a in assigned:
    31683170        if a.isPhysicalDevice:
    3169             print("%s: assigned host device %s guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.hostAddress), pciAddr(ctx, a.guestAddress)))
     3171            print "%s: assigned host device %s guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.hostAddress), pciAddr(ctx, a.guestAddress))
    31703172
    31713173    atts = ctx['global'].getArray(console, 'attachedPCIDevices')
    31723174    for a in atts:
    31733175        if a.isPhysicalDevice:
    3174             print("%s: physical, guest %s, host %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress), pciAddr(ctx, a.hostAddress)))
     3176            print "%s: physical, guest %s, host %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress), pciAddr(ctx, a.hostAddress))
    31753177        else:
    3176             print("%s: virtual, guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress)))
     3178            print "%s: virtual, guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress))
    31773179    return
    31783180
     
    31863188
    31873189def lspciCmd(ctx, args):
    3188     if len(args) < 2:
    3189         print("usage: lspci vm")
     3190    if (len(args) < 2):
     3191        print "usage: lspci vm"
    31903192        return 0
    31913193    mach = argsToMach(ctx, args)
     
    31963198
    31973199def attachpciCmd(ctx, args):
    3198     if len(args) < 3:
    3199         print("usage: attachpci vm hostpci <guestpci>")
     3200    if (len(args) < 3):
     3201        print "usage: attachpci vm hostpci <guestpci>"
    32003202        return 0
    32013203    mach = argsToMach(ctx, args)
     
    32043206    hostaddr = parsePci(args[2])
    32053207    if hostaddr == -1:
    3206         print("invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2]))
    3207         return 0
    3208 
    3209     if len(args) > 3:
     3208        print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2])
     3209        return 0
     3210
     3211    if (len(args) > 3):
    32103212        guestaddr = parsePci(args[3])
    32113213        if guestaddr == -1:
    3212             print("invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[3]))
     3214            print "invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[3])
    32133215            return 0
    32143216    else:
     
    32183220
    32193221def detachpciCmd(ctx, args):
    3220     if len(args) < 3:
    3221         print("usage: detachpci vm hostpci")
     3222    if (len(args) < 3):
     3223        print "usage: detachpci vm hostpci"
    32223224        return 0
    32233225    mach = argsToMach(ctx, args)
     
    32263228    hostaddr = parsePci(args[2])
    32273229    if hostaddr == -1:
    3228         print("invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2]))
     3230        print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2])
    32293231        return 0
    32303232
     
    32333235
    32343236def gotoCmd(ctx, args):
    3235     if len(args) < 2:
    3236         print("usage: goto line")
     3237    if (len(args) < 2):
     3238        print "usage: goto line"
    32373239        return 0
    32383240
     
    32713273            'verbose':['Toggle verbosity', verboseCmd, 0],
    32723274            'setvar':['Set VMs variable: setvar Fedora BIOSSettings.ACPIEnabled True', setvarCmd, 0],
    3273             'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print(m.name, "has", m.memorySize, "M")\'', evalCmd, 0],
     3275            'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print m.name, "has", m.memorySize, "M"\'', evalCmd, 0],
    32743276            'quit':['Exits', quitCmd, 0],
    32753277            'host':['Show host information', hostCmd, 0],
     
    33273329            'prompt' : ['Control shell prompt', promptCmd, 0],
    33283330            'foreachvm' : ['Perform command for each VM', foreachvmCmd, 0],
    3329             'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print(obj.name)"', foreachCmd, 0],
     3331            'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print obj.name"', foreachCmd, 0],
    33303332            'recordDemo':['Record demo: recordDemo Win32 file.dmo 10', recordDemoCmd, 0],
    33313333            'playbackDemo':['Playback demo: playbackDemo Win32 file.dmo 10', playbackDemoCmd, 0],
     
    33423344    ci = commands.get(c, None)
    33433345    if ci == None:
    3344         print("Unknown command: '%s', type 'help' for list of known commands" % (c))
     3346        print "Unknown command: '%s', type 'help' for list of known commands" % (c)
    33453347        return 0
    33463348    if ctx['remote'] and ctx['vb'] is None:
    33473349        if c not in ['connect', 'reconnect', 'help', 'quit']:
    3348             print("First connect to remote server with %s command." % (colored('connect', 'blue')))
     3350            print "First connect to remote server with %s command." % (colored('connect', 'blue'))
    33493351            return 0
    33503352    return ci[1](ctx, args)
     
    33523354
    33533355def runCommand(ctx, cmd):
    3354     if not cmd: return 0
     3356    if len(cmd) == 0: return 0
    33553357    args = split_no_quotes(cmd)
    33563358    if len(args) == 0: return 0
     
    33623364#
    33633365# def runTestCmd(ctx, args):
    3364 #    print("Testy test", ctx['vb'])
     3366#    print "Testy test", ctx['vb']
    33653367#    return 0
    33663368#
     
    33793381    d = {}
    33803382    try:
    3381         exec(compile(open(filename).read(), filename, 'exec'), d, d)
    3382         for (k, v) in list(d['commands'].items()):
     3383        execfile(filename, d, d)
     3384        for (k, v) in d['commands'].items():
    33833385            if g_fVerbose:
    3384                 print("customize: adding \"%s\" - %s" % (k, v[0]))
     3386                print "customize: adding \"%s\" - %s" % (k, v[0])
    33853387            cmds[k] = [v[0], v[1], filename]
    33863388    except:
    3387         print("Error loading user extensions from %s" % (filename))
     3389        print "Error loading user extensions from %s" % (filename)
    33883390        traceback.print_exc()
    33893391
     
    34213423    if vbox is not None:
    34223424        try:
    3423             print("Running VirtualBox version %s" % (vbox.version))
    3424         except Exception as e:
     3425            print "Running VirtualBox version %s" % (vbox.version)
     3426        except Exception, e:
    34253427            printErr(ctx, e)
    34263428            if g_fVerbose:
     
    34593461                cmd = 'runScript %s'% (g_sScriptFile)
    34603462            elif g_sCmd is not None:
    3461                 cmd = next(it)
     3463                cmd = it.next()
    34623464            else:
    3463                 if sys.version_info[0] <= 2:
    3464                     cmd = raw_input(ctx['prompt'])
    3465                 else:
    3466                     cmd = input(ctx['prompt'])
     3465                cmd = raw_input(ctx['prompt'])
    34673466            done = runCommand(ctx, cmd)
    34683467            if done != 0: break
     
    34703469                break
    34713470        except KeyboardInterrupt:
    3472             print('====== You can type quit or q to leave')
     3471            print '====== You can type quit or q to leave'
    34733472        except StopIteration:
    34743473            break
    34753474        except EOFError:
    34763475            break
    3477         except Exception as e:
     3476        except Exception, e:
    34783477            printErr(ctx, e)
    34793478            if g_fVerbose:
     
    35373536
    35383537    if options.autopath:
    3539         asLocations = [ os.getcwd(), ]
    3540         try:    sScriptDir = os.path.dirname(os.path.abspath(__file__))
     3538        asLocations = [ os.getcwd(), ];
     3539        try:    sScriptDir = os.path.dirname(os.path.abspath(__file__));
    35413540        except: pass; # In case __file__ isn't there.
    35423541        else:
    35433542            if platform.system() in [ 'SunOS', ]:
    3544                 asLocations.append(os.path.join(sScriptDir, 'amd64'))
    3545             asLocations.append(sScriptDir)
     3543                asLocations.append(os.path.join(sScriptDir, 'amd64'));
     3544            asLocations.append(sScriptDir);
    35463545
    35473546
     
    35513550                if   os.path.isfile(os.path.join(sCurLoc, "VirtualBox")) \
    35523551                  or os.path.isfile(os.path.join(sCurLoc, "VirtualBox.exe")):
    3553                     print("Autodetected VBOX_PROGRAM_PATH as", sCurLoc)
     3552                    print "Autodetected VBOX_PROGRAM_PATH as", sCurLoc
    35543553                    os.environ["VBOX_PROGRAM_PATH"] = sCurLoc
    35553554                    sPath = sCurLoc
    3556                     break
     3555                    break;
    35573556        if sPath:
    35583557            sys.path.append(os.path.join(sPath, "sdk", "installer"))
     
    35623561            for sCurLoc in asLocations:
    35633562                if os.path.isfile(os.path.join(sCurLoc, "sdk", "bindings", "VirtualBox.xidl")):
    3564                     sCurLoc = os.path.join(sCurLoc, "sdk")
    3565                     print("Autodetected VBOX_SDK_PATH as", sCurLoc)
     3563                    sCurLoc = os.path.join(sCurLoc, "sdk");
     3564                    print "Autodetected VBOX_SDK_PATH as", sCurLoc
    35663565                    os.environ["VBOX_SDK_PATH"] = sCurLoc
    3567                     sPath = sCurLoc
    3568                     break
     3566                    sPath = sCurLoc;
     3567                    break;
    35693568        if sPath:
    3570             sTmp = os.path.join(sCurLoc, 'bindings', 'xpcom', 'python')
     3569            sTmp = os.path.join(sCurLoc, 'sdk', 'bindings', 'xpcom', 'python');
    35713570            if os.path.isdir(sTmp):
    3572                 sys.path.append(sTmp)
    3573             del sTmp
    3574         del sPath, asLocations
     3571                sys.path.append(sTmp);
     3572            del sTmp;
     3573        del sPath, asLocations;
    35753574
    35763575
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