VirtualBox

Changeset 28631 in vbox


Ignore:
Timestamp:
Apr 23, 2010 8:57:19 AM (15 years ago)
Author:
vboxsync
Message:

vbox shell: usb control, cancellation

File:
1 edited

Legend:

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

    r28621 r28631  
    225225            p.waitForCompletion(wait)
    226226            ctx['global'].waitForEvents(0)
     227        return 0
    227228    except KeyboardInterrupt:
    228229        print "Interrupted."
     230        if p.cancelable:
     231            print "Canceling task..."
     232            p.cancel()
     233        return 1
     234       
    229235
    230236
     
    439445    machine.saveSettings()
    440446
     447def cond(c,v1,v2):
     448    if c:
     449        return v1
     450    else:
     451        return v2
     452
     453def printHostUsbDev(ctx,ud):
     454    print "  %s: %s (vendorId=%d productId=%d serial=%s) %s" %(ud.id, ud.product, ud.vendorId, ud.productId, ud.serialNumber,getUSBStateString(ud.state))
     455
     456def printUsbDev(ctx,ud):
     457    print "  %s: %s (vendorId=%d productId=%d serial=%s)" %(ud.id, ud.product, ud.vendorId, ud.productId, ud.serialNumber)
     458
     459def printSf(ctx,sf):
     460    print "name=%s host=%s %s %s" %(sf.name, sf.hostPath, cond(sf.accessible, "accessible", "not accessible"), cond(sf.writable, "writable", "read-only"))
     461
    441462def ginfo(ctx,console, args):
    442463    guest = console.guest
     
    450471    else:
    451472        print "No additions"
     473    usbs = ctx['global'].getArray(console, 'USBDevices')
     474    print "Attached USB:"
     475    for ud in usbs:
     476         printUsbDev(ctx,ud)
     477    rusbs = ctx['global'].getArray(console, 'remoteUSBDevices')
     478    print "Remote USB:"
     479    for ud in rusbs:
     480        printHostUsbDev(ctx,ud)
     481    print "Transient shared folders:"
     482    sfs =  rusbs = ctx['global'].getArray(console, 'sharedFolders')
     483    for sf in sfs:
     484        printSf(ctx,sf)
    452485
    453486def cmdExistingVm(ctx,mach,cmd,args):
     
    487520         'plugcpu':         lambda: plugCpu(ctx, session.machine, session, args),
    488521         'unplugcpu':       lambda: unplugCpu(ctx, session.machine, session, args),
    489          'mountiso':        lambda: mountIso(ctx, session.machine, session, args)
     522         'mountiso':        lambda: mountIso(ctx, session.machine, session, args),
    490523         }
    491524    try:
     
    10321065   print "USB devices:"
    10331066   for ud in ctx['global'].getArray(host, 'USBDevices'):
    1034        print "  %s (vendorId=%d productId=%d serial=%s) %s" %(ud.product, ud.vendorId, ud.productId, ud.serialNumber, getUSBStateString(ud.state))
     1067       printUsbHostDev(ctx,ud)
    10351068
    10361069   if ctx['perf']:
     
    12691302    p = app.write(format, path)
    12701303    progressBar(ctx, p)
    1271     print "Exported to %s in format %s" %(path, format)
     1304    if (p.completed and int(p.resultCode) == 0):
     1305        print "Exported to %s in format %s" %(path, format)
    12721306    return 0
    12731307
     
    15031537   return 0
    15041538
     1539def listUsbCmd(ctx,args):
     1540   if (len(args) > 1):
     1541      print "usage: listUsb"
     1542      return 0
     1543
     1544   host = ctx['vb'].host
     1545   for ud in ctx['global'].getArray(host, 'USBDevices'):
     1546       printHostUsbDev(ctx,ud)
     1547
     1548   return 0
     1549
    15051550def createHddCmd(ctx,args):
    15061551   if (len(args) < 3):
     
    18121857   return 0
    18131858
     1859def usbctr(ctx,mach,console,args):
     1860    if (args[0]):
     1861        console.attachUSBDevice(args[1])
     1862    else:
     1863        console.detachUSBDevice(args[1])
     1864
     1865def attachUsbCmd(ctx,args):
     1866   if (len(args) < 3):
     1867      print "usage: attachUsb vm deviceuid"
     1868      return 0
     1869
     1870   mach = argsToMach(ctx,args)
     1871   if mach is None:
     1872        return 0
     1873   dev = args[2]
     1874   cmdExistingVm(ctx, mach, 'guestlambda', [usbctr,True,dev])
     1875   return 0
     1876
     1877def detachUsbCmd(ctx,args):
     1878   if (len(args) < 3):
     1879      print "usage: detachUsb vm deviceuid"
     1880      return 0
     1881
     1882   mach = argsToMach(ctx,args)
     1883   if mach is None:
     1884        return 0
     1885   dev = args[2]
     1886   cmdExistingVm(ctx, mach, 'guestlambda', [usbctr,False,dev])
     1887   return 0
    18141888
    18151889aliases = {'s':'start',
     
    18771951            'attachCtr': ['Attach storage controller to the VM: attachCtr win Ctr0 IDE ICH6', attachCtrCmd, 0],
    18781952            'detachCtr': ['Detach HDD from the VM: detachCtr win Ctr0', detachCtrCmd, 0],
    1879             'listMediums': ['List mediums known to this VBox instance', listMediumsCmd, 0]
     1953            'attachUsb': ['Attach USB device to the VM (use listUsb to show available devices): attachUsb win uuid', attachUsbCmd, 0],
     1954            'detachUsb': ['Detach USB device from the VM: detachUsb win uui', detachUsbCmd, 0],
     1955            'listMediums': ['List mediums known to this VBox instance', listMediumsCmd, 0],
     1956            'listUsb': ['List known USB devices', listUsbCmd, 0]
    18801957            }
    18811958
Note: See TracChangeset for help on using the changeset viewer.

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