Friday, August 27, 2004

OpenOffice and cvs

I use OpenOffice at home for my word processing and spreadsheet needs. I often like to keep such documents under version control using cvs. One of the features of cvs that I have found very useful in the past is keyword substitution: version control information can be included in the document under version control so that for example the version number can be seen in the actual document. It works by including special text (for the version number the text is '$Revision: $') in the document. When the document is checked in cvs automatically inserts the relevant value after the ':'. That's fine and dandy but unfortunately it doesn't work with binary files whereas OpenOffice uses binary.

Closer examination of the OpenOffice format reveals that a text document is in fact saved as a zipped collection of xml files. Moreover OpenOffice's word processor supports user-defined properties; from File choose Properties and select the user-defined tab. You can then put the text $Revision: $ in one of these properties as shown below:




(Actually any text could be used, but I chose $Revision: $ to be consistent with normal keyword substitution in cvs.) You can then use this property in your document by selecting Insert | Fields | Other and expand the User-Defined item to choose the one containing $Revision: $.

This still leaves the problem of how to update this value. The solution I came up with is a Python script that you invoke when checking in instead of the normal cvs checkin. You can download this script here.When you run it something like the following should appear:


[pmu@mblinux python]$ sxw_checkin.py testdoc2.sxw "Eighth version"
+++> unzip -o testdoc2.sxw meta.xml
Archive: testdoc2.sxw
inflating: meta.xml
+++> zip testdoc2.sxw meta.xml
updating: meta.xml (deflated 56%)
+++> cvs ci -m"Eighth version" testdoc2.sxw
Checking in testdoc2.sxw;
/software/cvsroot/scripts/python/testdoc2.sxw,v <-- testdoc2.sxw new revision: 1.8; previous revision: 1.7 done


And hey presto! the property in the OpenOffice document has been updated (in this example it would now have the value "1.8").

Small print: I have only used the script on OpenOffice text documents so I can't say whether it works for the other tools that OpenOffice provides; please let me know if you try it!

Thursday, August 12, 2004

Trip to Britain

Just returned from a very pleasant trip to Britain catching up with friends. Stayed for a few days with our friends John and Claire where John regaled me with his new joke: on learning that presidential candidate John Kerry's wife was from the Heinz family, he asked an unimpressed Claire "Do you think he will be able to ketch-up".

Turns out the joke was on me anyway: Yvonne was captivated by John and Claire's Aibo ("Milton") so that is next on our shopping list. She has even chosen a name ("Darwin").