Changeset 59795 in vbox for trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
- Timestamp:
- Feb 24, 2016 9:13:27 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r59777 r59795 2 2 # -*- coding: utf-8 -*- 3 3 # $Id$ 4 5 4 """ 6 5 VirtualBox Python Shell. … … 20 19 """ 21 20 22 from __future__ import print_function23 24 21 __copyright__ = \ 25 22 """ 26 Copyright (C) 2009-201 6Oracle Corporation23 Copyright (C) 2009-2015 Oracle Corporation 27 24 28 25 This file is part of VirtualBox Open Source Edition (OSE), as … … 37 34 38 35 39 import os 40 import sys 36 import os, sys 41 37 import traceback 42 38 import shlex … … 46 42 from optparse import OptionParser 47 43 from pprint import pprint 44 48 45 49 46 … … 155 152 matches.append(word) 156 153 157 except Exception ase:154 except Exception, e: 158 155 printErr(self.ctx, e) 159 156 if g_fVerbose: … … 167 164 168 165 comps = {} 169 for (key, _value) in list(cmds.items()):166 for (key, _value) in cmds.items(): 170 167 comps[key] = None 171 168 completer = CompleterNG(comps, ctx) … … 192 189 try: 193 190 while not progress.completed: 194 print ("%s %%\r" % (colored(str(progress.percent), 'red')), end="")191 print "%s %%\r" % (colored(str(progress.percent), 'red')), 195 192 sys.stdout.flush() 196 193 progress.waitForCompletion(wait) … … 200 197 return 1 201 198 except KeyboardInterrupt: 202 print ("Interrupted.")199 print "Interrupted." 203 200 ctx['interrupt'] = True 204 201 if progress.cancelable: 205 print ("Canceling task...")202 print "Canceling task..." 206 203 progress.cancel() 207 204 return 0 208 205 209 206 def printErr(_ctx, e): 210 oVBoxMgr = _ctx['global'] 207 oVBoxMgr = _ctx['global']; 211 208 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') 215 212 216 213 def reportError(_ctx, progress): 217 214 errorinfo = progress.errorInfo 218 215 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') 220 217 221 218 def colCat(_ctx, strg): … … 244 241 mach = vbox.createMachine("", name, [], kind, "") 245 242 mach.saveSettings() 246 print ("created machine with UUID", mach.id)243 print "created machine with UUID", mach.id 247 244 vbox.registerMachine(mach) 248 245 # update cache … … 251 248 def removeVm(ctx, mach): 252 249 uuid = mach.id 253 print ("removing machine ", mach.name, "with UUID", uuid)250 print "removing machine ", mach.name, "with UUID", uuid 254 251 cmdClosedVm(ctx, mach, detachVmDevice, ["ALL"]) 255 252 disks = mach.unregister(ctx['global'].constants.CleanupMode_Full) … … 257 254 progress = mach.deleteConfig(disks) 258 255 if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0: 259 print ("Success!")256 print "Success!" 260 257 else: 261 258 reportError(ctx, progress) … … 274 271 try: 275 272 perf.setup(['*'], [mach], 10, 15) 276 except Exception ase:273 except Exception, e: 277 274 printErr(ctx, e) 278 275 if g_fVerbose: … … 327 324 return 328 325 for metric in ctx['perf'].query(["*"], [mach]): 329 print (metric['name'], metric['values_as_string'])326 print metric['name'], metric['values_as_string'] 330 327 331 328 def guestExec(ctx, machine, console, cmds): 332 exec (cmds)329 exec cmds 333 330 334 331 def 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) 336 333 337 334 def printKbdEvent(ctx, kev): 338 print ("Kbd: ", ctx['global'].getArray(kev, 'scancodes'))335 print "Kbd: ", ctx['global'].getArray(kev, 'scancodes') 339 336 340 337 def 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) 342 339 xPositions = ctx['global'].getArray(mtev, 'xPositions') 343 340 yPositions = ctx['global'].getArray(mtev, 'yPositions') … … 346 343 347 344 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]) 349 346 350 347 def monitorSource(ctx, eventSource, active, dur): 351 348 def handleEventImpl(event): 352 349 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)) 354 351 if evtype == ctx['global'].constants.VBoxEventType_OnMachineStateChanged: 355 352 scev = ctx['global'].queryInterface(event, 'IMachineStateChangedEvent') 356 353 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) 358 355 elif evtype == ctx['global'].constants.VBoxEventType_OnSnapshotTaken: 359 356 stev = ctx['global'].queryInterface(event, 'ISnapshotTakenEvent') 360 357 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) 362 359 elif evtype == ctx['global'].constants.VBoxEventType_OnGuestPropertyChanged: 363 360 gpcev = ctx['global'].queryInterface(event, 'IGuestPropertyChangedEvent') 364 361 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) 366 363 elif evtype == ctx['global'].constants.VBoxEventType_OnMousePointerShapeChanged: 367 364 psev = ctx['global'].queryInterface(event, 'IMousePointerShapeChangedEvent') … … 369 366 shape = ctx['global'].getArray(psev, 'shape') 370 367 if shape is None: 371 print ("pointer shape event - empty shape")368 print "pointer shape event - empty shape" 372 369 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)) 374 371 elif evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse: 375 372 mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent') … … 444 441 def handleEventImpl(event): 445 442 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)) 447 444 if evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse: 448 445 mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent') … … 492 489 493 490 header = demo.readline() 494 print ("Header is", header)491 print "Header is", header 495 492 basere = re.compile(r'(?P<s>\d+): (?P<t>[km]) (?P<p>.*)') 496 493 mre = re.compile(r'(?P<a>\d+) (?P<x>-*\d+) (?P<y>-*\d+) (?P<z>-*\d+) (?P<w>-*\d+) (?P<b>-*\d+)') … … 518 515 if rtype == 'k': 519 516 codes = kre.findall(params) 520 #print ("KBD:", codes)517 #print "KBD:", codes 521 518 kbd.putScancodes(codes) 522 519 elif rtype == 'm': … … 526 523 if mdict['a'] == '1': 527 524 # absolute 528 #print ("MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b'])525 #print "MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b'] 529 526 mouse.putMouseEventAbsolute(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b'])) 530 527 else: 531 #print ("MR: ", mdict['x'], mdict['y'], mdict['b'])528 #print "MR: ", mdict['x'], mdict['y'], mdict['b'] 532 529 mouse.putMouseEvent(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b'])) 533 530 … … 562 559 h = fbh 563 560 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) 565 562 data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_RGBA) 566 563 size = (w, h) … … 589 586 h = fbh 590 587 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) 592 589 data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_PNG) 593 590 pngfile = open(f, 'wb') … … 597 594 def teleport(ctx, _session, console, args): 598 595 if args[0].find(":") == -1: 599 print ("Use host:port format for teleport target")596 print "Use host:port format for teleport target" 600 597 return 601 598 (host, port) = args[0].split(":") … … 611 608 612 609 port = int(port) 613 print ("Teleporting to %s:%d..." % (host, port))610 print "Teleporting to %s:%d..." % (host, port) 614 611 progress = console.teleport(host, port, passwd, maxDowntime) 615 612 if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0: 616 print ("Success!")613 print "Success!" 617 614 else: 618 615 reportError(ctx, progress) … … 635 632 all_stats = ctx['const'].all_values('GuestStatisticType') 636 633 cpu = 0 637 for s in list(all_stats.keys()):634 for s in all_stats.keys(): 638 635 try: 639 636 val = guest.getStatistic( cpu, all_stats[s]) 640 print ("%s: %d" % (s, val))637 print "%s: %d" % (s, val) 641 638 except: 642 639 # likely not implemented … … 645 642 def plugCpu(_ctx, machine, _session, args): 646 643 cpu = int(args[0]) 647 print ("Adding CPU %d..." % (cpu))644 print "Adding CPU %d..." % (cpu) 648 645 machine.hotPlugCPU(cpu) 649 646 650 647 def unplugCpu(_ctx, machine, _session, args): 651 648 cpu = int(args[0]) 652 print ("Removing CPU %d..." % (cpu))649 print "Removing CPU %d..." % (cpu) 653 650 machine.hotUnplugCPU(cpu) 654 651 … … 664 661 665 662 def 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)) 667 664 668 665 def 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) 670 667 671 668 def 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")) 673 670 674 671 def ginfo(ctx, console, _args): 675 672 guest = console.guest 676 673 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" 684 681 usbs = ctx['global'].getArray(console, 'USBDevices') 685 print ("Attached USB:")682 print "Attached USB:" 686 683 for ud in usbs: 687 684 printUsbDev(ctx, ud) 688 685 rusbs = ctx['global'].getArray(console, 'remoteUSBDevices') 689 print ("Remote USB:")686 print "Remote USB:" 690 687 for ud in rusbs: 691 688 printHostUsbDev(ctx, ud) 692 print ("Transient shared folders:")689 print "Transient shared folders:" 693 690 sfs = rusbs = ctx['global'].getArray(console, 'sharedFolders') 694 691 for sf in sfs: … … 701 698 session = ctx['global'].getSessionObject(vbox) 702 699 mach.lockMachine(session, ctx['global'].constants.LockType_Shared) 703 except Exception ase:700 except Exception, e: 704 701 printErr(ctx, "Session to '%s' not open: %s" % (mach.name, str(e))) 705 702 if g_fVerbose: … … 707 704 return 708 705 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) 710 707 session.unlockMachine() 711 708 return … … 713 710 # in Webservices) functionality 714 711 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' 716 713 session.unlockMachine() 717 714 return … … 737 734 except KeyboardInterrupt: 738 735 ctx['interrupt'] = True 739 except Exception ase:736 except Exception, e: 740 737 printErr(ctx, e) 741 738 if g_fVerbose: … … 750 747 try: 751 748 cmd(ctx, mach, args) 752 except Exception ase:749 except Exception, e: 753 750 save = False 754 751 printErr(ctx, e) … … 758 755 try: 759 756 mach.saveSettings() 760 except Exception ase:757 except Exception, e: 761 758 printErr(ctx, e) 762 759 if g_fVerbose: … … 770 767 try: 771 768 cmd(ctx, mach, session.console, args) 772 except Exception ase:769 except Exception, e: 773 770 save = False 774 771 printErr(ctx, e) … … 780 777 781 778 def 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) 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 = list(commands.keys())918 print "Help page:" 919 names = 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 list(enumVals.keys()):934 for e in 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 ase: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: 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(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)) 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 (" '%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) 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:', oskind)1098 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 (user_inp) > 0: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", expr)1431 exec (expr)1430 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 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) 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 ase:1527 print "VirtualBox version %s" % (colored(vbox.version, 'blue')) 1528 except Exception, 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 (s)1739 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 (s)1769 print s 1770 1770 if context == 0: 1771 1771 active = False … … 1777 1777 active = True 1778 1778 context = 50 1779 print (s)1779 print s 1780 1780 uOffset += len(data) 1781 1781 … … 1785 1785 expr = ' '.join(args[1:]) 1786 1786 try: 1787 exec (expr)1788 except Exception ase:1787 exec expr 1788 except Exception, 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 ase:1807 print ("cannot open:", args[1], ":", e)1806 except IOError, e: 1807 print "cannot open:", args[1], ":", e 1808 1808 return 0 1809 1809 … … 1819 1819 break 1820 1820 1821 except Exception ase:1821 except Exception, 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 ase:1883 print "Running VirtualBox version %s" % (vbox.version) 1884 except Exception, 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 ase:1922 print "Running VirtualBox version %s" % (ctx['vb'].version) 1923 except Exception, 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", ch)2055 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 ase:2323 print ('failed: ', e)2322 except Exception, 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 list(alias.items()):2685 for aliasmode, aliaskey in alias.iteritems(): 2686 2686 if first == 0: 2687 2687 first = 1 … … 2689 2689 msg += ', ' 2690 2690 if int(nat.aliasMode) & aliaskey: 2691 msg += '% s: %s' % (aliasmode, 'on')2691 msg += '%d: %s' % (aliasmode, 'on') 2692 2692 else: 2693 msg += '%s: %s' % (aliasmode, 'off') 2693 msg += '%d: %s' % (aliasmode, 'off') 2694 msg += ')' 2694 2695 return (0, [msg]) 2695 2696 else: … … 2697 2698 if 'default' not in args: 2698 2699 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__ 2702 2703 return (1, None) 2703 2704 nat.aliasMode = int(nat.aliasMode) | alias[args[a]] … … 2722 2723 else: 2723 2724 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]) 2725 2726 return (1, None) 2726 2727 for i in range(2, len(args)): 2727 2728 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]) 2729 2730 return (1, None) 2730 2731 a = [args[1]] … … 2734 2735 else: 2735 2736 for i in range(2, len(args)): a.append(args[i]) 2736 #print (a)2737 #print a 2737 2738 nat.setNetworkSettings(int(a[0]), int(a[1]), int(a[2]), int(a[3]), int(a[4])) 2738 2739 return (0, None) … … 2785 2786 cmd = args[1] 2786 2787 if len(args) != 3: 2787 print ('invalid args:', args)2788 print (natTftp.__doc__)2788 print 'invalid args:', args 2789 print natTftp.__doc__ 2789 2790 return (1, None) 2790 2791 if cmd == 'prefix': nat.TFTPPrefix = args[2] … … 2792 2793 elif cmd == 'server': nat.TFTPNextServer = args[2] 2793 2794 else: 2794 print ("invalid cmd:", cmd)2795 print "invalid cmd:", cmd 2795 2796 return (1, None) 2796 2797 return (0, None) … … 2817 2818 pfcmd = { 2818 2819 '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, 2820 2821 'func':lambda: nat.addRedirect('', proto[args[2]], '', int(args[3]), '', int(args[4])) 2821 2822 }, 2822 2823 '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, 2824 2825 'func': lambda: nat.addRedirect('', proto[args[2]], args[3], int(args[4]), args[5], int(args[6])) 2825 2826 }, 2826 2827 '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, 2828 2829 'func': lambda: nat.addRedirect(args[3], proto[args[2]], args[4], int(args[5]), args[6], int(args[7])) 2829 2830 }, … … 2835 2836 2836 2837 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__ 2839 2840 return (1, None) 2840 2841 … … 2855 2856 (addr, mask) = args[1].split('/') 2856 2857 if addr.count('.') > 3 or int(mask) < 0 or int(mask) > 32: 2857 print ('Invalid arguments')2858 print 'Invalid arguments' 2858 2859 return (1, None) 2859 2860 nat.network = args[1] … … 2879 2880 if len(args) < 2 or args[1] == 'help': 2880 2881 if len(args) > 2: 2881 print (natcommands[args[2]].__doc__)2882 print natcommands[args[2]].__doc__ 2882 2883 else: 2883 print (natCmd.__doc__)2884 print natCmd.__doc__ 2884 2885 return 0 2885 2886 if len(args) == 1 or len(args) < 4 or args[3] not in natcommands: 2886 print (natCmd.__doc__)2887 print natCmd.__doc__ 2887 2888 return 0 2888 2889 mach = ctx['argsToMach'](args) 2889 2890 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)) 2894 2895 return 0 2895 2896 nicnum = int(args[2]) … … 2918 2919 for r in report: 2919 2920 msg ='%s nic%d %s: %s' % (mach.name, nicnum, func, r) 2920 print (msg)2921 print msg 2921 2922 return 0 2922 2923 … … 2929 2930 yesno = {'off' : 0, 'on' : 1} 2930 2931 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()) 2932 2933 return (1, None) 2933 2934 adapter.__setattr__(attr, yesno[args[1]]) … … 2952 2953 else: 2953 2954 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) 2956 2957 adapter.lineSpeed = int(args[1]) 2957 2958 return (0, None) … … 2975 2976 if len(args) == 1: 2976 2977 nictypes = ctx['const'].all_values('NetworkAdapterType') 2977 for key in list(nictypes.keys()):2978 for key in nictypes.keys(): 2978 2979 if str(adapter.adapterType) == str(nictypes[key]): 2979 2980 return (0, str(key)) … … 2981 2982 else: 2982 2983 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()) 2985 2986 return (1, None) 2986 2987 adapter.adapterType = nictypes[args[1]] … … 3001 3002 ctx['global'].constants.NetworkAttachmentType_Generic: ('Generic', ''), 3002 3003 } 3003 if type(adapter.attachmentType) != int: 3004 import types 3005 if type(adapter.attachmentType) != types.IntType: 3004 3006 t = str(adapter.attachmentType) 3005 3007 else: … … 3035 3037 'f': lambda: ctx['global'].constants.NetworkAttachmentType_Generic} 3036 3038 } 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()) 3039 3041 return (1, None) 3040 3042 if not nicAttachmentType[args[1]]['v'](): 3041 print (nicAttachmentType.__doc__)3043 print nicAttachmentType.__doc__ 3042 3044 return (1, None) 3043 3045 nicAttachmentType[args[1]]['p']() … … 3065 3067 if len(args) == 3 \ 3066 3068 and args[2] in niccomand: 3067 print (niccomand[args[2]].__doc__)3069 print niccomand[args[2]].__doc__ 3068 3070 else: 3069 print (nicCmd.__doc__)3071 print nicCmd.__doc__ 3070 3072 return 0 3071 3073 3072 3074 vm = ctx['argsToMach'](args) 3073 3075 if vm is None: 3074 print ('please specify vm')3076 print 'please specify vm' 3075 3077 return 0 3076 3078 3077 3079 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)) 3080 3082 return 0 3081 3083 nicnum = int(args[2]) … … 3090 3092 vm.saveSettings() 3091 3093 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) 3093 3095 session.unlockMachine() 3094 3096 return 0 … … 3097 3099 def promptCmd(ctx, args): 3098 3100 if len(args) < 2: 3099 print ("Current prompt: '%s'" % (ctx['prompt']))3101 print "Current prompt: '%s'" % (ctx['prompt']) 3100 3102 return 0 3101 3103 … … 3105 3107 def foreachCmd(ctx, args): 3106 3108 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']" 3108 3110 return 0 3109 3111 … … 3115 3117 e.apply(cmd) 3116 3118 except: 3117 print ("Error executing")3119 print "Error executing" 3118 3120 traceback.print_exc() 3119 3121 return 0 … … 3121 3123 def foreachvmCmd(ctx, args): 3122 3124 if len(args) < 2: 3123 print ("foreachvm command <args>")3125 print "foreachvm command <args>" 3124 3126 return 0 3125 3127 cmdargs = args[1:] … … 3131 3133 3132 3134 def 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)" 3135 3137 return 0 3136 3138 mach = argsToMach(ctx, args) … … 3145 3147 3146 3148 def 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)" 3149 3151 return 0 3150 3152 mach = argsToMach(ctx, args) … … 3167 3169 for a in assigned: 3168 3170 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)) 3170 3172 3171 3173 atts = ctx['global'].getArray(console, 'attachedPCIDevices') 3172 3174 for a in atts: 3173 3175 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)) 3175 3177 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)) 3177 3179 return 3178 3180 … … 3186 3188 3187 3189 def lspciCmd(ctx, args): 3188 if len(args) < 2:3189 print ("usage: lspci vm")3190 if (len(args) < 2): 3191 print "usage: lspci vm" 3190 3192 return 0 3191 3193 mach = argsToMach(ctx, args) … … 3196 3198 3197 3199 def 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>" 3200 3202 return 0 3201 3203 mach = argsToMach(ctx, args) … … 3204 3206 hostaddr = parsePci(args[2]) 3205 3207 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): 3210 3212 guestaddr = parsePci(args[3]) 3211 3213 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]) 3213 3215 return 0 3214 3216 else: … … 3218 3220 3219 3221 def 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" 3222 3224 return 0 3223 3225 mach = argsToMach(ctx, args) … … 3226 3228 hostaddr = parsePci(args[2]) 3227 3229 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]) 3229 3231 return 0 3230 3232 … … 3233 3235 3234 3236 def gotoCmd(ctx, args): 3235 if len(args) < 2:3236 print ("usage: goto line")3237 if (len(args) < 2): 3238 print "usage: goto line" 3237 3239 return 0 3238 3240 … … 3271 3273 'verbose':['Toggle verbosity', verboseCmd, 0], 3272 3274 '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], 3274 3276 'quit':['Exits', quitCmd, 0], 3275 3277 'host':['Show host information', hostCmd, 0], … … 3327 3329 'prompt' : ['Control shell prompt', promptCmd, 0], 3328 3330 '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], 3330 3332 'recordDemo':['Record demo: recordDemo Win32 file.dmo 10', recordDemoCmd, 0], 3331 3333 'playbackDemo':['Playback demo: playbackDemo Win32 file.dmo 10', playbackDemoCmd, 0], … … 3342 3344 ci = commands.get(c, None) 3343 3345 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) 3345 3347 return 0 3346 3348 if ctx['remote'] and ctx['vb'] is None: 3347 3349 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')) 3349 3351 return 0 3350 3352 return ci[1](ctx, args) … … 3352 3354 3353 3355 def runCommand(ctx, cmd): 3354 if not cmd: return 03356 if len(cmd) == 0: return 0 3355 3357 args = split_no_quotes(cmd) 3356 3358 if len(args) == 0: return 0 … … 3362 3364 # 3363 3365 # def runTestCmd(ctx, args): 3364 # print ("Testy test", ctx['vb'])3366 # print "Testy test", ctx['vb'] 3365 3367 # return 0 3366 3368 # … … 3379 3381 d = {} 3380 3382 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(): 3383 3385 if g_fVerbose: 3384 print ("customize: adding \"%s\" - %s" % (k, v[0]))3386 print "customize: adding \"%s\" - %s" % (k, v[0]) 3385 3387 cmds[k] = [v[0], v[1], filename] 3386 3388 except: 3387 print ("Error loading user extensions from %s" % (filename))3389 print "Error loading user extensions from %s" % (filename) 3388 3390 traceback.print_exc() 3389 3391 … … 3421 3423 if vbox is not None: 3422 3424 try: 3423 print ("Running VirtualBox version %s" % (vbox.version))3424 except Exception ase:3425 print "Running VirtualBox version %s" % (vbox.version) 3426 except Exception, e: 3425 3427 printErr(ctx, e) 3426 3428 if g_fVerbose: … … 3459 3461 cmd = 'runScript %s'% (g_sScriptFile) 3460 3462 elif g_sCmd is not None: 3461 cmd = next(it)3463 cmd = it.next() 3462 3464 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']) 3467 3466 done = runCommand(ctx, cmd) 3468 3467 if done != 0: break … … 3470 3469 break 3471 3470 except KeyboardInterrupt: 3472 print ('====== You can type quit or q to leave')3471 print '====== You can type quit or q to leave' 3473 3472 except StopIteration: 3474 3473 break 3475 3474 except EOFError: 3476 3475 break 3477 except Exception ase:3476 except Exception, e: 3478 3477 printErr(ctx, e) 3479 3478 if g_fVerbose: … … 3537 3536 3538 3537 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__)); 3541 3540 except: pass; # In case __file__ isn't there. 3542 3541 else: 3543 3542 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); 3546 3545 3547 3546 … … 3551 3550 if os.path.isfile(os.path.join(sCurLoc, "VirtualBox")) \ 3552 3551 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 3554 3553 os.environ["VBOX_PROGRAM_PATH"] = sCurLoc 3555 3554 sPath = sCurLoc 3556 break 3555 break; 3557 3556 if sPath: 3558 3557 sys.path.append(os.path.join(sPath, "sdk", "installer")) … … 3562 3561 for sCurLoc in asLocations: 3563 3562 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 3566 3565 os.environ["VBOX_SDK_PATH"] = sCurLoc 3567 sPath = sCurLoc 3568 break 3566 sPath = sCurLoc; 3567 break; 3569 3568 if sPath: 3570 sTmp = os.path.join(sCurLoc, ' bindings', 'xpcom', 'python')3569 sTmp = os.path.join(sCurLoc, 'sdk', 'bindings', 'xpcom', 'python'); 3571 3570 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; 3575 3574 3576 3575
Note:
See TracChangeset
for help on using the changeset viewer.