VirtualBox

Ignore:
Timestamp:
Apr 23, 2010 2:15:14 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60510
Message:

VBoxPython: smarter ISO mounter, better gexec

File:
1 edited

Legend:

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

    r28637 r28650  
    234234
    235235def reportError(ctx,progress):
    236     print progress.errorInfo
     236    ei = progress.errorInfo
     237    if ei:
     238        print "Error in %s: %s" %(ei.component, ei.text)
    237239
    238240def createVm(ctx,name,kind,base):
     
    745747    passwd = ""
    746748    tmo = 0
    747     print "executing %s with %s" %(args[0], args[1:])
    748     (progress, pid) = console.guest.executeProcess(args[0], 0, args[1:], [], "", "", "", user, passwd, tmo)
    749     if progressBar(ctx,progress, 10):
    750         print "executed with pid %d" %(pid)
     749    guest = console.guest
     750    print "executing %s with args %s" %(args[0], args[1:])
     751    (progress, pid) = guest.executeProcess(args[0], 0, args[1:], [], "", "", "", user, passwd, tmo)
     752    print "executed with pid %d" %(pid)
     753    if pid != 0:
     754        while not progress.completed:
     755            data = guest.getProcessOutput(pid, 0, 1, 4096)
     756            if data and len(data) > 0:
     757                sys.stdout.write(data)
     758            progress.waitForCompletion(100)
     759            ctx['global'].waitForEvents(0)
    751760    else:
    752761        reportError(ctx, progress)
     
    763772    cmdExistingVm(ctx, mach, 'guestlambda', gargs)
    764773    return 0
     774
     775def gcatCmd(ctx,args):
     776    if (len(args) < 2):
     777        print "usage: gcat [vmname|uuid] local_file | guestProgram, such as gcat linux /home/nike/.bashrc | sh -c 'cat >'"
     778        return 0
     779    mach = argsToMach(ctx,args)
     780    if mach == None:
     781        return 0
     782    gargs = args[2:]
     783    gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args))
     784    cmdExistingVm(ctx, mach, 'guestlambda', gargs)
     785    return 0
     786
    765787
    766788def removeVmCmd(ctx, args):
     
    15411563   return 0
    15421564
     1565
     1566def findDevOfType(ctx,mach,type):
     1567    atts = ctx['global'].getArray(mach, 'mediumAttachments')
     1568    for a in atts:
     1569        if a.type == type:
     1570            return [a.controller, a.port, a.device]
     1571    return [None, 0, 0]
     1572
    15431573def createHddCmd(ctx,args):
    15441574   if (len(args) < 3):
     
    15841614
    15851615def attachHddCmd(ctx,args):
    1586    if (len(args) < 4):
     1616   if (len(args) < 3):
    15871617      print "usage: attachHdd vm hdd controller port:slot"
    15881618      return 0
     
    15981628      print "no HDD with path %s registered" %(loc)
    15991629      return 0
    1600    ctr = args[3]
    1601    (port,slot) = args[4].split(":")
     1630   if len(args) > 3:
     1631       ctr = args[3]
     1632       (port,slot) = args[4].split(":")
     1633   else:
     1634       [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_HardDisk)
     1635
    16021636   cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_HardDisk,hdd.id))
    16031637   return 0
     
    17301764
    17311765def attachIsoCmd(ctx,args):
    1732    if (len(args) < 5):
     1766   if (len(args) < 3):
    17331767      print "usage: attachIso vm iso controller port:slot"
    17341768      return 0
     
    17441778      print "no DVD with path %s registered" %(loc)
    17451779      return 0
    1746    ctr = args[3]
    1747    (port,slot) = args[4].split(":")
     1780   if len(args) > 3:
     1781       ctr = args[3]
     1782       (port,slot) = args[4].split(":")
     1783   else:
     1784       [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_DVD)
    17481785   cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_DVD,dvd.id))
    17491786   return 0
     
    17691806
    17701807def mountIsoCmd(ctx,args):
    1771    if (len(args) < 5):
     1808   if (len(args) < 3):
    17721809      print "usage: mountIso vm iso controller port:slot"
    17731810      return 0
     
    17841821      return 0
    17851822
    1786    ctr = args[3]
    1787    (port,slot) = args[4].split(":")
     1823   if len(args) > 3:
     1824       ctr = args[3]
     1825       (port,slot) = args[4].split(":")
     1826   else:
     1827       # autodetect controller and location, just find first controller with media == DVD
     1828       [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_DVD)
    17881829
    17891830   cmdExistingVm(ctx, mach, 'mountiso', [ctr, port, slot, dvd.id, True])
     
    17921833
    17931834def unmountIsoCmd(ctx,args):
    1794    if (len(args) < 4):
     1835   if (len(args) < 2):
    17951836      print "usage: unmountIso vm controller port:slot"
    17961837      return 0
     
    18011842   vb = ctx['vb']
    18021843
    1803    ctr = args[2]
    1804    (port,slot) = args[3].split(":")
     1844   if len(args) > 2:
     1845       ctr = args[2]
     1846       (port,slot) = args[3].split(":")
     1847   else:
     1848       # autodetect controller and location, just find first controller with media == DVD
     1849       [ctr, port, slot] = findDevOfType(ctx, mach, ctx['global'].constants.DeviceType_DVD)
    18051850
    18061851   cmdExistingVm(ctx, mach, 'mountiso', [ctr, port, slot, "", True])
Note: See TracChangeset for help on using the changeset viewer.

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