Changeset 59798 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 24, 2016 2:35:47 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r59795 r59798 2 2 # -*- coding: utf-8 -*- 3 3 # $Id$ 4 4 5 """ 5 6 VirtualBox Python Shell. … … 19 20 """ 20 21 22 from __future__ import print_function 23 21 24 __copyright__ = \ 22 25 """ 23 Copyright (C) 2009-201 5Oracle Corporation26 Copyright (C) 2009-2016 Oracle Corporation 24 27 25 28 This file is part of VirtualBox Open Source Edition (OSE), as … … 34 37 35 38 36 import os, sys 39 import os 40 import sys 37 41 import traceback 38 42 import shlex … … 42 46 from optparse import OptionParser 43 47 from pprint import pprint 44 45 48 46 49 … … 152 155 matches.append(word) 153 156 154 except Exception ,e:157 except Exception as e: 155 158 printErr(self.ctx, e) 156 159 if g_fVerbose: … … 164 167 165 168 comps = {} 166 for (key, _value) in cmds.items():169 for (key, _value) in list(cmds.items()): 167 170 comps[key] = None 168 171 completer = CompleterNG(comps, ctx) … … 189 192 try: 190 193 while not progress.completed: 191 print "%s %%\r" % (colored(str(progress.percent), 'red')),194 print("%s %%\r" % (colored(str(progress.percent), 'red')), end="") 192 195 sys.stdout.flush() 193 196 progress.waitForCompletion(wait) … … 197 200 return 1 198 201 except KeyboardInterrupt: 199 print "Interrupted."202 print("Interrupted.") 200 203 ctx['interrupt'] = True 201 204 if progress.cancelable: 202 print "Canceling task..."205 print("Canceling task...") 203 206 progress.cancel() 204 207 return 0 205 208 206 209 def printErr(_ctx, e): 207 oVBoxMgr = _ctx['global'] ;210 oVBoxMgr = _ctx['global'] 208 211 if oVBoxMgr.errIsOurXcptKind(e): 209 print colored('%s: %s' % (oVBoxMgr.xcptToString(e), oVBoxMgr.xcptGetMessage(e)), 'red');210 else: 211 print colored(str(e), 'red')212 print(colored('%s: %s' % (oVBoxMgr.xcptToString(e), oVBoxMgr.xcptGetMessage(e)), 'red')) 213 else: 214 print(colored(str(e), 'red')) 212 215 213 216 def reportError(_ctx, progress): 214 217 errorinfo = progress.errorInfo 215 218 if errorinfo: 216 print colored("Error in module '%s': %s" % (errorinfo.component, errorinfo.text), 'red')219 print(colored("Error in module '%s': %s" % (errorinfo.component, errorinfo.text), 'red')) 217 220 218 221 def colCat(_ctx, strg): … … 241 244 mach = vbox.createMachine("", name, [], kind, "") 242 245 mach.saveSettings() 243 print "created machine with UUID", mach.id246 print("created machine with UUID", mach.id) 244 247 vbox.registerMachine(mach) 245 248 # update cache … … 248 251 def removeVm(ctx, mach): 249 252 uuid = mach.id 250 print "removing machine ", mach.name, "with UUID", uuid253 print("removing machine ", mach.name, "with UUID", uuid) 251 254 cmdClosedVm(ctx, mach, detachVmDevice, ["ALL"]) 252 255 disks = mach.unregister(ctx['global'].constants.CleanupMode_Full) … … 254 257 progress = mach.deleteConfig(disks) 255 258 if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0: 256 print "Success!"259 print("Success!") 257 260 else: 258 261 reportError(ctx, progress) … … 271 274 try: 272 275 perf.setup(['*'], [mach], 10, 15) 273 except Exception ,e:276 except Exception as e: 274 277 printErr(ctx, e) 275 278 if g_fVerbose: … … 324 327 return 325 328 for metric in ctx['perf'].query(["*"], [mach]): 326 print metric['name'], metric['values_as_string']329 print(metric['name'], metric['values_as_string']) 327 330 328 331 def guestExec(ctx, machine, console, cmds): 329 exec cmds332 exec(cmds) 330 333 331 334 def printMouseEvent(_ctx, mev): 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)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)) 333 336 334 337 def printKbdEvent(ctx, kev): 335 print "Kbd: ", ctx['global'].getArray(kev, 'scancodes')338 print("Kbd: ", ctx['global'].getArray(kev, 'scancodes')) 336 339 337 340 def printMultiTouchEvent(ctx, mtev): 338 print "MultiTouch : contacts=%d time=%d" % (mtev.contactCount, mtev.scanTime)341 print("MultiTouch : contacts=%d time=%d" % (mtev.contactCount, mtev.scanTime)) 339 342 xPositions = ctx['global'].getArray(mtev, 'xPositions') 340 343 yPositions = ctx['global'].getArray(mtev, 'yPositions') … … 343 346 344 347 for i in range(0, mtev.contactCount): 345 print " [%d] %d,%d %d %d" % (i, xPositions[i], yPositions[i], contactIds[i], contactFlags[i])348 print(" [%d] %d,%d %d %d" % (i, xPositions[i], yPositions[i], contactIds[i], contactFlags[i])) 346 349 347 350 def monitorSource(ctx, eventSource, active, dur): 348 351 def handleEventImpl(event): 349 352 evtype = event.type 350 print "got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))353 print("got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))) 351 354 if evtype == ctx['global'].constants.VBoxEventType_OnMachineStateChanged: 352 355 scev = ctx['global'].queryInterface(event, 'IMachineStateChangedEvent') 353 356 if scev: 354 print "machine state event: mach=%s state=%s" % (scev.machineId, scev.state)357 print("machine state event: mach=%s state=%s" % (scev.machineId, scev.state)) 355 358 elif evtype == ctx['global'].constants.VBoxEventType_OnSnapshotTaken: 356 359 stev = ctx['global'].queryInterface(event, 'ISnapshotTakenEvent') 357 360 if stev: 358 print "snapshot taken event: mach=%s snap=%s" % (stev.machineId, stev.snapshotId)361 print("snapshot taken event: mach=%s snap=%s" % (stev.machineId, stev.snapshotId)) 359 362 elif evtype == ctx['global'].constants.VBoxEventType_OnGuestPropertyChanged: 360 363 gpcev = ctx['global'].queryInterface(event, 'IGuestPropertyChangedEvent') 361 364 if gpcev: 362 print "guest property change: name=%s value=%s" % (gpcev.name, gpcev.value)365 print("guest property change: name=%s value=%s" % (gpcev.name, gpcev.value)) 363 366 elif evtype == ctx['global'].constants.VBoxEventType_OnMousePointerShapeChanged: 364 367 psev = ctx['global'].queryInterface(event, 'IMousePointerShapeChangedEvent') … … 366 369 shape = ctx['global'].getArray(psev, 'shape') 367 370 if shape is None: 368 print "pointer shape event - empty shape"371 print("pointer shape event - empty shape") 369 372 else: 370 print "pointer shape event: w=%d h=%d shape len=%d" % (psev.width, psev.height, len(shape))373 print("pointer shape event: w=%d h=%d shape len=%d" % (psev.width, psev.height, len(shape))) 371 374 elif evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse: 372 375 mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent') … … 441 444 def handleEventImpl(event): 442 445 evtype = event.type 443 #print "got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))446 #print("got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))) 444 447 if evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse: 445 448 mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent') … … 489 492 490 493 header = demo.readline() 491 print "Header is", header494 print("Header is", header) 492 495 basere = re.compile(r'(?P<s>\d+): (?P<t>[km]) (?P<p>.*)') 493 496 mre = re.compile(r'(?P<a>\d+) (?P<x>-*\d+) (?P<y>-*\d+) (?P<z>-*\d+) (?P<w>-*\d+) (?P<b>-*\d+)') … … 515 518 if rtype == 'k': 516 519 codes = kre.findall(params) 517 #print "KBD:", codes520 #print("KBD:", codes) 518 521 kbd.putScancodes(codes) 519 522 elif rtype == 'm': … … 523 526 if mdict['a'] == '1': 524 527 # absolute 525 #print "MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b']528 #print("MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b']) 526 529 mouse.putMouseEventAbsolute(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b'])) 527 530 else: 528 #print "MR: ", mdict['x'], mdict['y'], mdict['b']531 #print("MR: ", mdict['x'], mdict['y'], mdict['b']) 529 532 mouse.putMouseEvent(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b'])) 530 533 … … 559 562 h = fbh 560 563 561 print "Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)564 print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)) 562 565 data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_RGBA) 563 566 size = (w, h) … … 586 589 h = fbh 587 590 588 print "Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)591 print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)) 589 592 data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_PNG) 590 593 pngfile = open(f, 'wb') … … 594 597 def teleport(ctx, _session, console, args): 595 598 if args[0].find(":") == -1: 596 print "Use host:port format for teleport target"599 print("Use host:port format for teleport target") 597 600 return 598 601 (host, port) = args[0].split(":") … … 608 611 609 612 port = int(port) 610 print "Teleporting to %s:%d..." % (host, port)613 print("Teleporting to %s:%d..." % (host, port)) 611 614 progress = console.teleport(host, port, passwd, maxDowntime) 612 615 if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0: 613 print "Success!"616 print("Success!") 614 617 else: 615 618 reportError(ctx, progress) … … 632 635 all_stats = ctx['const'].all_values('GuestStatisticType') 633 636 cpu = 0 634 for s in all_stats.keys():637 for s in list(all_stats.keys()): 635 638 try: 636 639 val = guest.getStatistic( cpu, all_stats[s]) 637 print "%s: %d" % (s, val)640 print("%s: %d" % (s, val)) 638 641 except: 639 642 # likely not implemented … … 642 645 def plugCpu(_ctx, machine, _session, args): 643 646 cpu = int(args[0]) 644 print "Adding CPU %d..." % (cpu)647 print("Adding CPU %d..." % (cpu)) 645 648 machine.hotPlugCPU(cpu) 646 649 647 650 def unplugCpu(_ctx, machine, _session, args): 648 651 cpu = int(args[0]) 649 print "Removing CPU %d..." % (cpu)652 print("Removing CPU %d..." % (cpu)) 650 653 machine.hotUnplugCPU(cpu) 651 654 … … 661 664 662 665 def printHostUsbDev(ctx, ud): 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))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))) 664 667 665 668 def printUsbDev(_ctx, ud): 666 print " %s: %s (vendorId=%d productId=%d serial=%s)" % (ud.id, colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber)669 print(" %s: %s (vendorId=%d productId=%d serial=%s)" % (ud.id, colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber)) 667 670 668 671 def printSf(ctx, sf): 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"))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"))) 670 673 671 674 def ginfo(ctx, console, _args): 672 675 guest = console.guest 673 676 if guest.additionsRunLevel != ctx['const'].AdditionsRunLevelType_None: 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"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") 681 684 usbs = ctx['global'].getArray(console, 'USBDevices') 682 print "Attached USB:"685 print("Attached USB:") 683 686 for ud in usbs: 684 687 printUsbDev(ctx, ud) 685 688 rusbs = ctx['global'].getArray(console, 'remoteUSBDevices') 686 print "Remote USB:"689 print("Remote USB:") 687 690 for ud in rusbs: 688 691 printHostUsbDev(ctx, ud) 689 print "Transient shared folders:"692 print("Transient shared folders:") 690 693 sfs = rusbs = ctx['global'].getArray(console, 'sharedFolders') 691 694 for sf in sfs: … … 698 701 session = ctx['global'].getSessionObject(vbox) 699 702 mach.lockMachine(session, ctx['global'].constants.LockType_Shared) 700 except Exception ,e:703 except Exception as e: 701 704 printErr(ctx, "Session to '%s' not open: %s" % (mach.name, str(e))) 702 705 if g_fVerbose: … … 704 707 return 705 708 if session.state != ctx['const'].SessionState_Locked: 706 print "Session to '%s' in wrong state: %s" % (mach.name, session.state)709 print("Session to '%s' in wrong state: %s" % (mach.name, session.state)) 707 710 session.unlockMachine() 708 711 return … … 710 713 # in Webservices) functionality 711 714 if ctx['remote'] and cmd == 'some_local_only_command': 712 print 'Trying to use local only functionality, ignored'715 print('Trying to use local only functionality, ignored') 713 716 session.unlockMachine() 714 717 return … … 734 737 except KeyboardInterrupt: 735 738 ctx['interrupt'] = True 736 except Exception ,e:739 except Exception as e: 737 740 printErr(ctx, e) 738 741 if g_fVerbose: … … 747 750 try: 748 751 cmd(ctx, mach, args) 749 except Exception ,e:752 except Exception as e: 750 753 save = False 751 754 printErr(ctx, e) … … 755 758 try: 756 759 mach.saveSettings() 757 except Exception ,e:760 except Exception as e: 758 761 printErr(ctx, e) 759 762 if g_fVerbose: … … 767 770 try: 768 771 cmd(ctx, mach, session.console, args) 769 except Exception ,e:772 except Exception as e: 770 773 save = False 771 774 printErr(ctx, e) … … 777 780 778 781 def machById(ctx, uuid): 779 try: 780 mach = ctx['vb'].getMachine(uuid) 781 except: 782 mach = ctx['vb'].findMachine(uuid) 782 mach = ctx['vb'].findMachine(uuid) 783 783 return mach 784 784 … … 899 899 def argsToMach(ctx, args): 900 900 if len(args) < 2: 901 print "usage: %s [vmname|uuid]" % (args[0])901 print("usage: %s [vmname|uuid]" % (args[0])) 902 902 return None 903 903 uuid = args[1] 904 904 mach = machById(ctx, uuid) 905 905 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)) 907 907 return mach 908 908 … … 912 912 else: 913 913 spec = "" 914 print " %s: %s%s" % (colored(cmd, 'blue'), h, spec)914 print(" %s: %s%s" % (colored(cmd, 'blue'), h, spec)) 915 915 916 916 def helpCmd(_ctx, args): 917 917 if len(args) == 1: 918 print "Help page:"919 names = commands.keys()918 print("Help page:") 919 names = list(commands.keys()) 920 920 names.sort() 921 921 for i in names: … … 925 925 c = commands.get(cmd) 926 926 if c == None: 927 print "Command '%s' not known" % (cmd)927 print("Command '%s' not known" % (cmd)) 928 928 else: 929 929 helpSingleCmd(cmd, c[0], c[2]) … … 932 932 def asEnumElem(ctx, enum, elem): 933 933 enumVals = ctx['const'].all_values(enum) 934 for e in enumVals.keys():934 for e in list(enumVals.keys()): 935 935 if str(elem) == str(enumVals[e]): 936 936 return colored(e, 'green') … … 948 948 else: 949 949 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 ,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 as e: 952 952 printErr(ctx, e) 953 953 if g_fVerbose: … … 956 956 957 957 def 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]") 960 960 return 0 961 961 mach = argsToMach(ctx, args) … … 963 963 return 0 964 964 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() 981 981 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() 984 984 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))) 987 987 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)) 989 989 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)) 991 991 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))) 999 999 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(long(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(mach.lastStateChange/1000))) 1006 1006 # OSE has no VRDE 1007 1007 try: 1008 print " VRDE server [VRDEServer.enabled]: %s" % (asState(mach.VRDEServer.enabled))1008 print(" VRDE server [VRDEServer.enabled]: %s" % (asState(mach.VRDEServer.enabled))) 1009 1009 except: 1010 1010 pass 1011 1011 1012 print 1013 print colCat(ctx, " USB Controllers:")1012 print() 1013 print(colCat(ctx, " USB Controllers:")) 1014 1014 for oUsbCtrl in ctx['global'].getArray(mach, 'USBControllers'): 1015 print 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)) 1022 1022 1023 1023 controllers = ctx['global'].getArray(mach, 'storageControllers') 1024 1024 if controllers: 1025 print 1026 print colCat(ctx, " Storage Controllers:")1025 print() 1026 print(colCat(ctx, " Storage Controllers:")) 1027 1027 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))) 1029 1029 1030 1030 attaches = ctx['global'].getArray(mach, 'mediumAttachments') 1031 1031 if attaches: 1032 print 1033 print colCat(ctx, " Media:")1032 print() 1033 print(colCat(ctx, " Media:")) 1034 1034 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)) 1036 1036 medium = a.medium 1037 1037 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)) 1043 1043 1044 1044 if a.type == ctx['global'].constants.DeviceType_DVD: 1045 print " DVD:"1045 print(" DVD:") 1046 1046 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)) 1049 1049 if medium.hostDrive: 1050 print " Host DVD %s" % (colPath(ctx, medium.location))1050 print(" Host DVD %s" % (colPath(ctx, medium.location))) 1051 1051 if a.passthrough: 1052 print " [passthrough mode]"1052 print(" [passthrough mode]") 1053 1053 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)) 1056 1056 1057 1057 if a.type == ctx['global'].constants.DeviceType_Floppy: 1058 print " Floppy:"1058 print(" Floppy:") 1059 1059 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)) 1062 1062 if medium.hostDrive: 1063 print " Host floppy %s" % (colPath(ctx, medium.location))1063 print(" Host floppy %s" % (colPath(ctx, medium.location))) 1064 1064 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:")) 1070 1070 for sf in ctx['global'].getArray(mach, 'sharedFolders'): 1071 1071 printSf(ctx, sf) … … 1075 1075 def startCmd(ctx, args): 1076 1076 if len(args) < 2: 1077 print "usage: start name <frontend>"1077 print("usage: start name <frontend>") 1078 1078 return 0 1079 1079 mach = argsToMach(ctx, args) … … 1088 1088 1089 1089 def 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") 1092 1092 return 0 1093 1093 name = args[1] … … 1096 1096 ctx['vb'].getGuestOSType(oskind) 1097 1097 except Exception: 1098 print 'Unknown OS type:', oskind1098 print('Unknown OS type:', oskind) 1099 1099 return 0 1100 1100 createVm(ctx, name, oskind) … … 1102 1102 1103 1103 def 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]") 1106 1106 return 0 1107 1107 mach = argsToMach(ctx, args) … … 1113 1113 def execInGuest(ctx, console, args, env, user, passwd, tmo, inputPipe=None, outputPipe=None): 1114 1114 if len(args) < 1: 1115 print "exec in guest needs at least program name"1115 print("exec in guest needs at least program name") 1116 1116 return 1117 1117 guest = console.guest … … 1119 1119 # shall contain program name as argv[0] 1120 1120 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)) 1122 1122 flags = 0 1123 1123 if inputPipe is not None: 1124 1124 flags = 1 # set WaitForProcessStartOnly 1125 print args[0]1125 print(args[0]) 1126 1126 process = guestSession.processCreate(args[0], gargs, env, [], tmo) 1127 print "executed with pid %d" % (process.PID)1127 print("executed with pid %d" % (process.PID)) 1128 1128 if pid != 0: 1129 1129 try: … … 1161 1161 1162 1162 except KeyboardInterrupt: 1163 print "Interrupted."1163 print("Interrupted.") 1164 1164 ctx['interrupt'] = True 1165 1165 if progress.cancelable: 1166 1166 progress.cancel() 1167 1167 (_reason, code, _flags) = guest.getProcessStatus(pid) 1168 print "Exit code: %d" % (code)1168 print("Exit code: %d" % (code)) 1169 1169 return 0 1170 1170 else: … … 1175 1175 dst = args[1] 1176 1176 flags = 0 1177 print "Copying host %s to guest %s" % (src, dst)1177 print("Copying host %s to guest %s" % (src, dst)) 1178 1178 progress = console.guest.copyToGuest(src, dst, user, passwd, flags) 1179 1179 progressBar(ctx, progress) … … 1196 1196 user = getpass.getuser() 1197 1197 user_inp = nh_raw_input("User (%s): " % (user)) 1198 if len 1198 if len(user_inp) > 0: 1199 1199 user = user_inp 1200 1200 passwd = getpass.getpass() … … 1203 1203 1204 1204 def 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") 1207 1207 return 0 1208 1208 mach = argsToMach(ctx, args) … … 1217 1217 1218 1218 def 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") 1221 1221 return 0 1222 1222 mach = argsToMach(ctx, args) … … 1236 1236 1237 1237 def 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\"'") 1240 1240 return 0 1241 1241 mach = argsToMach(ctx, args) … … 1309 1309 1310 1310 def 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") 1313 1313 return 0 1314 1314 mach = argsToMach(ctx, args) … … 1322 1322 1323 1323 def 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>") 1326 1326 return 0 1327 1327 mach = argsToMach(ctx, args) … … 1332 1332 1333 1333 def 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>") 1336 1336 return 0 1337 1337 mach = argsToMach(ctx, args) … … 1351 1351 1352 1352 def 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>") 1355 1355 return 0 1356 1356 mach = argsToMach(ctx, args) … … 1358 1358 return 0 1359 1359 port = int(args[2]) 1360 if (len(args) > 3):1360 if len(args) > 3: 1361 1361 passwd = args[3] 1362 1362 else: … … 1368 1368 1369 1369 def closeportalCmd(ctx, args): 1370 if (len(args) < 2):1371 print "usage: closeportal name"1370 if len(args) < 2: 1371 print("usage: closeportal name") 1372 1372 return 0 1373 1373 mach = argsToMach(ctx, args) … … 1379 1379 1380 1380 def 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>") 1383 1383 return 0 1384 1384 mach = argsToMach(ctx, args) … … 1392 1392 cpu = args[1] 1393 1393 if plug: 1394 print "Adding CPU %d..." % (cpu)1394 print("Adding CPU %d..." % (cpu)) 1395 1395 mach.hotPlugCPU(cpu) 1396 1396 else: 1397 print "Removing CPU %d..." % (cpu)1397 print("Removing CPU %d..." % (cpu)) 1398 1398 mach.hotUnplugCPU(cpu) 1399 1399 1400 1400 def 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") 1403 1403 return 0 1404 1404 mach = argsToMach(ctx, args) … … 1413 1413 1414 1414 def 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") 1417 1417 return 0 1418 1418 mach = argsToMach(ctx, args) … … 1428 1428 def setvar(_ctx, _mach, args): 1429 1429 expr = 'mach.'+args[0]+' = '+args[1] 1430 print "Executing", expr1431 exec expr1430 print("Executing", expr) 1431 exec(expr) 1432 1432 1433 1433 def 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") 1436 1436 return 0 1437 1437 mach = argsToMach(ctx, args) … … 1444 1444 key = args[0] 1445 1445 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)) 1447 1447 mach.setExtraData(key, value) 1448 1448 1449 1449 def 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>") 1452 1452 return 0 1453 1453 key = args[2] … … 1467 1467 1468 1468 def printExtraKey(obj, key, value): 1469 print "%s: '%s' = '%s'" % (obj, key, value)1469 print("%s: '%s' = '%s'" % (obj, key, value)) 1470 1470 1471 1471 def 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>") 1474 1474 return 0 1475 1475 if len(args) == 3: … … 1498 1498 1499 1499 def aliasCmd(ctx, args): 1500 if (len(args) == 3):1500 if len(args) == 3: 1501 1501 aliases[args[1]] = args[2] 1502 1502 return 0 1503 1503 1504 for (key, value) in aliases.items():1505 print "'%s' is an alias for '%s'" % (key, value)1504 for (key, value) in list(aliases.items()): 1505 print("'%s' is an alias for '%s'" % (key, value)) 1506 1506 return 0 1507 1507 1508 1508 def verboseCmd(ctx, args): 1509 1509 global g_fVerbose 1510 if (len(args) > 1):1510 if len(args) > 1: 1511 1511 g_fVerbose = (args[1]=='on') 1512 1512 else: … … 1516 1516 def colorsCmd(ctx, args): 1517 1517 global g_fHasColors 1518 if (len(args) > 1):1518 if len(args) > 1: 1519 1519 g_fHasColors = (args[1] == 'on') 1520 1520 else: … … 1525 1525 vbox = ctx['vb'] 1526 1526 try: 1527 print "VirtualBox version %s" % (colored(vbox.version, 'blue'))1528 except Exception ,e:1527 print("VirtualBox version %s" % (colored(vbox.version, 'blue'))) 1528 except Exception as e: 1529 1529 printErr(ctx, e) 1530 1530 if g_fVerbose: 1531 1531 traceback.print_exc() 1532 1532 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:") 1536 1536 #for ud in ctx['global'].getArray(vbox, 'sharedFolders'): 1537 1537 # printSf(ctx, sf) 1538 1538 host = vbox.host 1539 1539 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)) 1542 1542 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)) 1549 1549 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:")) 1555 1555 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:")) 1559 1559 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:")) 1563 1563 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:")) 1567 1567 for ud in ctx['global'].getArray(host, 'USBDevices'): 1568 1568 printHostUsbDev(ctx, ud) … … 1570 1570 if ctx['perf']: 1571 1571 for metric in ctx['perf'].query(["*"], [host]): 1572 print metric['name'], metric['values_as_string']1572 print(metric['name'], metric['values_as_string']) 1573 1573 1574 1574 return 0 1575 1575 1576 1576 def 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)") 1579 1579 return 0 1580 1580 mach = argsToMach(ctx, args) … … 1589 1589 1590 1590 def 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)") 1593 1593 return 0 1594 1594 mach = argsToMach(ctx, args) … … 1603 1603 1604 1604 def 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)") 1607 1607 return 0 1608 1608 mach = argsToMach(ctx, args) … … 1617 1617 1618 1618 def 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)") 1621 1621 return 0 1622 1622 mach = argsToMach(ctx, args) … … 1631 1631 1632 1632 def monitorVBoxCmd(ctx, args): 1633 if (len(args) > 2):1634 print "usage: monitorVBox (duration)"1633 if len(args) > 2: 1634 print("usage: monitorVBox (duration)") 1635 1635 return 0 1636 1636 dur = 5 … … 1659 1659 1660 1660 def 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>") 1663 1663 return 0 1664 1664 mach = argsToMach(ctx, args) … … 1690 1690 1691 1691 def 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>") 1694 1694 return 0 1695 1695 mach = argsToMach(ctx, args) … … 1698 1698 1699 1699 log = 0 1700 if (len(args) > 2):1700 if len(args) > 2: 1701 1701 log = args[2] 1702 1702 … … 1704 1704 while True: 1705 1705 data = mach.readLog(log, uOffset, 4096) 1706 if (len(data) == 0):1706 if len(data) == 0: 1707 1707 break 1708 1708 # print adds either NL or space to chunks not ending with a NL … … 1713 1713 1714 1714 def 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>") 1717 1717 return 0 1718 1718 mach = argsToMach(ctx, args) … … 1721 1721 1722 1722 log = 0 1723 if (len(args) > 3):1723 if len(args) > 3: 1724 1724 log = args[3] 1725 1725 … … 1729 1729 # to reduce line splits on buffer boundary 1730 1730 data = mach.readLog(log, uOffset, 512*1024) 1731 if (len(data) == 0):1731 if len(data) == 0: 1732 1732 break 1733 1733 d = str(data).split("\n") … … 1737 1737 for mt in match: 1738 1738 s = s.replace(mt, colored(mt, 'red')) 1739 print s1739 print(s) 1740 1740 uOffset += len(data) 1741 1741 … … 1744 1744 1745 1745 def 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>") 1748 1748 return 0 1749 1749 mach = argsToMach(ctx, args) … … 1752 1752 1753 1753 log = 0 1754 if (len(args) > 2):1754 if len(args) > 2: 1755 1755 log = args[2] 1756 1756 … … 1762 1762 # to reduce line splits on buffer boundary 1763 1763 data = mach.readLog(log, uOffset, 512*1024) 1764 if (len(data) == 0):1764 if len(data) == 0: 1765 1765 break 1766 1766 d = str(data).split("\n") 1767 1767 for s in d: 1768 1768 if active: 1769 print s1769 print(s) 1770 1770 if context == 0: 1771 1771 active = False … … 1777 1777 active = True 1778 1778 context = 50 1779 print s1779 print(s) 1780 1780 uOffset += len(data) 1781 1781 … … 1785 1785 expr = ' '.join(args[1:]) 1786 1786 try: 1787 exec expr1788 except Exception ,e:1787 exec(expr) 1788 except Exception as e: 1789 1789 printErr(ctx, e) 1790 1790 if g_fVerbose: … … 1799 1799 1800 1800 def runScriptCmd(ctx, args): 1801 if (len(args) != 2):1802 print "usage: runScript <script>"1801 if len(args) != 2: 1802 print("usage: runScript <script>") 1803 1803 return 0 1804 1804 try: 1805 1805 lf = open(args[1], 'r') 1806 except IOError ,e:1807 print "cannot open:", args[1], ":", e1806 except IOError as e: 1807 print("cannot open:", args[1], ":", e) 1808 1808 return 0 1809 1809 … … 1819 1819 break 1820 1820 1821 except Exception ,e:1821 except Exception as e: 1822 1822 printErr(ctx, e) 1823 1823 if g_fVerbose: … … 1827 1827 1828 1828 def sleepCmd(ctx, args): 1829 if (len(args) != 2):1830 print "usage: sleep <secs>"1829 if len(args) != 2: 1830 print("usage: sleep <secs>") 1831 1831 return 0 1832 1832 … … 1840 1840 1841 1841 def shellCmd(ctx, args): 1842 if (len(args) < 2):1843 print "usage: shell <commands>"1842 if len(args) < 2: 1843 print("usage: shell <commands>") 1844 1844 return 0 1845 1845 cmd = ' '.join(args[1:]) … … 1854 1854 1855 1855 def 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>") 1858 1858 return 0 1859 1859 1860 1860 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: 1865 1865 url = args[1] 1866 1866 else: 1867 1867 url = None 1868 1868 1869 if (len(args) > 2):1869 if len(args) > 2: 1870 1870 user = args[2] 1871 1871 else: 1872 1872 user = "" 1873 1873 1874 if (len(args) > 3):1874 if len(args) > 3: 1875 1875 passwd = args[3] 1876 1876 else: … … 1881 1881 ctx['vb'] = vbox 1882 1882 try: 1883 print "Running VirtualBox version %s" % (vbox.version)1884 except Exception ,e:1883 print("Running VirtualBox version %s" % (vbox.version)) 1884 except Exception as e: 1885 1885 printErr(ctx, e) 1886 1886 if g_fVerbose: … … 1890 1890 1891 1891 def disconnectCmd(ctx, args): 1892 if (len(args) != 1):1893 print "usage: disconnect"1892 if len(args) != 1: 1893 print("usage: disconnect") 1894 1894 return 0 1895 1895 1896 1896 if ctx['vb'] is None: 1897 print "Not connected yet."1897 print("Not connected yet.") 1898 1898 return 0 1899 1899 … … 1909 1909 def reconnectCmd(ctx, args): 1910 1910 if ctx['wsinfo'] is None: 1911 print "Never connected..."1911 print("Never connected...") 1912 1912 return 0 1913 1913 … … 1920 1920 ctx['vb'] = ctx['global'].platform.connect(url, user, passwd) 1921 1921 try: 1922 print "Running VirtualBox version %s" % (ctx['vb'].version)1923 except Exception ,e:1922 print("Running VirtualBox version %s" % (ctx['vb'].version)) 1923 except Exception as e: 1924 1924 printErr(ctx, e) 1925 1925 if g_fVerbose: … … 1929 1929 def exportVMCmd(ctx, args): 1930 1930 if len(args) < 3: 1931 print "usage: exportVm <machine> <path> <format> <license>"1931 print("usage: exportVm <machine> <path> <format> <license>") 1932 1932 return 0 1933 1933 mach = argsToMach(ctx, args) … … 1935 1935 return 0 1936 1936 path = args[2] 1937 if (len(args) > 3):1937 if len(args) > 3: 1938 1938 fmt = args[3] 1939 1939 else: 1940 1940 fmt = "ovf-1.0" 1941 if (len(args) > 4):1941 if len(args) > 4: 1942 1942 lic = args[4] 1943 1943 else: … … 1949 1949 progress = app.write(fmt, path) 1950 1950 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)) 1952 1952 else: 1953 1953 reportError(ctx, progress) … … 2053 2053 extCode = extScancodes.get(ch, []) 2054 2054 if len(extCode) == 0: 2055 print "bad ext", ch2055 print("bad ext", ch) 2056 2056 return extCode 2057 2057 … … 2125 2125 def typeGuestCmd(ctx, args): 2126 2126 if len(args) < 3: 2127 print "usage: typeGuest <machine> <text> <charDelay>"2127 print("usage: typeGuest <machine> <text> <charDelay>") 2128 2128 return 0 2129 2129 mach = argsToMach(ctx, args) … … 2161 2161 verbose = False 2162 2162 hdds = ctx['global'].getArray(ctx['vb'], 'hardDisks') 2163 print colCat(ctx, "Hard disks:")2163 print(colCat(ctx, "Hard disks:")) 2164 2164 for hdd in hdds: 2165 2165 if hdd.state != ctx['global'].constants.MediumState_Created: 2166 2166 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)))) 2168 2168 2169 2169 dvds = ctx['global'].getArray(ctx['vb'], 'DVDImages') 2170 print colCat(ctx, "CD/DVD disks:")2170 print(colCat(ctx, "CD/DVD disks:")) 2171 2171 for dvd in dvds: 2172 2172 if dvd.state != ctx['global'].constants.MediumState_Created: 2173 2173 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)))) 2175 2175 2176 2176 floppys = ctx['global'].getArray(ctx['vb'], 'floppyImages') 2177 print colCat(ctx, "Floppy disks:")2177 print(colCat(ctx, "Floppy disks:")) 2178 2178 for floppy in floppys: 2179 2179 if floppy.state != ctx['global'].constants.MediumState_Created: 2180 2180 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)))) 2182 2182 2183 2183 return 0 2184 2184 2185 2185 def listUsbCmd(ctx, args): 2186 if (len(args) > 1):2187 print "usage: listUsb"2186 if len(args) > 1: 2187 print("usage: listUsb") 2188 2188 return 0 2189 2189 … … 2202 2202 2203 2203 def 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") 2206 2206 return 0 2207 2207 … … 2216 2216 progress = hdd.createBaseStorage(size, (ctx['global'].constants.MediumVariant_Standard, )) 2217 2217 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)) 2221 2221 reportError(ctx,progress) 2222 2222 return 0 … … 2225 2225 2226 2226 def registerHddCmd(ctx, args): 2227 if (len(args) < 2):2228 print "usage: registerHdd location"2227 if len(args) < 2: 2228 print("usage: registerHdd location") 2229 2229 return 0 2230 2230 … … 2236 2236 parentId = "" 2237 2237 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)) 2239 2239 return 0 2240 2240 … … 2244 2244 2245 2245 def 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") 2248 2248 return 0 2249 2249 … … 2256 2256 hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False) 2257 2257 except: 2258 print "no HDD with path %s registered" % (loc)2258 print("no HDD with path %s registered" % (loc)) 2259 2259 return 0 2260 2260 if len(args) > 3: … … 2279 2279 2280 2280 def 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") 2283 2283 return 0 2284 2284 … … 2291 2291 hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False) 2292 2292 except: 2293 print "no HDD with path %s registered" % (loc)2293 print("no HDD with path %s registered" % (loc)) 2294 2294 return 0 2295 2295 … … 2298 2298 2299 2299 def 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>") 2302 2302 return 0 2303 2303 2304 2304 vbox = ctx['vb'] 2305 2305 loc = args[1] 2306 if (len(args) > 2):2306 if len(args) > 2: 2307 2307 vmunreg = int(args[2]) 2308 2308 else: … … 2311 2311 hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False) 2312 2312 except: 2313 print "no HDD with path %s registered" % (loc)2313 print("no HDD with path %s registered" % (loc)) 2314 2314 return 0 2315 2315 … … 2318 2318 try: 2319 2319 for mach in machs: 2320 print "Trying to detach from %s" % (mach)2320 print("Trying to detach from %s" % (mach)) 2321 2321 detachMedium(ctx, mach, hdd) 2322 except Exception ,e:2323 print 'failed: ', e2322 except Exception as e: 2323 print('failed: ', e) 2324 2324 return 0 2325 2325 hdd.close() … … 2327 2327 2328 2328 def removeHddCmd(ctx, args): 2329 if (len(args) != 2):2330 print "usage: removeHdd path"2329 if len(args) != 2: 2330 print("usage: removeHdd path") 2331 2331 return 0 2332 2332 … … 2336 2336 hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False) 2337 2337 except: 2338 print "no HDD with path %s registered" % (loc)2338 print("no HDD with path %s registered" % (loc)) 2339 2339 return 0 2340 2340 … … 2345 2345 2346 2346 def registerIsoCmd(ctx, args): 2347 if (len(args) < 2):2348 print "usage: registerIso location"2347 if len(args) < 2: 2348 print("usage: registerIso location") 2349 2349 return 0 2350 2350 … … 2352 2352 loc = args[1] 2353 2353 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)) 2355 2355 return 0 2356 2356 2357 2357 def unregisterIsoCmd(ctx, args): 2358 if (len(args) != 2):2359 print "usage: unregisterIso path"2358 if len(args) != 2: 2359 print("usage: unregisterIso path") 2360 2360 return 0 2361 2361 … … 2365 2365 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2366 2366 except: 2367 print "no DVD with path %s registered" % (loc)2367 print("no DVD with path %s registered" % (loc)) 2368 2368 return 0 2369 2369 2370 2370 progress = dvd.close() 2371 print "Unregistered ISO at %s" % (colPath(ctx, loc))2371 print("Unregistered ISO at %s" % (colPath(ctx, loc))) 2372 2372 2373 2373 return 0 2374 2374 2375 2375 def removeIsoCmd(ctx, args): 2376 if (len(args) != 2):2377 print "usage: removeIso path"2376 if len(args) != 2: 2377 print("usage: removeIso path") 2378 2378 return 0 2379 2379 … … 2383 2383 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2384 2384 except: 2385 print "no DVD with path %s registered" % (loc)2385 print("no DVD with path %s registered" % (loc)) 2386 2386 return 0 2387 2387 2388 2388 progress = dvd.deleteStorage() 2389 2389 if progressBar(ctx, progress): 2390 print "Removed ISO at %s" % (colPath(ctx, dvd.location))2390 print("Removed ISO at %s" % (colPath(ctx, dvd.location))) 2391 2391 else: 2392 2392 reportError(ctx, progress) … … 2394 2394 2395 2395 def 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") 2398 2398 return 0 2399 2399 … … 2406 2406 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2407 2407 except: 2408 print "no DVD with path %s registered" % (loc)2408 print("no DVD with path %s registered" % (loc)) 2409 2409 return 0 2410 2410 if len(args) > 3: … … 2417 2417 2418 2418 def 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") 2421 2421 return 0 2422 2422 … … 2429 2429 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2430 2430 except: 2431 print "no DVD with path %s registered" % (loc)2431 print("no DVD with path %s registered" % (loc)) 2432 2432 return 0 2433 2433 … … 2436 2436 2437 2437 def 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") 2440 2440 return 0 2441 2441 … … 2448 2448 dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False) 2449 2449 except: 2450 print "no DVD with path %s registered" % (loc)2450 print("no DVD with path %s registered" % (loc)) 2451 2451 return 0 2452 2452 … … 2463 2463 2464 2464 def 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") 2467 2467 return 0 2468 2468 … … 2490 2490 2491 2491 def 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>") 2494 2494 return 0 2495 2495 … … 2497 2497 ctrltype = enumFromString(ctx, 'StorageControllerType', args[4]) 2498 2498 if ctrltype == None: 2499 print "Controller type %s unknown" % (args[4])2499 print("Controller type %s unknown" % (args[4])) 2500 2500 return 0 2501 2501 else: … … 2507 2507 bus = enumFromString(ctx, 'StorageBus', args[3]) 2508 2508 if bus is None: 2509 print "Bus type %s unknown" % (args[3])2509 print("Bus type %s unknown" % (args[3])) 2510 2510 return 0 2511 2511 name = args[2] … … 2514 2514 2515 2515 def 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") 2518 2518 return 0 2519 2519 … … 2526 2526 2527 2527 def usbctr(ctx, mach, console, args): 2528 if (args[0]):2528 if args[0]: 2529 2529 console.attachUSBDevice(args[1], "") 2530 2530 else: … … 2532 2532 2533 2533 def 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") 2536 2536 return 0 2537 2537 … … 2544 2544 2545 2545 def 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") 2548 2548 return 0 2549 2549 … … 2557 2557 2558 2558 def guiCmd(ctx, args): 2559 if (len(args) > 1):2560 print "usage: gui"2559 if len(args) > 1: 2560 print("usage: gui") 2561 2561 return 0 2562 2562 … … 2572 2572 2573 2573 def 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>") 2576 2576 return 0 2577 2577 … … 2596 2596 2597 2597 def 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") 2600 2600 return 0 2601 2601 … … 2617 2617 def snapshotCmd(ctx, args): 2618 2618 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") 2622 2622 return 0 2623 2623 … … 2627 2627 cmd = args[2] 2628 2628 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>") 2631 2631 return 0 2632 2632 name = args[3] 2633 if (len(args) > 4):2633 if len(args) > 4: 2634 2634 desc = args[4] 2635 2635 else: … … 2639 2639 2640 2640 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") 2643 2643 return 0 2644 2644 name = args[3] … … 2648 2648 2649 2649 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") 2652 2652 return 0 2653 2653 snap = mach.currentSnapshot() … … 2656 2656 2657 2657 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") 2660 2660 return 0 2661 2661 name = args[3] … … 2664 2664 return 0 2665 2665 2666 print "Command '%s' is unknown" % (cmd)2666 print("Command '%s' is unknown" % (cmd)) 2667 2667 return 0 2668 2668 … … 2683 2683 first = 0 2684 2684 msg = '' 2685 for aliasmode, aliaskey in alias.iteritems():2685 for aliasmode, aliaskey in list(alias.items()): 2686 2686 if first == 0: 2687 2687 first = 1 … … 2689 2689 msg += ', ' 2690 2690 if int(nat.aliasMode) & aliaskey: 2691 msg += '% d: %s' % (aliasmode, 'on')2691 msg += '%s: %s' % (aliasmode, 'on') 2692 2692 else: 2693 msg += '%d: %s' % (aliasmode, 'off') 2694 msg += ')' 2693 msg += '%s: %s' % (aliasmode, 'off') 2695 2694 return (0, [msg]) 2696 2695 else: … … 2698 2697 if 'default' not in args: 2699 2698 for a in range(1, len(args)): 2700 if not alias.has_key(args[a]):2701 print 'Invalid alias mode: ' + args[a]2702 print natAlias.__doc__2699 if args[a] not in alias: 2700 print('Invalid alias mode: ' + args[a]) 2701 print(natAlias.__doc__) 2703 2702 return (1, None) 2704 2703 nat.aliasMode = int(nat.aliasMode) | alias[args[a]] … … 2723 2722 else: 2724 2723 if args[1] < 16000: 2725 print 'invalid mtu value (%s not in range [65 - 16000])' % (args[1])2724 print('invalid mtu value (%s not in range [65 - 16000])' % (args[1])) 2726 2725 return (1, None) 2727 2726 for i in range(2, len(args)): 2728 2727 if not args[i].isdigit() or int(args[i]) < 8 or int(args[i]) > 1024: 2729 print 'invalid %s parameter (%i not in range [8-1024])' % (i, args[i])2728 print('invalid %s parameter (%i not in range [8-1024])' % (i, args[i])) 2730 2729 return (1, None) 2731 2730 a = [args[1]] … … 2735 2734 else: 2736 2735 for i in range(2, len(args)): a.append(args[i]) 2737 #print a2736 #print(a) 2738 2737 nat.setNetworkSettings(int(a[0]), int(a[1]), int(a[2]), int(a[3]), int(a[4])) 2739 2738 return (0, None) … … 2786 2785 cmd = args[1] 2787 2786 if len(args) != 3: 2788 print 'invalid args:', args2789 print natTftp.__doc__2787 print('invalid args:', args) 2788 print(natTftp.__doc__) 2790 2789 return (1, None) 2791 2790 if cmd == 'prefix': nat.TFTPPrefix = args[2] … … 2793 2792 elif cmd == 'server': nat.TFTPNextServer = args[2] 2794 2793 else: 2795 print "invalid cmd:", cmd2794 print("invalid cmd:", cmd) 2796 2795 return (1, None) 2797 2796 return (0, None) … … 2818 2817 pfcmd = { 2819 2818 'simple': { 2820 'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 5,2819 'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 5, 2821 2820 'func':lambda: nat.addRedirect('', proto[args[2]], '', int(args[3]), '', int(args[4])) 2822 2821 }, 2823 2822 'no_name': { 2824 'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 7,2823 'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 7, 2825 2824 'func': lambda: nat.addRedirect('', proto[args[2]], args[3], int(args[4]), args[5], int(args[6])) 2826 2825 }, 2827 2826 'ex': { 2828 'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 8,2827 'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 8, 2829 2828 'func': lambda: nat.addRedirect(args[3], proto[args[2]], args[4], int(args[5]), args[6], int(args[7])) 2830 2829 }, … … 2836 2835 2837 2836 if not pfcmd[args[1]]['validate'](): 2838 print 'invalid port-forwarding or args of sub command ', args[1]2839 print natPortForwarding.__doc__2837 print('invalid port-forwarding or args of sub command ', args[1]) 2838 print(natPortForwarding.__doc__) 2840 2839 return (1, None) 2841 2840 … … 2856 2855 (addr, mask) = args[1].split('/') 2857 2856 if addr.count('.') > 3 or int(mask) < 0 or int(mask) > 32: 2858 print 'Invalid arguments'2857 print('Invalid arguments') 2859 2858 return (1, None) 2860 2859 nat.network = args[1] … … 2880 2879 if len(args) < 2 or args[1] == 'help': 2881 2880 if len(args) > 2: 2882 print natcommands[args[2]].__doc__2881 print(natcommands[args[2]].__doc__) 2883 2882 else: 2884 print natCmd.__doc__2883 print(natCmd.__doc__) 2885 2884 return 0 2886 2885 if len(args) == 1 or len(args) < 4 or args[3] not in natcommands: 2887 print natCmd.__doc__2886 print(natCmd.__doc__) 2888 2887 return 0 2889 2888 mach = ctx['argsToMach'](args) 2890 2889 if mach == None: 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))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))) 2895 2894 return 0 2896 2895 nicnum = int(args[2]) … … 2919 2918 for r in report: 2920 2919 msg ='%s nic%d %s: %s' % (mach.name, nicnum, func, r) 2921 print msg2920 print(msg) 2922 2921 return 0 2923 2922 … … 2930 2929 yesno = {'off' : 0, 'on' : 1} 2931 2930 if args[1] not in yesno: 2932 print '%s isn\'t acceptable, please choose %s' % (args[1], yesno.keys())2931 print('%s isn\'t acceptable, please choose %s' % (args[1], list(yesno.keys()))) 2933 2932 return (1, None) 2934 2933 adapter.__setattr__(attr, yesno[args[1]]) … … 2953 2952 else: 2954 2953 if not args[1].isdigit(): 2955 print '%s isn\'t a number' % (args[1])2956 print(1, None)2954 print('%s isn\'t a number' % (args[1])) 2955 return (1, None) 2957 2956 adapter.lineSpeed = int(args[1]) 2958 2957 return (0, None) … … 2976 2975 if len(args) == 1: 2977 2976 nictypes = ctx['const'].all_values('NetworkAdapterType') 2978 for key in nictypes.keys():2977 for key in list(nictypes.keys()): 2979 2978 if str(adapter.adapterType) == str(nictypes[key]): 2980 2979 return (0, str(key)) … … 2982 2981 else: 2983 2982 nictypes = ctx['const'].all_values('NetworkAdapterType') 2984 if args[1] not in nictypes.keys():2985 print '%s not in acceptable values (%s)' % (args[1], nictypes.keys())2983 if args[1] not in list(nictypes.keys()): 2984 print('%s not in acceptable values (%s)' % (args[1], list(nictypes.keys()))) 2986 2985 return (1, None) 2987 2986 adapter.adapterType = nictypes[args[1]] … … 3002 3001 ctx['global'].constants.NetworkAttachmentType_Generic: ('Generic', ''), 3003 3002 } 3004 import types 3005 if type(adapter.attachmentType) != types.IntType: 3003 if type(adapter.attachmentType) != int: 3006 3004 t = str(adapter.attachmentType) 3007 3005 else: … … 3037 3035 'f': lambda: ctx['global'].constants.NetworkAttachmentType_Generic} 3038 3036 } 3039 if args[1] not in nicAttachmentType.keys():3040 print '%s not in acceptable values (%s)' % (args[1], nicAttachmentType.keys())3037 if args[1] not in list(nicAttachmentType.keys()): 3038 print('%s not in acceptable values (%s)' % (args[1], list(nicAttachmentType.keys()))) 3041 3039 return (1, None) 3042 3040 if not nicAttachmentType[args[1]]['v'](): 3043 print nicAttachmentType.__doc__3041 print(nicAttachmentType.__doc__) 3044 3042 return (1, None) 3045 3043 nicAttachmentType[args[1]]['p']() … … 3067 3065 if len(args) == 3 \ 3068 3066 and args[2] in niccomand: 3069 print niccomand[args[2]].__doc__3067 print(niccomand[args[2]].__doc__) 3070 3068 else: 3071 print nicCmd.__doc__3069 print(nicCmd.__doc__) 3072 3070 return 0 3073 3071 3074 3072 vm = ctx['argsToMach'](args) 3075 3073 if vm is None: 3076 print 'please specify vm'3074 print('please specify vm') 3077 3075 return 0 3078 3076 3079 3077 if len(args) < 3 \ 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))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))) 3082 3080 return 0 3083 3081 nicnum = int(args[2]) … … 3092 3090 vm.saveSettings() 3093 3091 if report is not None: 3094 print '%s nic %d %s: %s' % (vm.name, nicnum, args[3], report)3092 print('%s nic %d %s: %s' % (vm.name, nicnum, args[3], report)) 3095 3093 session.unlockMachine() 3096 3094 return 0 … … 3099 3097 def promptCmd(ctx, args): 3100 3098 if len(args) < 2: 3101 print "Current prompt: '%s'" % (ctx['prompt'])3099 print("Current prompt: '%s'" % (ctx['prompt'])) 3102 3100 return 0 3103 3101 … … 3107 3105 def foreachCmd(ctx, args): 3108 3106 if len(args) < 3: 3109 print "usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']"3107 print("usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']") 3110 3108 return 0 3111 3109 … … 3117 3115 e.apply(cmd) 3118 3116 except: 3119 print "Error executing"3117 print("Error executing") 3120 3118 traceback.print_exc() 3121 3119 return 0 … … 3123 3121 def foreachvmCmd(ctx, args): 3124 3122 if len(args) < 2: 3125 print "foreachvm command <args>"3123 print("foreachvm command <args>") 3126 3124 return 0 3127 3125 cmdargs = args[1:] … … 3133 3131 3134 3132 def recordDemoCmd(ctx, args): 3135 if (len(args) < 3):3136 print "usage: recordDemo vm filename (duration)"3133 if len(args) < 3: 3134 print("usage: recordDemo vm filename (duration)") 3137 3135 return 0 3138 3136 mach = argsToMach(ctx, args) … … 3147 3145 3148 3146 def playbackDemoCmd(ctx, args): 3149 if (len(args) < 3):3150 print "usage: playbackDemo vm filename (duration)"3147 if len(args) < 3: 3148 print("usage: playbackDemo vm filename (duration)") 3151 3149 return 0 3152 3150 mach = argsToMach(ctx, args) … … 3169 3167 for a in assigned: 3170 3168 if a.isPhysicalDevice: 3171 print "%s: assigned host device %s guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.hostAddress), pciAddr(ctx, a.guestAddress))3169 print("%s: assigned host device %s guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.hostAddress), pciAddr(ctx, a.guestAddress))) 3172 3170 3173 3171 atts = ctx['global'].getArray(console, 'attachedPCIDevices') 3174 3172 for a in atts: 3175 3173 if a.isPhysicalDevice: 3176 print "%s: physical, guest %s, host %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress), pciAddr(ctx, a.hostAddress))3174 print("%s: physical, guest %s, host %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress), pciAddr(ctx, a.hostAddress))) 3177 3175 else: 3178 print "%s: virtual, guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress))3176 print("%s: virtual, guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress))) 3179 3177 return 3180 3178 … … 3188 3186 3189 3187 def lspciCmd(ctx, args): 3190 if (len(args) < 2):3191 print "usage: lspci vm"3188 if len(args) < 2: 3189 print("usage: lspci vm") 3192 3190 return 0 3193 3191 mach = argsToMach(ctx, args) … … 3198 3196 3199 3197 def attachpciCmd(ctx, args): 3200 if (len(args) < 3):3201 print "usage: attachpci vm hostpci <guestpci>"3198 if len(args) < 3: 3199 print("usage: attachpci vm hostpci <guestpci>") 3202 3200 return 0 3203 3201 mach = argsToMach(ctx, args) … … 3206 3204 hostaddr = parsePci(args[2]) 3207 3205 if hostaddr == -1: 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):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: 3212 3210 guestaddr = parsePci(args[3]) 3213 3211 if guestaddr == -1: 3214 print "invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[3])3212 print("invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[3])) 3215 3213 return 0 3216 3214 else: … … 3220 3218 3221 3219 def detachpciCmd(ctx, args): 3222 if (len(args) < 3):3223 print "usage: detachpci vm hostpci"3220 if len(args) < 3: 3221 print("usage: detachpci vm hostpci") 3224 3222 return 0 3225 3223 mach = argsToMach(ctx, args) … … 3228 3226 hostaddr = parsePci(args[2]) 3229 3227 if hostaddr == -1: 3230 print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2])3228 print("invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2])) 3231 3229 return 0 3232 3230 … … 3235 3233 3236 3234 def gotoCmd(ctx, args): 3237 if (len(args) < 2):3238 print "usage: goto line"3235 if len(args) < 2: 3236 print("usage: goto line") 3239 3237 return 0 3240 3238 … … 3273 3271 'verbose':['Toggle verbosity', verboseCmd, 0], 3274 3272 'setvar':['Set VMs variable: setvar Fedora BIOSSettings.ACPIEnabled True', setvarCmd, 0], 3275 'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print m.name, "has", m.memorySize, "M"\'', evalCmd, 0],3273 'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print(m.name, "has", m.memorySize, "M")\'', evalCmd, 0], 3276 3274 'quit':['Exits', quitCmd, 0], 3277 3275 'host':['Show host information', hostCmd, 0], … … 3329 3327 'prompt' : ['Control shell prompt', promptCmd, 0], 3330 3328 'foreachvm' : ['Perform command for each VM', foreachvmCmd, 0], 3331 'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print obj.name"', foreachCmd, 0],3329 'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print(obj.name)"', foreachCmd, 0], 3332 3330 'recordDemo':['Record demo: recordDemo Win32 file.dmo 10', recordDemoCmd, 0], 3333 3331 'playbackDemo':['Playback demo: playbackDemo Win32 file.dmo 10', playbackDemoCmd, 0], … … 3344 3342 ci = commands.get(c, None) 3345 3343 if ci == None: 3346 print "Unknown command: '%s', type 'help' for list of known commands" % (c)3344 print("Unknown command: '%s', type 'help' for list of known commands" % (c)) 3347 3345 return 0 3348 3346 if ctx['remote'] and ctx['vb'] is None: 3349 3347 if c not in ['connect', 'reconnect', 'help', 'quit']: 3350 print "First connect to remote server with %s command." % (colored('connect', 'blue'))3348 print("First connect to remote server with %s command." % (colored('connect', 'blue'))) 3351 3349 return 0 3352 3350 return ci[1](ctx, args) … … 3354 3352 3355 3353 def runCommand(ctx, cmd): 3356 if len(cmd) == 0: return 03354 if not cmd: return 0 3357 3355 args = split_no_quotes(cmd) 3358 3356 if len(args) == 0: return 0 … … 3364 3362 # 3365 3363 # def runTestCmd(ctx, args): 3366 # print "Testy test", ctx['vb']3364 # print("Testy test", ctx['vb']) 3367 3365 # return 0 3368 3366 # … … 3381 3379 d = {} 3382 3380 try: 3383 exec file(filename, d, d)3384 for (k, v) in d['commands'].items():3381 exec(compile(open(filename).read(), filename, 'exec'), d, d) 3382 for (k, v) in list(d['commands'].items()): 3385 3383 if g_fVerbose: 3386 print "customize: adding \"%s\" - %s" % (k, v[0])3384 print("customize: adding \"%s\" - %s" % (k, v[0])) 3387 3385 cmds[k] = [v[0], v[1], filename] 3388 3386 except: 3389 print "Error loading user extensions from %s" % (filename)3387 print("Error loading user extensions from %s" % (filename)) 3390 3388 traceback.print_exc() 3391 3389 … … 3423 3421 if vbox is not None: 3424 3422 try: 3425 print "Running VirtualBox version %s" % (vbox.version)3426 except Exception ,e:3423 print("Running VirtualBox version %s" % (vbox.version)) 3424 except Exception as e: 3427 3425 printErr(ctx, e) 3428 3426 if g_fVerbose: … … 3461 3459 cmd = 'runScript %s'% (g_sScriptFile) 3462 3460 elif g_sCmd is not None: 3463 cmd = it.next()3461 cmd = next(it) 3464 3462 else: 3465 cmd = raw_input(ctx['prompt']) 3463 if sys.version_info[0] <= 2: 3464 cmd = raw_input(ctx['prompt']) 3465 else: 3466 cmd = input(ctx['prompt']) 3466 3467 done = runCommand(ctx, cmd) 3467 3468 if done != 0: break … … 3469 3470 break 3470 3471 except KeyboardInterrupt: 3471 print '====== You can type quit or q to leave'3472 print('====== You can type quit or q to leave') 3472 3473 except StopIteration: 3473 3474 break 3474 3475 except EOFError: 3475 3476 break 3476 except Exception ,e:3477 except Exception as e: 3477 3478 printErr(ctx, e) 3478 3479 if g_fVerbose: … … 3536 3537 3537 3538 if options.autopath: 3538 asLocations = [ os.getcwd(), ] ;3539 try: sScriptDir = os.path.dirname(os.path.abspath(__file__)) ;3539 asLocations = [ os.getcwd(), ] 3540 try: sScriptDir = os.path.dirname(os.path.abspath(__file__)) 3540 3541 except: pass; # In case __file__ isn't there. 3541 3542 else: 3542 3543 if platform.system() in [ 'SunOS', ]: 3543 asLocations.append(os.path.join(sScriptDir, 'amd64')) ;3544 asLocations.append(sScriptDir) ;3544 asLocations.append(os.path.join(sScriptDir, 'amd64')) 3545 asLocations.append(sScriptDir) 3545 3546 3546 3547 … … 3550 3551 if os.path.isfile(os.path.join(sCurLoc, "VirtualBox")) \ 3551 3552 or os.path.isfile(os.path.join(sCurLoc, "VirtualBox.exe")): 3552 print "Autodetected VBOX_PROGRAM_PATH as", sCurLoc3553 print("Autodetected VBOX_PROGRAM_PATH as", sCurLoc) 3553 3554 os.environ["VBOX_PROGRAM_PATH"] = sCurLoc 3554 3555 sPath = sCurLoc 3555 break ;3556 break 3556 3557 if sPath: 3557 3558 sys.path.append(os.path.join(sPath, "sdk", "installer")) … … 3561 3562 for sCurLoc in asLocations: 3562 3563 if os.path.isfile(os.path.join(sCurLoc, "sdk", "bindings", "VirtualBox.xidl")): 3563 sCurLoc = os.path.join(sCurLoc, "sdk") ;3564 print "Autodetected VBOX_SDK_PATH as", sCurLoc3564 sCurLoc = os.path.join(sCurLoc, "sdk") 3565 print("Autodetected VBOX_SDK_PATH as", sCurLoc) 3565 3566 os.environ["VBOX_SDK_PATH"] = sCurLoc 3566 sPath = sCurLoc ;3567 break ;3567 sPath = sCurLoc 3568 break 3568 3569 if sPath: 3569 sTmp = os.path.join(sCurLoc, ' sdk', 'bindings', 'xpcom', 'python');3570 sTmp = os.path.join(sCurLoc, 'bindings', 'xpcom', 'python') 3570 3571 if os.path.isdir(sTmp): 3571 sys.path.append(sTmp) ;3572 del sTmp ;3573 del sPath, asLocations ;3572 sys.path.append(sTmp) 3573 del sTmp 3574 del sPath, asLocations 3574 3575 3575 3576
Note:
See TracChangeset
for help on using the changeset viewer.