A couple of weeks ago, I was chatting with Michael Banck about DebConf. He told me that one of the sponsors provided everyone a SIM card with 5 units of credit, and that the first time he established a data connection was also his last: he got bit by Maemo's automatic repository update misfeature; because, he had gone more than 24 hours without checking for software updates, Maemo checked even though he was using a cellular data connection and only had a few megabytes worth of data transfer credit.

A simple workaround for this bug is to disable updates. This has the unfortunate side effect that the user is no longer informed when updates become available. A better solution is one that fetches updates when background updates are acceptable. This is exactly the type of scheduling problem that Woodchuck was designed to help applications with.

Over the past few days, I've developed APT Woodchuck, a small Python script, that does exactly this: APT Woodchuck lets Woodchuck determine when it should check for updates. On installation, APT Woodchuck disables HAM's automatic update feature and registers itself with Woodchuck. When Woodchuck decides APT Woodchuck should perform an update, it starts it (using DBus). APT Woodchuck then updates the package list (it uses HAM's apt-worker utility to ensure that all of HAM's usual update mechanisms are performed, including tickling the update widget, if necessary). APT Woodchuck also prefetches packages for which an update is available.

In total, APT Woodchuck is about 700 SLOC and took about 2 days to write. Most of the time was spent figuring out how to use Python APT. That seems to me like a pretty easy solution to a hard scheduling problem.

I've made packages for APT Woodchuck for Maemo available.

If you are thinking about including Woodchuck support in your application, APT Woodchuck is a fairly good example of how to go about going it.