VirtualBox

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


Ignore:
Timestamp:
Jul 7, 2009 1:47:28 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49676
Message:

Python shell: adding shell command, repeat count for runScript

File:
1 edited

Legend:

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

    r21330 r21331  
    236236    progress = vb.openRemoteSession(session, uuid, type, "")
    237237    progress.waitForCompletion(-1)
    238     completed = progress.completed
    239     rc = int(progress.resultCode)
    240     print "Completed:", completed, "rc:",hex(rc&0xffffffff)
     238    rc = long(progress.resultCode)
     239    #print "Completed:", progress.completed, "rc:",hex(rc&0xffffffff)
    241240    if rc == 0:
    242241        # we ignore exceptions to allow starting VM even if
     
    333332    ops={'pause' :     lambda: console.pause(),
    334333         'resume':     lambda: console.resume(),
    335          'powerdown':  lambda: console.powerDown(),
     334         'powerdown':  lambda: console.powerDown().waitForCompletion(-1),
    336335         'powerbutton':  lambda: console.powerButton(),
    337336         'stats':      lambda: guestStats(ctx, mach),
     
    675674
    676675def runScriptCmd(ctx, args):
    677     if (len(args) != 2):
    678         print "usage: runScript <script>"
    679         return 0
     676    import time
     677    if (len(args) < 2 or len (args) > 4):
     678        print "usage: runScript <script> <times> <pause>"
     679        return 0
     680
     681    if len (args) >= 3:
     682        times = int(args[2])
     683        if g_verbose:
     684            print "repeating %d times" %(times)
     685    else:
     686        times = 1
     687
     688    if len (args) >= 4:
     689        pause = int(args[3])
     690    else:
     691        pause = 0
     692   
    680693    try:
    681694        lf = open(args[1], 'r')
     
    684697        return 0
    685698
     699    script = []
    686700    try:
    687701        for line in lf:
    688             done = runCommand(ctx, line)
    689             if done != 0: break
     702            script.append(line)
     703
     704        for i in range(times):
     705            for line in script:
     706                done = runCommand(ctx, line)
     707                if done != 0: break
     708            if g_verbose:
     709                print "%d done" %(i)
     710            if i != times - 1 and pause != 0:
     711                time.sleep(pause)
    690712    except Exception,e:
    691713        print "error:",e
     
    695717    return 0
    696718
     719
     720def runShellCmd(ctx, args):
     721    if len (args) < 2:
     722        print "usage: shell <command>"
     723    expr = ' '.join(args[1:])
     724    try:
     725        os.system(expr)
     726    except Exception,e:
     727        print "error:",e
     728        if g_verbose:
     729                traceback.print_exc()
     730    return 0
    697731
    698732aliases = {'s':'start',
     
    728762            'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0],
    729763            'reloadExt':['Reload custom extensions: reloadExt', reloadExtCmd, 0],
    730             'runScript':['Run VBox script: runScript script.vbox', runScriptCmd, 0],
     764            'runScript':['Run VBox script: runScript script.vbox <times>', runScriptCmd, 0],
     765            'shell':['Execute system shell command: shell ls -l', runShellCmd, 0],
    731766            }
    732767
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