Planet Changes

Recently, a new solar system was discovered, one with a planet that just might contain liquid water.

This is not about that.

Rather, this is about the Planet Planet, a flexible feed aggregator, that Sam Ruby and Danny Ayers (among others) have been hacking on recently.

I have created a personal planet for myself, one of the introverted ones that gather what I produce rather than what I consume: Planet Morten (styling yet to be perfected).

While setting it up, and getting it running like I wanted to, I noticed that it updated the generated files on every run, even though no new entries had been included. On a web that knows about Last-Modified and ETag (as Planet Planet itself does), it seemed like waste of bandwidth to preserve the incoming bytes but not the outgoing ones.

My limited Python skills to the rescue.

Two patches against the latest nightly — the one with a Last-Modified header of Mon, 22 May 2006 16:02:22 GMT (even though it contains files that were changed in the future when I GOT it):

planet-filecmp.diff
This patch makes Planet Planet write its output to a temporary file, which is then compared to the previous version, which is then only overwritten if the contents differ. This precludes the use of <TMPL_VAR date> in templates, as that will surely make the files differ, but the patch has the added bonus of not trashing the previous version of the generated file, in case something goes wrong during the write process.
planet-conditional-output.diff
This patch contains the above patch and additional logic to prevent output files from being generated if no channels were updated. Thus, the original files will be left untouched if no new entries were found, logic that also somewhat invalidates <TMPL_VAR date> in templates, since it can’t be trusted anymore.

The Planet Planet development list has been notified.

Update: Sam Ruby was kind enough to point out some shortcomings in my solution and prompt me for a test case. Thus: