VirtualBox

Changeset 21330 in vbox


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

Python shell: execute external scripts, autodetect path

File:
1 edited

Legend:

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

    r21245 r21330  
    673673   return 0
    674674
     675
     676def runScriptCmd(ctx, args):
     677    if (len(args) != 2):
     678        print "usage: runScript <script>"
     679        return 0
     680    try:
     681        lf = open(args[1], 'r')
     682    except IOError,e:
     683        print "cannot open:",args[1], ":",e
     684        return 0
     685
     686    try:
     687        for line in lf:
     688            done = runCommand(ctx, line)
     689            if done != 0: break
     690    except Exception,e:
     691        print "error:",e
     692        if g_verbose:
     693                traceback.print_exc()
     694    lf.close()
     695    return 0
     696
     697
    675698aliases = {'s':'start',
    676699           'i':'info',
     
    705728            'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0],
    706729            'reloadExt':['Reload custom extensions: reloadExt', reloadExtCmd, 0],
     730            'runScript':['Run VBox script: runScript script.vbox', runScriptCmd, 0],
    707731            }
    708732
     
    788812        pass
    789813
    790 
    791 from vboxapi import VirtualBoxManager
    792 
    793 def main(argv):   
     814def main(argv):
    794815    style = None
    795     if len(argv) > 1:
    796         if argv[1] == "-w":
     816    autopath = False
     817    argv.pop(0)
     818    while len(argv) > 0:
     819        if argv[0] == "-w":
    797820            style = "WEBSERVICE"
    798        
     821        if argv[0] == "-a":
     822            autopath = True
     823        argv.pop(0)
     824
     825    if autopath:
     826        cwd = os.getcwd()
     827        vpp = os.environ.get("VBOX_PROGRAM_PATH")
     828        if vpp is None and (os.path.isfile(os.path.join(cwd, "VirtualBox")) or os.path.isfile(os.path.join(cwd, "VirtualBox.exe"))) :
     829            vpp = cwd
     830            print "Autodetected VBOX_PROGRAM_PATH as",vpp
     831            os.environ["VBOX_PROGRAM_PATH"] = cwd
     832            sys.path.append(os.path.join(vpp, "sdk", "installer"))
     833
     834    from vboxapi import VirtualBoxManager
    799835    g_virtualBoxManager = VirtualBoxManager(style, None)
    800836    ctx = {'global':g_virtualBoxManager,
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