Ideas about metaconfiguration tool (proz?)

Paweł Kołodziej pawelk at pld.org.pl
Wed May 23 00:44:34 CEST 2001


Dnia Mon, May 21, 2001 at 06:06:06PM +0200, Michal Moskal napisał(a):
> On Mon, May 21, 2001 at 03:02:26PM +0200, Lukas Dobrek wrote:
> > This is the metaconfig file with desciption of an booting procedure for Linux.
> > 
> > TYPE=LINUX
> > ROOT=/dev/hda2
> > KERNEL=/boot/kernel-3.4.7-22.gz
> > INITRD=/boot/initrd
> > VGA=0x317
> > APPEND="video=atyfb:1024x768,font=SUN12x22"
> > 
> > The config file is /etc/lilo.conf or /boot/grub/menu.lst (just for
> > information).
> > 
> > Ok it is cleari, easy to write and simple. But I would like to have also 
> > something like this somewhere. 
> > 
> > <varible> 
> > TYPE
> > <posible_valuess>
> > <val>LINUX</val><val>WINDA</val><val>bsd</val><val>dupa</val>
> > <error>
> > Sorry but there is no such OS.
> > <error>
> > <error LANG=pl>
> > Nie ma takiego systemu baranie.
> > <error LANG=pl>
> > </posible_valuess>
> > </verible>
> 
> As Wiget pointed out: it's much like XML-Schama... So there are (will
> be?) tools ready for this kind of validation. However they validate
> XML, not Name=value pairs. There are two parts of meteconfigurator work:
> one is to validate meta.config -- this can be done using XML-Schama/DTD,
> but only if config file is in XML, the second is to generate sth.conf.
> Shell would be good here I guess.

Oh. shell. hmm.. It's said that everything is posible to do using only
XML and scotch tape. So why to use sh? Maybe XSLT will be beter (there are
already some tools for it :)

Small example:
+++++++++++++++++++++++++++++++++++++++ file lilo.xml:
<image type="linux">
        <kernel>/boot/mykernel</kernel>
        <label>PLD Linux</label>
        <root>/dev/hda2</root>
        <initrd>/boot/by</initrd>
</image>

<image type="win">
        <root>/dev/null</root>
        <label>windows</label>
        <table>/dev/hda</table>
</image>

</boot>

+++++++++++++++++++++++++++++++++++++++++ file: lilo.xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:xt="http://www.jclark.com/xt"
                extension-element-prefixes="xt">


<xsl:output method="text"/>

<xsl:template match="/boot">
	<xsl:apply-templates/>
#end of generated lilo.conf
	
</xsl:template>

<xsl:template match="image">
	<xsl:variable name="type"><xsl:value-of select="@type"/></xsl:variable>
	<xsl:choose>
		<xsl:when test='@type="linux"'>
			
			<xsl:apply-templates select="kernel"/>
			<xsl:apply-templates select="root"/>
			<xsl:apply-templates select="label"/>
			<xsl:apply-templates select="initrd"/>
		</xsl:when>
		<xsl:when test='@type="win"'>
			<xsl:apply-templates select="root"/>
			<xsl:apply-templates select="label"/>
			<xsl:apply-templates select="table"/>
		</xsl:when>
	</xsl:choose>
</xsl:template>

<xsl:template match="kernel">
image=<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="root">
	<xsl:if test='../@type="linux"'>
	root=<xsl:value-of select="text()"/>
	</xsl:if>
	<xsl:if test='../@type="win"'>
other=<xsl:value-of select="text()"/>
	</xsl:if>
</xsl:template>

<xsl:template match="label">
	label=<xsl:value-of select="text()"/>
</xsl:template>

<xsl:template match="table">
	table=<xsl:value-of select="text()"/>
</xsl:template>


<xsl:template match="initrd">
	initrd=<xsl:value-of select="text()"/>
</xsl:template>

</xsl:stylesheet>
		
++++++++++++++++++++++++++++++++++++++++++++++++++++

And then:
[pawel at paw ~/PLD/my]%  java com.jclark.xsl.sax.Driver lilo.xml lilo.xsl lilo.conf && cat lilo.conf


image=/boot/mykernel
        root=/dev/hda2
        label=PLD Linux
        initrd=/boot/by


other=/dev/null
        label=windows
        table=/dev/hda


#end of generated lilo.conf

You have to downland xt.zip and xs.zip from http://www.jclark.com/xml/xt.html
extract it and put xt.jar and xs.jar on your CLASSPATH first.
Only one disadventage of above is that parser and converter is written in
java.
Adventages:
1) xtpl seams to be simply (Above is my first xsl (I have been learning how to
   write it for a hour))
2) xtpl seams to be powerful. 

Maybe there is some xtpl written in C/C++ ?


-- 
Paweł Kołodziej 
pawelk at pld.org.pl 



More information about the pld-devel-en mailing list