Command line xml queries for Plone configuration using xmlstarlet

One of the nice things about having declarative configuration in xml files is that you can use standard xml tools to do interesting things with them. XMLStarlet is a handy command line tool for manipulating xml. For a migration from a Plone 3 site to Plone 4 I wanted to check some things e.g. Portlets Generic Setup syntax changes explains that the use of the “for” attribute in a portlet element is deprecated. I would like to know if we have any Generic Setup xml with a portlet element which has a “for” attribute:

$ xmlstarlet sel -t -m //portlet[@for] -c . some.xml

This uses the XPath expression “//portlet[@for]” to select any >portlet< elements which have a “for” attribute. It returns a copy of any elements which match. Let’s combine this with find:

$ find . -name "*.xml" -exec xmlstarlet sel -t -m //portlet[@for] -f -n -c . -n {} \;

Here we also output the filename with “-f” and add a few newlines to make it easier to read “-n”.

You will often need to set the namespace too:

find -L . -name "*.zcml" -exec xmlstarlet sel -N x="http://namespaces.zope.org/zope" -t -m //x:vocabulary -f -n -c . -n {} \;

This can easily be adjusted for more complicated queries. The interesting parts are the XPath expression and if you want a copy of the whole matching element you can use “-c .” as above, if you want the value you can use “-v”. See http://xmlstar.sourceforge.net/doc/xmlstarlet.txt for more info.

A nice tutorial:
http://www.freesoftwaremagazine.com/articles/xml_starlet

EDIT:

To print the value of an attrtribute you can use -c “string(@attrname)”

<?xml version="1.0"?>
<phonebook>
 <contact>
  <name>John Doe</name>
  <phone type="home">555-1234</phone>
  <phone type="work" class="emphasis">555-9876</phone>
  </contact>
</phonebook>
xmlstarlet sel -t -m "//contact/phone[@type='work']" -c "string(@class)"  test.xml

Emacs 23 Tramp: sudo to another user account on a remote machine

It took me a while to figure out the correct incantation to log in to another machine and change user account with sudo: `sudo -u someuser -i`. It’s actually very easy once you know how:

.emacs

(set-default 'tramp-default-proxies-alist
(quote (("remote.domain" "someuser" "/ssh:%h:"))))

In emacs:

C-x C-f /sudo:someuser@remote.domain:/some/dir

There’s some nice code on http://www.gnu.org/software/tramp/ to display the hostname in the mode-line:

(defconst my-mode-line-buffer-identification
(list
'(:eval
(let ((host-name
(or (file-remote-p default-directory 'host)
(system-name))))
(if (string-match "^[^0-9][^.]*\\(\\..*\\)" host-name)
(substring host-name 0 (match-beginning 1))
host-name)))
": %12b"))

(setq-default
mode-line-buffer-identification
my-mode-line-buffer-identification)

(add-hook
'dired-mode-hook
'(lambda ()
(setq
mode-line-buffer-identification
my-mode-line-buffer-identification)))

IE 7 and IE 8 on Linux with Wine 1.1.20

In an interview with Jeremy White (C.E.O. of CodeWeavers) on The Linux Action Show he mentioned they have IE7 working in CrossOver Office in the latest beta release of version 8 and that the latest version of Wine has lots of improvements that make this possible. I thought I’d try it out as I’m working on a new site and would like to be able to test it. I installed the latest version available for Mandriva 2009.0 in the package manager and did the following dance:

Created a fresh ~/.wine
Ran winetricks and set the version to win2k and installed IE6.
Ran winetricks and set the version to winxp.
Installed IE7:
$ wine IE7-WindowsXP-x86-enu.exe
Installed IE8:
$ wine IE8-WindowsXP-x86-ENU.exe
I think it installed the first time, but when I tried to run it, it threw an error. For no good reason I ran the installer again. After that it works fine (except it doesn’t seem to run any JavaScript). I think it is very usable for testing layout issues.

Some sites throw an error: “Internet Explorer couldn’t download %ws” and not having JavaScript working is a problem, perhaps I’m just missing a dll or something. I think it’s really great news though. I bet the CrossOver Office folks will have this polished pretty soon (if they don’t already).

It’s really phenominal work the Wine community do and it is greatly appreciated. I have no copy of Microsoft Windows and from time to time I really need to run a Windows application (e.g. Tax Software from the Government) and without Wine this wouldn’t be possible. Up until today I could only partially test in IE7 so it is great to know that I now have a way to make sure that sites I make are at least functional in Internet Explorer. Unless the site is for a client I’m not going to go to kill myself trying to make it work perfectly though, I tend to assume that people who use Internet Explorer are accustomed to things not working perfectly 😀

Are your modules ready for Drupal 6?

I was wondering when I could upgrade a Drupal 5 site to Drupal 6 so I knocked out a little script which reads the project page for each Drupal module you have installed and tells you the current releases and the version of Drupal that it can be used with:

http://drupal.org/project/og
Release: 6.x-1.0-rc6        Drupal version: 6.x
Release: 5.x-7.3           Drupal version: 5.x

It’s here:
http://cairde.net/social/drupal-module-status.py
(It requires Python and BeautifulSoup http://www.crummy.com/software/BeautifulSoup)