BUG Community

Welcome! Log In

Forums Applications Scripting the BUG

Subscribe to Scripting the BUG  7 posts, 3 voices

Log in to reply to this topic
Oct 18, 2007 3:26pm
Medium Bug Labs team bballantine 56 posts


I've been thinking about Scripting on the BUG, or perhaps more accurately, writing BUG apps in a scripting language instead of Java. I'm starting this thread to continue this discussion which started here: http://bugbeta.com/forums/viewtopic.php?t=46

Also, Ken sent me an interesting related thread on the Java Community News forums: http://www.artima.com/forums/flat.jsp?forum=276&thread=216815
Oct 18, 2007 3:29pm
Medium Bug Labs team bballantine 56 posts

I've been working on using Jython to write BUG apps and I've had some success. Once I go over what I've done with Ken and clean it up a little, I'll post a Hello World-type app on buglabs.net and a tutorial.

In the meantime I'll outline my approach (there are certainly other approaches, and probably better approaches, but so far what I've done is working):

  • In your bug app, add the Jython jar, and add it to your bundle manifest's "Bundle-ClassPath".
  • Create a Python interface to "wrap" your Jython class.
  • Create a Jython script
  • (.py file), implementing your wrapper interface.
  • To use the class, create an in instance of org.python.util.PythonInterpreter
  • There's some tricky code you have to add after you have your interpreter initialized that adds the bundle packages to the packages your jython script can see:

Bundle thisBundle = context.getBundle();
Dictionary bundleHeaders = thisBundle.getHeaders();
String importPackages = (String)bundleHeaders.get("Import-Package");
String[] result = StringUtil.split(importPackages, ",");
for(int x=0; x<result.length; x++){
String pkg = result[x].trim();
// this package -- so my Jython script can access my local classes

  • Run the script
  • (.py) file via PythonInterpreter.execfile()
  • Create an instance of your Jython class within the script context
  • Pull out the object and cast it as your wrapper class.
  • Use it like you would a java class. See the code snippet below:

// execute my script, making the class available within the interpreter context
// create an instance of my class within the interpreter context
interp.exec("jython_service_listener = JythonServiceListener()");
// create a java object from the PyObject and cast as my wrapper interface
IJythonServiceListener serviceListener = (IJythonServiceListener) interp.get("jython_service_listener", IJythonServiceListener.class);
// use it
context.addServiceListener(serviceListener, myFilter);

If you're interested and still confused, wait a couple of days and I'll have a good sample app on buglabs.net for you to pull apart.
Oct 30, 2007 12:22pm
Medium Bug Labs team bballantine 56 posts

I know I promised this a while ago, but I finally got my Jython BUG application documented and ready for BUGnet. Here it is: http://buglabs.net/application/show/22. It's called JythonGps.

Please check it out. If you're into Python or Jython, definitely take a look. Perhaps you can think of a different or better way to get Python on the BUG. Or perhaps you can use this method to make an application that we've never seen before. I am interested in seeing something unique that would be difficult to do in Java.

Jan 9, 2008 11:44am
Img_missing_medium myaliasisr... 15 posts

Has there been any update on getting pure python (w/o java) running on the Bug? That is pretty much my only request at this point – the hardware looks great, and I just sold my UMPC so I can buy the BUGBase and all the modules @ launch :)

Jan 9, 2008 3:22pm
Medium Bug Labs team bballantine 56 posts


I was interested in having Python run within Java so I could take advantage of the OSGi runtime, where we’ve done a lot of work providing bindings to the module drivers, for example. This code could also access other OSGi bundle services and other BUG applications.

I’m pretty sure the BUG won’t ship with Python on it (because of space issues), but we plan to provide our kernel and root file system build tools. You could use these tools to put Python on the BUG pretty easily. If I’m right about the space concerns, but the community is hankering for Python, we will consider creating a separate package that you can install.

Another thing to keep in mind is, at this time, we don’t have bindings to hardware drivers written for any language other than Java. If you wish to access your modules from Python code, your options are to write your own bindings, wait and hope that we do it, or use the web services running on the BUG internally—the BUG ships with a simple suite of web services that provide access to the modules through http.

I hope this helps.

Jan 13, 2008 5:01am
Medium Bug Labs team kgilmer 215 posts


One addition to what Brian said; if your language of choice already supports a given device-type in Linux, then that support should work on the BUG. Since the beginning we’ve tried to keep with standard Linux APIs. Java is not the only language/environment we care about…obviously different people and applications require different tools. As we work to native support we will update the wiki, in addition if you’d like to work on this (once you have a BUG :) ) that would be great!

Jan 15, 2008 12:17am
Img_missing_medium myaliasisr... 15 posts

I think that’s a good idea! I am actively switching most of my rapid application development/prototyping development to python from java, prolog and C. Well, mostly – I want to get gnuprolog up as well :) A friend of mine work doesn't think the BUG will be great shakes vision – I want to see if, through optimization, I can get some good speech authentication and maybe image recognition.


Log in to reply to this topic
Forums Applications Scripting the BUG

Powered by Community Engine