VirtualBox

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

Last change on this file since 11896 was 11896, checked in by vboxsync, 17 years ago

samples update, ship mscom examples

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

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