VirtualBox

Ignore:
Timestamp:
Aug 1, 2009 3:55:25 AM (15 years ago)
Author:
vboxsync
Message:

Python shell: fixes, shell extension dirs support

File:
1 edited

Legend:

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

    r21907 r21924  
    206206    return shlex.split(s)
    207207
     208def progressBar(ctx,p,wait=1000):
     209    try:
     210        while not p.completed:
     211            print "%d %%\r" %(p.percent),
     212            sys.stdout.flush()
     213            p.waitForCompletion(wait)
     214    except KeyboardInterrupt:
     215        print "Interrupted."
     216
    208217def createVm(ctx,name,kind,base):
    209218    mgr = ctx['mgr']
     
    223232    session = ctx['global'].openMachineSession(id)
    224233    try:
    225        mach = session.Machine
     234       mach = session.machine
    226235       for d in ctx['global'].getArray(mach, 'hardDiskAttachments'):
    227236          mach.detachHardDisk(d.controller, d.port, d.device)
    228237    except:
    229238       traceback.print_exc()
     239    mach.saveSettings()
    230240    ctx['global'].closeMachineSession(session)
    231241    mach = vb.unregisterMachine(id)
     
    242252    uuid = mach.id
    243253    progress = vb.openRemoteSession(session, uuid, type, "")
    244     progress.waitForCompletion(-1)
     254    progressBar(ctx, progress, 100)
    245255    completed = progress.completed
    246256    rc = int(progress.resultCode)
     
    348358         'guest':           lambda: guestExec(ctx, mach, console, args),
    349359         'monitorGuest':    lambda: monitorGuest(ctx, mach, console, args),
    350          'save':            lambda: console.saveState().waitForCompletion(-1)
     360         'save':            lambda: progressBar(ctx,console.saveState())
    351361         }
    352362    try:
     
    383393    return m
    384394
     395def helpSingleCmd(cmd,h,sp):
     396    if sp != 0:
     397        spec = " [ext from "+sp+"]"
     398    else:
     399        spec = ""
     400    print "    %s: %s%s" %(cmd,h,spec)
     401
    385402def helpCmd(ctx, args):
    386403    if len(args) == 1:
     
    389406        names.sort()
    390407        for i in names:
    391             print "   ",i,":", commands[i][0]
    392     else:
    393         c = commands.get(args[1], None)
     408            helpSingleCmd(i, commands[i][0], commands[i][2])
     409    else:
     410        cmd = args[1]
     411        c = commands.get(cmd)
    394412        if c == None:
    395             print "Command '%s' not known" %(args[1])
     413            print "Command '%s' not known" %(cmd)
    396414        else:
    397             print "   ",args[1],":", c[0]
     415            helpSingleCmd(cmd, c[0], c[2])
    398416    return 0
    399417
     
    905923    desc.addDescription(ctx['global'].constants.VirtualSystemDescriptionType_License, license, "")
    906924    p = app.write(format, path)
    907     try:
    908         while not p.completed:
    909             print "%d %%\r" %(p.percent),
    910             sys.stdout.flush()
    911             p.waitForCompletion(1000)
    912     except KeyboardInterrupt:
    913         print "Interrupted."
     925    progressBar(ctx, p)
    914926    print "Exported to %s in format %s" %(path, format)
    915927    return 0
     
    982994# }
    983995# and issue reloadExt shell command.
    984 # This file also will be read automatically on startup.
     996# This file also will be read automatically on startup or 'reloadExt'.
    985997#
    986 def checkUserExtensions(ctx, cmds, folder):
    987     name =  os.path.join(str(folder), "shellext.py")
    988     if not os.path.isfile(name):
     998# Also one can put shell extensions into ~/.VirtualBox/shexts and
     999# they will also be picked up, so this way one can exchange
     1000# shell extensions easily.
     1001def addExtsFromFile(ctx, cmds, file):
     1002    if not os.path.isfile(file):
    9891003        return
    9901004    d = {}
    9911005    try:
    992         execfile(name, d, d)
     1006        execfile(file, d, d)
    9931007        for (k,v) in d['commands'].items():
    9941008            if g_verbose:
    9951009                print "customize: adding \"%s\" - %s" %(k, v[0])
    996             cmds[k] = [v[0], v[1], 1]
     1010            cmds[k] = [v[0], v[1], file]
    9971011    except:
    998         print "Error loading user extensions:"
     1012        print "Error loading user extensions from %s" %(file)
    9991013        traceback.print_exc()
     1014
     1015
     1016def checkUserExtensions(ctx, cmds, folder):
     1017    name =  os.path.join(folder, "shellext.py")
     1018    addExtsFromFile(ctx, cmds, name)
     1019    # also check 'exts' directory for all files
     1020    shextdir = os.path.join(folder, "shexts")
     1021    if not os.path.isdir(shextdir):
     1022        return
     1023    exts = os.listdir(shextdir)
     1024    for e in exts:
     1025        addExtsFromFile(ctx, cmds, os.path.join(shextdir,e))
    10001026
    10011027def interpret(ctx):   
     
    10821108           'run': lambda cmd,args: runCommandCb(ctx, cmd, args),
    10831109           'machById': lambda id: machById(ctx,id),
     1110           'progressBar': lambda p: progressBar(ctx,p),
    10841111           '_machlist':None
    10851112           }
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