VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/python/sample/vboxshell.py@ 12095

Last change on this file since 12095 was 12095, checked in by vboxsync, 16 years ago

fixed XPCOMIPC deps, other minor fixes

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
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
36import xpcom.vboxxpcom
37import xpcom
38import xpcom.components
39import sys, traceback
40
41from shellcommon import interpret
42
43class LocalManager:
44 def getSessionObject(self, vb):
45 return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
46
47vbox = None
48mgr = LocalManager()
49try:
50 vbox = xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
51except xpcom.Exception, e:
52 print "XPCOM exception: ",e
53 traceback.print_exc()
54 sys.exit(1)
55
56ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':xpcom.components.interfaces, 'remote':False}
57
58interpret(ctx)
59
60del vbox
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette