VirtualBox

Changeset 36048 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 22, 2011 10:59:08 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
70158
Message:

vboxshell: flow control and interrupts when running scripts

File:
1 edited

Legend:

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

    r36002 r36048  
    181181    except KeyboardInterrupt:
    182182        print "Interrupted."
     183        ctx['interrupt'] = True
    183184        if p.cancelable:
    184185            print "Canceling task..."
     
    489490
    490491    # We need to catch all exceptions here, to close file
     492    except KeyboardInterrupt:
     493        ctx['interrupt'] = True
    491494    except:
    492495        traceback.print_exc()
     
    691694    try:
    692695        ops[cmd]()
     696    except KeyboardInterrupt:
     697        ctx['interrupt'] = True
    693698    except Exception, e:
    694699        printErr(ctx,e)
     
    11181123        except KeyboardInterrupt:
    11191124            print "Interrupted."
     1125            ctx['interrupt'] = True
    11201126            if progress.cancelable:
    11211127                progress.cancel()
     
    17351741   return 0
    17361742
    1737 
    17381743def runScriptCmd(ctx, args):
    17391744    if (len(args) != 2):
     
    17471752
    17481753    try:
    1749         for line in lf:
     1754        lines = lf.readlines()
     1755        ctx['scriptLine'] = 0
     1756        ctx['interrupt'] = False
     1757        while ctx['scriptLine'] < len(lines):
     1758            line = lines[ctx['scriptLine']]
     1759            ctx['scriptLine'] = ctx['scriptLine'] + 1
    17501760            done = runCommand(ctx, line)
    1751             if done != 0: break
     1761            if done != 0 or ctx['interrupt']:
     1762                break
     1763
    17521764    except Exception,e:
    17531765        printErr(ctx,e)
     
    31563168
    31573169    cmdClosedVm(ctx, mach, lambda ctx,mach,a: mach.detachHostPciDevice(hostaddr))
     3170    return 0
     3171
     3172def gotoCmd(ctx, args):
     3173    if (len(args) < 2):
     3174        print "usage: goto line"
     3175        return 0
     3176
     3177    line = int(args[1])
     3178
     3179    ctx['scriptLine'] = line
     3180
    31583181    return 0
    31593182
     
    32463269            'lspci': ['List PCI devices attached to the VM: lspci Win32', lspciCmd, 0],
    32473270            'attachpci': ['Attach host PCI device to the VM: attachpci Win32 01:00.0', attachpciCmd, 0],
    3248             'detachpci': ['Detach host PCI device from the VM: detachpci Win32 01:00.0', detachpciCmd, 0]
     3271            'detachpci': ['Detach host PCI device from the VM: detachpci Win32 01:00.0', detachpciCmd, 0],
     3272            'goto': ['Go to line in script (script-only)', gotoCmd, 0]
    32493273            }
    32503274
     
    34733497           'typeInGuest': typeInGuest,
    34743498           '_machlist': None,
    3475            'prompt': g_prompt
     3499           'prompt': g_prompt,
     3500           'scriptLine': 0,
     3501           'interrupt': False
    34763502           }
    34773503    interpret(ctx)
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