My favorites | Sign in
Project Logo
                
Search
for
Updated Aug 14, 2008 by zachriggle
Labels: Featured
HowDoesSugarbotWork  
How does sugarbot work?

Introduction

Sugarbot is a conglomeration of clever Python programming and XML-RPC. There main components to sugarbot are:

  1. Script server (XML-RPC)
  2. Activity emulation
  3. GTK hooking and widget identification
  4. Script execution engine

Script Server

The script server is very simple. It is provided with a list of Python files (specified on the command-line), and then serves those files' contents over XML-RPC (as well as some other data scraped from the files) to the sugarbot clients. The server supports multiple concurrent sessions, as would be expected, so all of the clients can connect to a single XML-RPC server. The XML-RPC server also provides future capabilities to extend error reporting, as it is made aware of all of the success/failures of the client script execution.

Activity Emulation

In order to test an Activity, it has to be instantiated. In the Sugar/OLPC environment, this is less easy than it would originally seem. However, due to dynamic typing and nifty run-time inheritance changes, the entire activity is emulated, and operates exactly as it would normally operate.

GTK Hooks and Widget Identification

Before the GUI can be manipulated, all of the GUI widgets not only have to be identified, but they must be assigned meaningful identifiers. By hooking into the core of GTK, we can build a database of all of the instantiated widgets. Using the base gtk.Widget class, developers can specify names for each of the Widgets. Alternatively, sugarbot attempts to create proper names for un-named widgets by using various means, allowing developers to quickly start writing tests without having to make large changes to the existing code-base.

Script execution engine

The script execution engine takes all of the information gathered by the GTK hooks and Widget identification, and then passes that information to a script. In addition to providing convenience accessors, the script has full access to the actual gtk.Widget objects, and can perform any custom manipulation needed.

The scripts used by sugarbot are all native Python code, so it is not necessary to learn any new syntax. The only unique property of the scripts are that they must define a global variable, define a specific function for execution.

Example script:

import time
import logging

sugarActivityName = 'Calculate'

def sugarbot_main(widgets):
	# Test 'selected' functionality.
	assert widgets['Share with:'].selected == "Private"
	widgets['Share with:'].selected = "My Neighborhood"
	assert widgets['Share with:'].selected == "My Neighborhood"

	# Test widget fetching/assignment
	one 	= widgets['1']
	plus 	= widgets['+']
	enter 	= widgets['enter']
	
	for i in range(0,5):
		# Test click
		one.click()
		plus.click()
		one.click()
		
		# Test Entry text assignment
		assert widgets['TextEntry'].text == '1+1'
		
		enter.click()
		
		assert len(widgets['TextEntry'].text) == 0
		
		time.sleep(1)
	
	# More Entry text assignment
	widgets['TextEntry'].text = "1+5"
	assert widgets['TextEntry'].text == '1+5'
	enter.click()

Sign in to add a comment
Hosted by Google Code