VirtualBox

Changeset 30437 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 24, 2010 1:47:46 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63079
Message:

VBoxShell: option parser has been inroduced (from python 2.3) and options disscused in xTracker/#4329.

File:
1 edited

Legend:

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

    r30389 r30437  
    3030import re
    3131import platform
     32from optparse import OptionParser
    3233
    3334# Simple implementation of IConsoleCallback, one can use it as skeleton
     
    134135       print "onGuestPropertyChange: %s: %s=%s" %(id, name, newValue)
    135136
     137g_batchmode = False
     138g_scripfile = None
     139g_cmd = None
    136140g_hasreadline = True
    137141try:
     
    25922596        nat.network = args[1]
    25932597    return (0, None)
     2598
    25942599def natCmd(ctx, args):
    25952600    """This command is entry point to NAT settins management
     
    30503055      except:
    30513056        pass
     3057    cmds = []
     3058   
     3059    if g_cmd is not None:
     3060        cmds = g_cmd.split(';')
     3061    it = cmds.__iter__()
    30523062
    30533063    while True:
    30543064        try:
    3055             cmd = raw_input(ctx['prompt'])
     3065            if g_batchmode:
     3066                cmd = 'runScript %s'%(g_scripfile)
     3067            elif g_cmd is not None:
     3068                cmd = it.next()
     3069            else:
     3070                cmd = raw_input(ctx['prompt'])
    30563071            done = runCommand(ctx, cmd)
    30573072            if done != 0: break
     3073            if g_batchmode:
     3074                break
    30583075        except KeyboardInterrupt:
    30593076            print '====== You can type quit or q to leave'
     3077        except StopIteration:
     3078            break
    30603079        except EOFError:
    30613080            break
     
    30883107def main(argv):
    30893108    style = None
     3109    params = None
    30903110    autopath = False
    3091     argv.pop(0)
    3092     while len(argv) > 0:
    3093         if argv[0] == "-w":
    3094             style = "WEBSERVICE"
    3095         if argv[0] == "-a":
    3096             autopath = True
    3097         argv.pop(0)
    3098 
    3099     if autopath:
     3111    script_file = None
     3112    parse = OptionParser()
     3113    parse.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help = "switch on verbose")
     3114    parse.add_option("-a", "--autopath", dest="autopath", action="store_true", default=False, help = "switch on autopath")
     3115    parse.add_option("-w", "--webservice", dest="style", action="store_const", const="WEBSERVICE", help = "connect to webservice")
     3116    parse.add_option("-b", "--batch", dest="batch_file", help = "script file to execute")
     3117    parse.add_option("-c", dest="command_line", help = "command sequence to execute")
     3118    parse.add_option("-o", dest="opt_line", help = "option line")
     3119    global g_verbose, g_scripfile, g_batchmode, g_hascolors, g_hasreadline, g_cmd
     3120    (options, args) = parse.parse_args()
     3121    g_verbose = options.verbose
     3122    style = options.style
     3123    if options.batch_file is not None:
     3124        g_batchmode = True
     3125        g_hascolors = False
     3126        g_hasreadline = False
     3127        g_scripfile = options.batch_file
     3128    if options.command_line is not None:
     3129        g_hascolors = False
     3130        g_hasreadline = False
     3131        g_cmd = options.command_line
     3132    if options.opt_line is not None:
     3133        params = {}
     3134        strparams = options.opt_line
     3135        l = strparams.split(',')
     3136        for e in l:
     3137            (k,v) = e.split('=')
     3138            params[k] = v
     3139    else:
     3140        params = None
     3141
     3142    if options.autopath:
    31003143        cwd = os.getcwd()
    31013144        vpp = os.environ.get("VBOX_PROGRAM_PATH")
     
    31073150
    31083151    from vboxapi import VirtualBoxManager
    3109     g_virtualBoxManager = VirtualBoxManager(style, None)
     3152    g_virtualBoxManager = VirtualBoxManager(style, params)
    31103153    ctx = {'global':g_virtualBoxManager,
    31113154           'mgr':g_virtualBoxManager.mgr,
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