vboxshell.py revision cfeff5d2b11d81c5a7443e83c2e3eca153185bc5
#
#################################################################################
# This program is a simple interactive shell for VirtualBox. You can query #
# information and issue commands from a simple command line. #
# #
# It also provides you with examples on how to use VirtualBox's Python API. #
# This shell is even somewhat documented and supports TAB-completion and #
# history if you have Python readline installed. #
# #
# Enjoy. #
#################################################################################
#
# To make it work, the following variables have to be set.
# Please note the trailing slash in VBOX_PROGRAM_PATH - it's a must.
#
# This is the place where VirtualBox resides
# To allow Python find modules
# export PYTHONPATH=$VBOX_PROGRAM_PATH/sdk/bindings/xpcom/python:$VBOX_PROGRAM_PATH
# To allow library resolution
# export LD_LIBRARY_PATH=$VBOX_PROGRAM_PATH
# Additionally, on 64-bit Solaris, you need to use 64-bit Python from
# Python do the following:
# mkdir $VBOX_PROGRAM_PATH/64
# ln -s $VBOX_PROGRAM_PATH/VBoxPython.so $VBOX_PROGRAM_PATH/64/VBoxPython.so
#
import traceback
import sys
import pdb
g_hasreadline = 1
try:
import readline
import rlcompleter
except:
g_hasreadline = 0
# this one has to be the first XPCOM related import
import xpcom
import xpcom.components
class LocalManager:
if g_hasreadline:
"""
taken from:
"""
if text == "":
return ['\t',None][state]
else:
"""
Compute matches when text is a simple name.
Return a list of all names currently defined
in self.namespace that match.
"""
matches = []
return matches
if not g_hasreadline:
return
comps = {}
comps[k] = None
def split_no_quotes(s):
return s.split()
def getMachines(ctx):
if var:
return 'on'
else:
return 'off'
stats = {
}
try:
print "'%s' = '%s'" %(k,str(v))
except:
print "Cannot get value for '%s'" %(k)
pass
try:
except Exception,e:
if g_verbose:
return
return
# can cache known machines, if needed
mach = None
for m in getMachines(ctx):
mach = m
break
return mach
return None
if m == None:
print "Machine '%s' is unknown, use list command to find available machines" %(id)
return m
print "Help page:"
for i in commands:
else:
if c == None:
else:
return 0
for m in getMachines(ctx):
return 0
print "usage: info [vmname|uuid]"
return 0
if mach == None:
return 0
return 0
if mach == None:
return 0
else:
type = "gui"
return 0
if mach == None:
return 0
return 0
if mach == None:
return 0
return 0
if mach == None:
return 0
return 0
if mach == None:
return 0
return 0
return 1
print "'%s' is an alias for '%s'" %(k,v)
return 0
global g_verbose
return 0
print "Processor count:",cnt
return 0
'i':'info',
'l':'list',
'h':'help',
'a':'aliases',
'q':'quit', 'exit':'quit',
'v':'verbose'}
c = args[0]
c = aliases[c]
if ci == None:
print "Unknown command: '%s', type 'help' for list of known commands" %(c)
return 0
def interpret():
vbox = None
try:
print "XPCOM exception: ",e
return
mgr = LocalManager()
while True:
try:
if done != 0: break
except KeyboardInterrupt:
print '====== You can type quit or q to leave'
break
except EOFError:
break;
except Exception,e:
print e
if g_verbose: