VirtualBox Python API - remote access - python

I'm trying to run virtual machine set on Computer with Windows 7 (my main laptop) from my netbook (Ubuntu system).
On Ubuntu I've prepared python script:
from vboxapi import VirtualBoxManager
import sys
sys.path.append("/home/myLogin/Downloads/sdk/bindings/webservice/python/lib")
mgr = VirtualBoxManager("WEBSERVICE", {'url':'myIP', 'user':'myServerLogin', 'password':'myPassthere'})
vbox = mgr.vbox
name = "Muszelek"
mach = vbox.findMachine(name)
session = mgr.mgr.getSessionObject(vbox)
progress = mach.launchVMProcess(session, "gui", "")
progress.waitForCompletion(-1)
mgr.closeMachineSession(session)
I'm getting error:
Installation problem: check that appropriate libs in place
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/vboxapi/__init__.py", line 981, in __init__
self.vbox = self.platform.getVirtualBox()
File "/usr/local/lib/python2.7/dist-packages/vboxapi/__init__.py", line 856, in getVirtualBox
return self.connect(self.url, self.user, self.password)
File "/usr/local/lib/python2.7/dist-packages/vboxapi/__init__.py", line 910, in connect
self.vbox = self.wsmgr.logon(self.user, self.password)
File "/home/karolinka/Downloads/sdk/bindings/webservice/python/lib/VirtualBox_wrappers.py", line 11790, in logon
req=IWebsessionManager_logonRequestMsg()
NameError: global name 'IWebsessionManager_logonRequestMsg' is not defined
Traceback (most recent call last):
File "vmmach.py", line 5, in <module>
mgr = VirtualBoxManager("WEBSERVICE", {'url':'myIP', 'user':'myComputerLogin', 'password':'myPass'})
File "/usr/local/lib/python2.7/dist-packages/vboxapi/__init__.py", line 985, in __init__
raise ne
NameError: global name 'IWebsessionManager_logonRequestMsg' is not defined
Any idea how could I solve this issue?
Is it problem with libs on my Windows Machine?

I just had the exact same problem on my Mac. The issue is that VirtualBox_wrappers.py imports VirtualBox_client.py (which defines the global name in question) in a try block and continues (pass) if it can not be imported
try:
from VirtualBox_client import *
except:
pass
the issue is that VirtualBox_client.py depends on ZSI, which was not installed, so the import failed. Once I did
easy_install zsi
everything worked as expected.

It seems that the class is not found! Have you tried to look for the webservice api if they are available?
I had a similar issue, I looked in /usr/lib/virtualbox/sdk/bindings and I didn't find the webservice folder only xpcom was in there, so I just included the webservice folder from the sdk and all worked fine.

Related

Python 2.7 and Pyo, Server must be booted before creating any audio project

