1 | #!/usr/bin/python
|
---|
2 | #
|
---|
3 | #################################################################################
|
---|
4 | # This program is a simple interactive shell for VirtualBox. You can query #
|
---|
5 | # information and issue commands from a simple command line. #
|
---|
6 | # #
|
---|
7 | # It also provides you with examples on how to use VirtualBox's Python API. #
|
---|
8 | # This shell is even somewhat documented and supports TAB-completion and #
|
---|
9 | # history if you have Python readline installed. #
|
---|
10 | # #
|
---|
11 | # Enjoy. #
|
---|
12 | #################################################################################
|
---|
13 | #
|
---|
14 | # To make it work, the following variables have to be set.
|
---|
15 | # Please note the trailing slash in VBOX_PROGRAM_PATH - it's a must.
|
---|
16 | #
|
---|
17 | # This is the place where VirtualBox resides
|
---|
18 | # export VBOX_PROGRAM_PATH=/opt/VirtualBox-2.0.0/
|
---|
19 | # To allow Python find modules
|
---|
20 | # export PYTHONPATH=../:$VBOX_PROGRAM_PATH
|
---|
21 | #
|
---|
22 |
|
---|
23 | # this one has to be the first XPCOM related import
|
---|
24 | import xpcom.vboxxpcom
|
---|
25 | import xpcom
|
---|
26 | import xpcom.components
|
---|
27 | import sys, traceback
|
---|
28 |
|
---|
29 | from shellcommon import interpret
|
---|
30 |
|
---|
31 | class LocalManager:
|
---|
32 | def getSessionObject(self, vb):
|
---|
33 | return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
|
---|
34 |
|
---|
35 | vbox = None
|
---|
36 | mgr = LocalManager()
|
---|
37 | try:
|
---|
38 | vbox = xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
|
---|
39 | except xpcom.Exception, e:
|
---|
40 | print "XPCOM exception: ",e
|
---|
41 | traceback.print_exc()
|
---|
42 | sys.exit(1)
|
---|
43 |
|
---|
44 | ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':xpcom.components.interfaces, 'remote':False}
|
---|
45 |
|
---|
46 | interpret(ctx)
|
---|
47 |
|
---|
48 | del vbox
|
---|