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=/home/nike/work/ws/out/linux.amd64/debug/bin/
|
---|
19 | # To allow Python find modules
|
---|
20 | # export PYTHONPATH=$VBOX_PROGRAM_PATH/sdk/bindings/xpcom/python:$VBOX_PROGRAM_PATH
|
---|
21 | #
|
---|
22 | # Additionally, on 64-bit Solaris, you need to use 64-bit Python from
|
---|
23 | # /usr/bin/amd64/python and due to quirks in native modules loading of
|
---|
24 | # Python do the following:
|
---|
25 | # mkdir $VBOX_PROGRAM_PATH/64
|
---|
26 | # ln -s $VBOX_PROGRAM_PATH/VBoxPython.so $VBOX_PROGRAM_PATH/64/VBoxPython.so
|
---|
27 | #
|
---|
28 | # Mac OS X users can get away with just this:
|
---|
29 | # export PYTHONPATH=$VBOX_SDK/bindings/xpcom/python:$PYTHONPATH
|
---|
30 | # , where $VBOX_SDK is is replaced with the place you unzipped the SDK
|
---|
31 | # or <trunk>/out/darwin.x86/release/dist/sdk.
|
---|
32 | #
|
---|
33 | #
|
---|
34 |
|
---|
35 | # this one has to be the first XPCOM related import
|
---|
36 | import xpcom.vboxxpcom
|
---|
37 | import xpcom
|
---|
38 | import xpcom.components
|
---|
39 | import sys, traceback
|
---|
40 |
|
---|
41 | from shellcommon import interpret
|
---|
42 |
|
---|
43 | class LocalManager:
|
---|
44 | def getSessionObject(self, vb):
|
---|
45 | return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
|
---|
46 |
|
---|
47 | vbox = None
|
---|
48 | mgr = LocalManager()
|
---|
49 | try:
|
---|
50 | vbox = xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
|
---|
51 | except xpcom.Exception, e:
|
---|
52 | print "XPCOM exception: ",e
|
---|
53 | traceback.print_exc()
|
---|
54 | sys.exit(1)
|
---|
55 |
|
---|
56 | ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':xpcom.components.interfaces, 'remote':False}
|
---|
57 |
|
---|
58 | interpret(ctx)
|
---|
59 |
|
---|
60 | del vbox
|
---|