I am using Pyo (http://ajaxsoundstudio.com/software/pyo/) in Python 2.7.14 and I an trying to play an audio file with this code
from pyo import *
s = Server()
s.boot()
s.start()
sf = SfPlayer("C:\Users\name\Downloads\audio.mp3", speed=1, loop=True).out()
but I get this message:
Traceback (most recent call last):
File "C:\Python27\pyotest.py", line 5, in <module>
sf = SfPlayer("C:\Users\name\Downloads\audio.mp3", speed=1, loop=True).out()
File "C:\Python27\lib\site-packages\pyolib\players.py", line 98, in __init__
PyoObject.__init__(self, mul, add)
File "C:\Python27\lib\site-packages\pyolib\_core.py", line 967, in __init__
PyoObjectBase.__init__(self)
File "C:\Python27\lib\site-packages\pyolib\_core.py", line 809, in __init__
raise PyoServerStateException("The Server must be booted before "
PyoServerStateException: The Server must be booted before creating any audio object.
I had the same error once (on Windows). Started the E-Pyo Editor that comes with installing Pyo. After that it worked fine.
If that doesn't help you might want to set the server options and the output device manually.
Get the ID of the desired output device with
pa_list_devices()
If you found your ID you can set it with this command (change the 0 to your device ID) and then boot the server:
s.setOutputDevice(0)
s.boot()

ConfigParser Error when running python script from RoR app's controller

I am trying to trigger a python script from a controller.
I have defined the follwing function in the controller:
private
def update_product_count(skus, qty)
system "python2 /home/nish/stuff/repos/Untitled/voylla_staging_changes/app/models/ReviseItem.py
skus qty > output"
end
Calling this function in another method of the same controller:
def show
//some code
update_product_count(#skus, #qty)
end
When I run the script manually, from my console, it runs fine. But i get this error when run from the controller:
Traceback (most recent call last):
File "/home/nish/stuff/repos/Untitled/voylla_staging_changes/app/models/ReviseItem.py", line 24, in <module>
devID = config.get("Keys", "Developer")
File "/usr/lib/python2.7/ConfigParser.py", line 607, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'Keys'
The most likely cause is that you are opening the config file using a relative path, and the controller has a different current directory to your console.
You should either use an absolute path to the config file, or have the script work out the directory it is executing in, and prepend that to the file name.

What dependencies do I need for USB programing in python with pyUSB?

I am trying to get the usb.find command to work properly in a python script I'm writing on Angstrom for the Beagleboard.
Here is my code:
#!/usr/bin/env python
import usb.core
import usb.util
import usb.backend.libusb01 as libusb
PYUSB_DEBUG_LEVEL = 'debug'
# find our device
# Bus 002 Device 006: ID 1208:0815
# idVendor 0x1208
# idProduct 0x0815
# dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)
# iManufacturer 1 TOROBOT.com
dev = usb.core.find(idVendor=0x1208, idProduct=0x0815,
backend=libusb.get_backend() )
I don't know what's missing, but here is what I do know.
When I don't specify the backend, no backend is found. When I do specify the backend "usb.backend.libusb01" I get the following error:
root#beagleboard:~/servo# ./pyServo.py
Traceback (most recent call last):
File "./pyServo.py", line 17, in <module>
dev = usb.core.find(idVendor=0x1208, idProduct=0x0815, backend=libusb.get_backend() )
File "/usr/lib/python2.6/site-packages/usb/core.py", line 854, in find
return _interop._next(device_iter(k, v))
File "/usr/lib/python2.6/site-packages/usb/_interop.py", line 60, in _next
return next(iter)
File "/usr/lib/python2.6/site-packages/usb/core.py", line 821, in device_iter
for dev in backend.enumerate_devices():
File "/usr/lib/python2.6/site-packages/usb/backend/libusb01.py", line 390, in enumerate_devices
_check(_lib.usb_find_busses())
File "/usr/lib/python2.6/ctypes/__init__.py", line 366, in __getattr__
func = self.__getitem__(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 371, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: python: undefined symbol: usb_find_busses
What am I missing so that this will work properly?
Thank you.
Python, pyusb, libusb.
I think that's it.
Well libc, ld-linux.so too of course, but those are in your system by default.
Do nm -D /path-to/libusb.so and see if usb_find_busses symbol is really there. There's always a chance that your libusb is outdated or somehow specially compiled.
Check if you get any log, for example missing libusb.so should produce something like 'Error loading libusb 0.1 backend'

Error starting Pyro Daemon using a NameServer: "could not find NameServer"

I'm trying to get a simple Pyro example running (taken from this page), this is the code:
import Pyro.core
import Pyro.naming
class JokeGen(Pyro.core.ObjBase):
def joke(self, name):
return "Sorry "+name+", I don't know any jokes."
daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)
uri=daemon.connect(JokeGen(),"jokegen")
daemon.requestLoop()
When I run this script with Python 2.6.5 and Python 2.6.6 (tried both on Ubuntu 10.04 and Debian Squeeze), I'm always getting this error:
Traceback (most recent call last):
File "/home/ingo/tools/python/pyroserver.py", line 9, in <module>
ns=Pyro.naming.NameServerLocator().getNS()
File "/usr/lib/pymodules/python2.6/Pyro/naming.py", line 176, in getNS
reply = self.sendSysCommand(NS_SYSCMD_LOCATION,host,port,trace,1,bcaddr)
File "/usr/lib/pymodules/python2.6/Pyro/naming.py", line 76, in sendSysCommand
raise Pyro.errors.NamingError("could not find NameServer")
Pyro.errors.NamingError: could not find NameServer
What's wrong with the script? How can I create that nameserver?
Run pyro-ns in another terminial first. That is the Pyro object broker.

py2exe/pyinstaller and DispatchWithEvents

I have a program that uses the win32com library to control iTunes, but have been having some issues getting it to compile into an executable. The problem seems to revolve around using DispatchWithEvents instead of Dispatch. I've created a very simple program to illustrate my problem:
import win32com.client
win32com.client.gencache.is_readonly = False #From py2exe wiki
class ITunesEvents(object):
def __init__(self): self.comEnabled = True
def OnCOMCallsDisabledEvent(self, reason): self.comEnabled = False
def OnCOMCallsEnabledEvent(self): self.comEnabled = True
# The first line works in the exe, the second doesn't.
itunes = win32com.client.Dispatch("iTunes.Application")
#itunes = win32com.client.DispatchWithEvents("iTunes.Application", ITunesEvents)
lib = getattr(itunes, "LibraryPlaylist")
src = getattr(lib, "Source")
playlists = getattr(src, "Playlists")
print "Found %i playlists." % getattr(playlists, "Count")
Using Dispatch, the program compiles and runs correctly. Using DispatchWithEvents, the program runs fine when called from the command line, but produces the following error when running the exe:
Traceback (most recent call last):
File "sandbox.py", line 16, in <module>
itunes = win32com.client.DispatchWithEvents("iTunes.Application", ITunesEvents)
File "win32com\client\__init__.pyc", line 252, in DispatchWithEvents
File "win32com\client\gencache.pyc", line 520, in EnsureModule
File "win32com\client\gencache.pyc", line 287, in MakeModuleForTypelib
File "win32com\client\makepy.pyc", line 259, in GenerateFromTypeLibSpec
File "win32com\client\gencache.pyc", line 141, in GetGeneratePath
IOError: [Errno 2] No such file or directory: '[distDir]\\library.zip\\win32com\\gen_py\\__init__.py'
I've also tried using PyInstaller, which gives a similar error:
File "<string>", line 16, in <module>
File "[outDir]/win32com.client", line 252, in DispatchWithEvents
File "[outDir]/win32com.client.gencache", line 520, in EnsureModule
File "[outDir]/win32com.client.gencache", line 287, in MakeModuleForTypelib
File "[outDir]/win32com.client.makepy", line 286, in GenerateFromTypeLibSpec
File "[outDir]/win32com.client.gencache", line 550, in AddModuleToCache
File "[outDir]/win32com.client.gencache", line 629, in _GetModule
File "[pyinstallerDir]\iu.py", line 455, in importHook
raise ImportError, "No module named %s" % fqname
ImportError: No module named win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13
I know I can manually add the typelib in my setup.py file, but I'd like to run the code on computers with different versions of iTunes without recompiling so I'd prefer to dynamically create it. If there's no way to do this with the setup/spec, maybe there is another way to load the events? Thanks.
Addition:
Thanks to Ryan, I found I could take the generated py file and after a little digging, was able to come up with the following.
Take the generated py file (from makepy.py) and rename it somewhere like cominterface.py. Then you'll need to do the following to actually create the COM object with event handler.
import cominterface
from types import ClassType
from win32com.client import EventsProxy, _event_setattr_
class ItunesEvents:
'''iTunes events class. See cominterface for details.'''
def OnPlayerPlayEvent(self, t):print "Playing..."
def OnPlayerStopEvent(self, t): print "Stopping..."
itunes = cominterface.iTunesApp()
rClass = ClassType("COMEventClass", (itunes.__class__, itunes.default_source, ItunesEvents), {'__setattr__': _event_setattr_})
instance = rClass(itunes._oleobj_)
itunes.default_source.__init__(instance, instance)
#ItunesEvents.__init__(instance) #Uncomment this line if your events class has __init__.
itunes = EventsProxy(instance)
Then you can go about your business.
I was experiencing the exact same error.
This link put me in the right direction -->
http://www.py2exe.org/index.cgi/UsingEnsureDispatch
however it mentions that :
NB You must ensure that the python...\win32com.client.gen_py dir does not exist
to allow creation of the cache in %temp%
Which was a bit confusing.
What solved it for me was renaming "C:\Python26\Lib\site-packages\win32com\gen_py" to "C:\Python26\Lib\site-packages\win32com\gen_pybak" (when running py2exe)
This is the official way to do it.
(Edit: copied verbatim example from that link above)
import win32com.client
if win32com.client.gencache.is_readonly == True:
#allow gencache to create the cached wrapper objects
win32com.client.gencache.is_readonly = False
# under p2exe the call in gencache to __init__() does not happen
# so we use Rebuild() to force the creation of the gen_py folder
win32com.client.gencache.Rebuild()
# NB You must ensure that the python...\win32com.client.gen_py dir does not exist
# to allow creation of the cache in %temp%
# Use SAPI speech through IDispatch
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants
voice = EnsureDispatch("Sapi.SpVoice", bForDemand=0)
voice.Speak( "Hello World.", constants.SVSFlagsAsync )
Instead of depending on the cache, I'd recommend going into the local cache directory, copying the generated file into your local project file, and naming it something like ITunesInterface.py, and calling to that explicitly. This will make py2exe pull it into your compiled app.

Categories

Resources