Python List Inheritance Post Creation Pattern

One of the fun things to do with python is to use the language to bend the rules of programming. One neat way of using your resources wisely with objects is to create objects in the right places, but not generate or call costly data gathering operations until you absolutely need to.

So called ‘late data initialisation’ is useful in certain kinds of programs. I document here the best pattern I’ve found to turn a python list into a late data class:

class newList(list):
    def data(self):
        if self.populate:
        return self

    def populate(self):
        print "Generating Now"
        for x in range(42):
            self.append( x )
        self.populate = None

    def __getitem__(self, key):
        return super(newList,

    def __len__(self):
        return super(newList,

    def __iter__(self):
        return super(newList,

Basically populate can be any piece of code which calls what ever it needs in order to gather the data. It’ll only be called once and to prevent having to use an __init__ variable we just clobber the method attribute. Sneaky!

When the list is used for an iteration (for loop), or if you delve into it directly for a specific item, or need to know it’s length, then we can get the data behind our object and have it contained within the list object we’re inheriting. No need for secondary list object variables dangling off of self. Ugly! Although this pattern does require that every use you want to put the object to (i.e. string, representation, slicing, dicing, mincing or conditionalising) you’ll have to make a new super method to wrap around to make sure that the data is generated if that’s the first way the list will be used.

What are your thoughts about this pattern? Do you know how to fix the init issue with a better pattern?

Ubuntu Contributor Harmony

I have made no bones about my opposition to unpaid copyright assignment in any quarter. Least understandable was the old Canonical contributors agreement, Mark wrote another of his personal defences in his blog on Friday; of what I consider to be unreasonable and assumptive. But this isn’t about that blog post.

Only just today I have noticed that the Canonical contributor agreement has changed from a copyright assignment to a broad license. Creators get to keep their copyright and Canonical doesn’t have it’s hands tied by the GPL. I’m not sure how long it’s been this way, but I am happy to see it has changed.

Balancing this difficult policy with the views and feelings of the wider community is an unenvious job, various people in a number of different Free Software communities try their best to get solid legal frameworks in place, while maintaining the rights of contributors with the need to keep things protected in the open.

I’m certainly happier to contribute under the harmony agreement, than I was under the old CA. Even though this does permit Canonical to make proprietary versions of the software. The main factor there being that their reputation would be shredded so quickly as to damage the very fabric of the community endeavour.

What are your thoughts?

What Ubuntu Versions are still supported?

I was writing a script today to do a tarball release of any python app and upload to ppa a version for all currently supported versions. The problem I’m having is that I can’t find a simple place to go to to find the information about supported versions.

If any of you guys know of either a downloadable files which contains all versions with dates or a simple list of all _currently_ supported versions. That would be great. Obviously they would have to be locations where Canonical keeps them up to date so the scripts continue to work into the future.


Lab Session Manager, New Release 1.2

I’m pleased to release a new version of the lab session manager.

The Lab Session Manager is a indicator which times how long you can be on the computer for, notifies you when you’re running out of time and then logs you off when your time is over. It replaces the old and unmaintained timed functionality with a modern, gtk based system tray icon and logging functionality for generating reports about who is using the computer for how long. See previous blog post here.

This version includes a successful upgrade of the code to python modualisation which will help future bug fixing. plus a big upgrade to the logging functionality to allow logs to be read back and sorted and reported on. New reporting mechanisms are in the works for the next version too.

You can find this release’s ppa here or the source packages in the above link. Please give the PPA time to build everything.

The next release should also include more fixes and some custom icons, so we can guarentee the style and design of the dialogs no matter what theme you’re using.

If you find any bugs, please report them in launchpad here.

Letter to: Creative Industry

This is the letter I sent to the petition organiser to try and get apple’s final cut reinstated.

Dear Andrew Landini,

I read with great interest the petition of a great many creative people who have built their work around the Final Cut product line. Of course, I feel your pain and wish to offer my sympathies.

But I also wish to share with you what I have learned about software and the importance of ownership and control. It is true that there are a great number of good, solid software packages being made by companies like Adobe and Apple which artists and businesses regularly use to get their work done in the best way possible.

The problem with these packages is that they take away effective ownership and with that any sense of control over the direction of the development of the tools in use. These programs are known as proprietary software[1], because they use trade secretes to hide their source code, strong copyright to sell products in a box and even go so far as to implement anti-features[2] to ensure stratification of their market money earning potential.

This isn’t necessarily at issue, but it does put users (and more importantly businesses) at a huge disadvantage. Instead of investing into an ecosystem that requires it take control away from your business, I would like to propose supporting Free and Open Source[3] business models for the furthering of creative tools.

This new way of creating software doesn’t require programmers keep secretes from their users. Development is done in the open, multiple different parties generally pay into development of the same features and we end up with free software that every participant gets full rights to use, modify, and basically do with as they wish for their own business needs.

Tools such as Gimp, Inkscape and Blender are not always first with features or even the best technical tool at the moment. But what they offer is something far more important, they give every user Freedom, Ownership and Control to take the software and fully define how they want to see the software developed further. They require no loyalty to any one set of developers, there is no one company you must go to for support. Despite marginal investment from the creative industry, these tools are already quite powerful.

With most artists and creative businesses understanding and supporting Free and Open Source as a good business strategy, I think we can prevent, in the future, ever having to write an petition begging a mischievous company from putting small creative businesses out of work because they decided to develop for the lowest common denominator.

Best Regards, Martin Owens (Artist, Programmer, Teacher)


I had the Idea of Using Javascript Instead

The Genetic Wallpapers project is supposed to be able to help any artist create a wallpaper capable of shifting and moving over time to produce interesting and unique results over time.

The Idea

The problem is that artists have all sorts of crazy ideas about what and how the wallpaper should progress and currently the logic for how the wallpaper will mutate is contained within the python code of the main project.

So I had this crazy idea, what if I could move that logic to javascript, a language which far more people know and each logic mechanism would be self contained within the svg wallpaper it’s supposed to effect.

I thought this was such a cool idea I rushed to google to do a search to find out how I could execute self contained javascript from python without a browser (because it’s svg, not html) and it only needs to be able to modify the Document Object Model to move and resize the objects in the image.

The Problem

All of the projects I encountered searching for a solution couldn’t really do the job. Either they were hacks, tied to web browsers, didn’t really work or were mostly converters to make javascript out of python. Which isn’t what we need for this to work. I looked at python-jswebkit, python-spidermonkey and pyv8, none of which could really do the job of running javascript to act on a DOM.

Possible Solution

Instead of trying to use python, I could farm it out to perl. I hear perl has better javascript execution support and best of all, documentation to show you how to do it.

The alternative is to ask the community. But this is quite a highly specialised bit of functionality, very rarely do we need to run one bit of JIT code on another. But any ideas would be very welcome.

Comments and thoughts on the idea and the direction, please to post below.

Packaging: Need Help!

I haven’t had much time to blog about interesting things, sorry guys. But I did want to take an opportunity to share a problem I’m having.

I make software, and I make it for people. I’ve driven by people’s needs. So I tend to make lots of smaller things to fix certain problems or do something interesting on a small scale. The difficulty I’m having is with packaging and getting packages into Debian and thus into Ubuntu. I make lots of PPAs and they seem to work for users who are interested in getting what I do directly from me. But…

I feel that as the developer, designer, QA and possibly only user; that to do all the work on the packaging and being the sponsor in the upload process would deny my projects much needed oversight, not to mention being tiresome.

If you check out my launchpad list of code branches, I have A LOT of really awesome code which isn’t in the Ubuntu archive. I have a lot of interesting and useful tools which should be available to all kinds of people and just aren’t. The reason why all these code branches have failed to move anywhere is because I’m not good at asking for help on packaging and when I do I ask the wrong people. Despite on a number of projects being asked by users to get packages into Ubuntu, the answer is simply: I can’t do it myself and I need help.

If you know how to get code into Ubuntu _without_ having to be the packager and Debian maintainer: let me know you thoughts, as always below.

New Session Manager

For community centers we need to present to the user the amount of time that their session has left and at the same time log the user off when the session timer runs out. As a nice touch we want to warn the user as the session nears it’s end.

To achieve this we use an app indicator with a menu item with the amount of time left.

For the warnings we use the libnotify and change the icon of the app indicator too:

We also want to notify the user of how much time they have, so we add a welcome:

If the program exits or is killed, the gnome pid is also killed so the user logs off.

All of this is configurable so we can say what users should have what kind of session and what warnings:

logs: /var/log/sessions/
admin: ''
users: 01:00:00
testing: false
- message: Welcome!
description: You have %(remains)d minutes in your session.
icon: application-community
from: session-start
times: [ '00:01' ]
- message: Session Running Out
description: Your session is about to end automatically, please save all your work. %(time)d minutes remaining.
icon: gtk-quit
from: session-end
times: ['10:00', '05:00', '01:00']

For reporting we also want to log sessions, when they start, when they end and on what machine:

- {date: '2011-07-07T15:36:02.734579', message: log-started}
- &id002 {date: '2011-07-07T15:36:02.763812', message: login, session-pid: 1830, tag: started}
- &id001 {date: '2011-07-07T15:36:51.898611', message: forced, tag: end}
meta: {hostname: delen, username: doctormo}

We add the program’s .desktop file to the /etc/adg/autostart directory so it launches when gnome starts.

You can find all the code here and the ppa package here.

Inner City Boston Ubuntu Hour 2

Today was the second Inner City Ubuntu Hour, myself, Dave Hunt and Ralph DeGenero met at Winter Street and Tremont on this beautiful july forth weekend to talk geek about Ubuntu.

First stop we went to Starbucks to get some drinks and use up Rio’s free drink card. Then onwards to have some food at Pho Pasture in Boston’s China Town. We talked about the etymology of language and lots of various geeky subjects. The main event followed:

We took the T (train) to Andrew Sq. and walked over to the Mary Ellen Community Center. I showed off the computer lab with full Ubuntu machines and how the network was administered and kept in sync. Particularly interesting was the way the package syncing worked and the new user registration gdm. You can see a video of me demonstrating the user registration system here.

I also have a set of scripts to notify users and track their session times using libnotify and app-indicators. You can check out the client and server scripts here and the session manager here (unfinished).

We tested the Orca screen reader and attempted to upgrade it for the lab to 3.1, but the new versions are having trouble with Maverick at the moment. So they were quickly downgraded.

With that, we ended to Ubuntu Hour which was extended into over time to show off some really cool stuff.