Introducing Config::Augeas::Exporter

Following my little experiments from two days ago, I decided to turn my prototype into a Perl module so others could benefit from it.
I am therefore happy to introduce Config::Augeas::Exporter, uploaded today to the CPAN. Packages are also available for Ubuntu Lucid and Natty in the Augeas PPA.
This module wraps up around Config::Augeas and currently provides 4 public export methods:
- to_xml(): export the Augeas tree to an XML::LibXML::Document object ;
- to_hash(): export the Augeas tree to a hash ;
- to_json(): export the Augeas tree to a JSON document ;
- to_yaml(): export the Augeas tree to a YAML document ;
In addition to this, it also provides a from_xml() method to import back an XML exported tree.
The module is shipped with two scripts, aug2xml and xml2aug, which are essentially the scripts presented in my previous blog entry, rewritten to use the module.
Thanks to the great advice of David Lutterkort, Augeasβ main developer, the XML layout has been improved, which makes it much nicer, smaller, easier to parse, and much easier to import back.
As a result of this, xml2aug is now able to replace only the files listed in the XML document, instead of replacing the whole tree.
Here are some examples of what can be done with aug2xml and xml2aug:
# Letβs export the pam.d files only, excluding the comment nodes $ aug2xml -p β/files/etc/pam.dβ -e β#commentβ > export.xml
How many files where exported?
$ grep -o β<fileβ export.xml | wc -l 34 $ ls -lh export.xml -rw-rβrβ 1 raphink raphink 20K 2011-02-25 23:06 export.xml
We can try some XPath requests on the file
For example finding the control condition
for the pam_env.so module in the cron rule
$ xpath -e β//file[@path=β/etc/pam.d/cronβ]/node[node[@label=βmoduleβ]=βpam_env.soβ]/node[@label=βcontrolβ]β export.xml Found 2 nodes in export.xml: β NODE β required β NODE β required
Now letβs import it back to a clean fakeroot
$ mkdir -p fakeroot/etc/pam.d $ xml2aug -r fakeroot/ -f export.xml $ tree fakeroot/ fakeroot/ βββ etc βββ pam.d βββ atd βββ chfn βββ chpasswd βββ chsh βββ common-account βββ common-auth βββ common-password βββ common-session βββ common-session-noninteractive βββ cron βββ cups βββ cvs βββ gdm βββ gdm-autologin βββ gnome-screensaver βββ kcheckpass βββ kdm βββ kdm-kde4 βββ kdm-kde4-np βββ kdm-np βββ kscreensaver βββ login βββ newusers βββ other βββ passwd βββ polkit βββ polkit-1 βββ ppp βββ samba βββ sshd βββ su βββ sudo βββ xscreensaver
2 directories, 33 files