Archive for the 'Python' Category

Extracting files from a directory tree

Saturday, October 6th, 2007

Mr. Ben Polito has recently beating his drum to the tune that I am a repressed mechanical engineer who needs to release his inner software engineer.

Normally, I am too busy with preparations for the arrival of the Hard Times to spend time busting the myths spread by a sailor in the dark, but a recent problem I ran into at work gave me pause. The first version of our corporate wiki, a tweaked version of mediawiki, left a hierarchy of a few hundred directories sprinkled with around 1600 files. These files were attachments to the old wiki, and while most of them were transferred to the new wiki, some were not.

I thought to myself, “Ah! I bet I could write a little Python function that recursed through the directories, copying out the files and calling itself for each subsequent subdirectory!” This was Friday night around 10, after a day spent writing PLC code for work. It was at this moment that I thought, “Perhaps Mr. Polito has a point.”

To that end, I present Pylito.

Python on the Gumstix Verdex

Sunday, July 22nd, 2007

Being both a Python zealot and an embedded systems zealot, I’ve been looking for an embedded system that I can program in Python. Most of the embedded code I write professionally I write in C. Having learned Python a few years ago, I’m finding C increasingly painful, approximately in proportion to my facility with Python.

Thus far, it seems that the Gumstix Verdex may be the answer I’ve been seeking. The Verdex is an embedded Linux board, about 1 inch by 3 inches, based around Marvell’s (previously, Intel’s) XScale PXA270, common in PDAs and cellphones. It uses around 1 W of power in its quiescent state (not suspended, but not at full processor load either).

I was able to compile a new binary image including the Linux kernel, various utilities, and Python 2.4.2 and upload it to the Verdex using the Gumstix’s console-vx serial interface board. (I seem to have hosed the ethernet interface at the same time, but I’ll worry about that later.)

The ultimate goal (well, for now) was to test on an embedded processor Pysolar, the Python sun-tracking code I’ve been writing. The Verdex I have, the XL6P, runs at 600 MHz. The Pysolar test suite executed in around 1.2 seconds. On my desktop Linux machine, the same test suite executes in 0.012 s. The fact that the times vary by a factor of precisely 100 makes me a little suspicious, but it doesn’t seem impossible that a desktop could beat an embedded computer by 100x.