These are general ideas of things you should do and understand before trying to program for the XO
Sugar is the Fedora Linux based operating system used by OLPC on their XO laptops and now maintained by SugarLabs. For more information on sugar look at the floss manuals
Reflashing will restore the XO to its factory settings. This process can be used for upgrading or downgrading the XO. Directions can be found in the Floss manual. While off, insert a USB stick with the image to reflash with, and while holding down the four game buttons, power on the XO.
import pygame.version print "PyGame version:", pygame.version.ver
See this page which describes how to check your XO version. The information is most likely found under “Control Panel : About my XO”.
Build, release, and update information.
CCCS has XO-1's with build 802.
“OLPC is not the only one making XO-1 operating system builds. You can also obtain builds from others in the wider community” (link).
How to differentiate between XO-1 and XO-1.5?
Success with getting to the OK prompt by holding the “X” game button when powering on, and then hitting ESC when prompted to halt the normal startup. So, the laptops at CCCS all appear to be unsecured, and that we will not need a developer key.
Install the sugar package that comes with Ubuntu to use their Sugar Emulator. You can actually open up two different emulators and have them act as two different XOs.
Open two different emulators using these two seperate commands:
ubuntu-prompt$ SUGAR_PROFILE=cat sugar-emulator ubuntu-prompt$ SUGAR_PROFILE=dog sugar-emulator
Note that cat and dog can be anything, as long as they are different.
With Sugar on a Stick (SOAS), you can boot directly to the Sugar OS on any machine without the need virtualizing or emulating Sugar. Students can use the journal on the stick to save their work.
In order to use sugar on a stick:
Go here for information on downloading sugar on a stick. The instructions are still in beta, and may not be effective.
VirtualBox is useful for emulating a variety of operating systems including sugar. To download VirtualBox go here. Once you have installed VirtualBox, you can press the “New” button and follow the instructions to create a virtual machine. Make sure that you select the correct operating system and version for Fedora. If your virtual machine is running slowly, you may want to allocate more RAM for it.
You will also need a virtual image of the OS you wish to emulate. You can get a .iso file of Fedora here. The first time you run your virtual machine you will be prompted to provide a bootable drive. Use the disk image you just downloaded. If you run into errors attempting to run your virtual machine, your file may have been corrupted during the download. In this instance, you will have to re-download Fedora. Then, in VirtualBox, click on the yellow “Settings” button on the top of the screen. On the left side of that screen click on storage, and in the center panel select the cd image under IDE controller. On the right there should be a section labeled attributes. Under that it will say CD/DVD drive. Click on the little disk icon next to the drop down menu to select a new disk image.
Once you have a running emulation of Fedora, go to applications and then to add/remove software. Then search for sugar and select “The emulator for the Sugar Learning Environment” and any activities you want installed. You should then be able to run a sugar emulator.
It is also possible to use VirtualBox to run the Sugar on a Stick file. Go into settings for your Fedora virtual machine and change the disk image to the sugar on stick iso file. You should then be able to boot the Virtual Machine normally, and it will go directly to Sugar.
Familiarity with the Linux family of operating systems can be useful when dealing with the XO. If you haven't done so before, you might consider installing Linux on a machine you have access to. Ubuntu is a distribution that is particularly suited for beginners, and Fedora (the basis for the XO operating system) is good for intermediate users. The Gentoo installation process is considerably more involved, but upon completion you will have a better understanding and appreciation for Linux. For Windows users, the Ubuntu CD provides Wubi, a Windows program that allows Ubuntu to be installed without re-partitioning your computer. Sun Microsystem's VirtualBox provides Windows and Mac OS X users the ability to install any flavor of Linux as a virtual machine inside their existing OS, free of charge.
Some useful links related to Linux:
The XO Laptop Wiki Provides these guides for setting up a development environment (These are extremely important!!):
When an application is ready for deployment on the XO, the source code is packaged into a .xo file which can be natively imported by the XO laptop. If you need to obtain the source code for an XO application, there are 2 possible ways to do it:
If the program has been imported as an XO activity:
If you have access to the .xo file:
A .xo file is really a compressed zip file: it can be extracted/opened to show the source code and other relevant files. Use:
or a similar command. The source code for the application can be found in DESTINATION_DIRECTORY/bin/
If you have access to the .xo file then you can move into the flash-drive and then use the “sugar-install-bundle” command on the .xo file to install the activity on the XO. This method shows you each step of the installation process and is useful for debugging the bundling issues.
Mesh Networks are no longer supported in XO 1.5 source
# apt-get install python
# yum install python
# emerge -av python
# apt-get install emacs21
# apt-get install python-pygame
If you have Python (2.5 or higher) and PyGame 1.8 installed, you should be good to go. I've tested crashRun on both MacOS X and Windows and I hope it'll run on Linux, too.
If you need Python, you can download it from: http://python.org/download/
And PyGame is available here: http://pygame.org/download.shtml
Vista users note: when I tried the python installer on a Vista machine, the installer didn't modify the PATH to include Python (it appeared to on XP). You can set this variable by right-clicking My Computer in the Start menu, selecting Properties, Advanced, and then pressing the Environment Variables button. You'll need to append “;C:\Python25\” to the end of the PATH variable.
Recursion
For those new to python, the following links can be of great benefit:
Some Slides from previous classes:
Python and Game development tutorials:
A separate page has been created that contains example python programs and games made by previous classes.
Python Example Programs
Pygame provides a relatively simple API for programming games in python, and is incredibly useful for animations. It does not however, provide GUI elements such as buttons/text fields/menus/etc. These must be created by hand when using pygame.
Pygame Tips
These are two useful skeletons for building a game. These skeletons are compatible with various versions of sugar. The pygtk example is useful for games that don't require much animation. Otherwise, the pygame example is the better starting point.
We have a virtual machine set up for our server needs. The information for it is located on this page.
The database information is here
This file passes data via the POST method to the server. The server will log all data passed by $_POST[“data”]. So in this example, “test data from python again” will be passed.
The server script post-server.php catches this string and appends it to an output file test-output.txt.
Try it out, and run this python script from your local machine!
''' Richard Burns November 28, 2010 Test script which passes information to the class apache server via the POST method. The server script currently captures this information and appends it to a testing output file, demonstrating one way that we can pass data to the server for it to record. Taken from: http://docs.python.org/library/httplib.html TODO: test size limitations of the POST ''' import httplib, urllib #params = urllib.urlencode({'milk': 1, 'eggs': 2, 'bacon': 0}) params = urllib.urlencode({'data': "test data from python again"}); headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn = httplib.HTTPConnection("cisc367.acad.cis.udel.edu:80") #conn.request("POST", "/cgi-bin/query", params, headers) conn.request("POST", "/post-server.php", params, headers) response = conn.getresponse() print response.status, response.reason data = response.read() conn.close()