Configuration Files

Subject: Re: Configuration Files
From: “Ara.T.Howard” ahoward@ngdc.noaa.gov
Date: Fri, 19 Dec 2003 02:11:56 +0900
References: 88419 88424 88427
In-reply-to: 88427

Date: Thu, 18 Dec 2003 13:51:45 +0900
From: Gavin Sinclair gsinclair@soyabean.com.au
Newsgroups: comp.lang.ruby
Subject: Re: Configuration Files

That sounds like a great config file system. I rolled my own basic
one
not too long ago, but having seen this, I’m thinking I’d replace
it. :slight_smile:

One thing I did in mine which I kind of like, but has drawbacks, is a
sort of grouping, where:
[plugin.player]
class=CommandPlayer
command=mpg123

is the same as:
plugin.player.class=CommandPlayer
plugin.player.command=mpg123

I have a really cool way of specifying config files. It goes like this:

plugin:
player:
class: CommandPlayer
command: mpg123

However, the code for parsing this is a secret :slight_smile:

i’m with you (and use it myself), but the above is problematic if you
actually
want non-programmers to be able to configure a system. for example,
how long
do you think it would take a non-programmer to debug this?

file config.rb:

require ‘yaml’
config = <<-txt
plugin:
player:
class: CommandPlayer
command: mpg123
txt
YAML::load(config)

~/eg/ruby > ruby config.rb
/data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in load': parse error on line 3, col 12: command: mpg123’ (ArgumentError)
from /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load’
from config.rb:8

I just got it :-). However it seems like cheating :wink: – there were no
tabs in Gavin’s example. There are lots of issues with TABs in yaml, we
all know. The common approach is just to avoid them alltogether. I
usually “untab” config files before calling YAML::load

Gennady.

···

On Thu, 18 Dec 2003, Gavin Sinclair wrote:

-a

Date: Fri, 19 Dec 2003 03:13:52 +0900
From: Gennady gfb@tonesoft.com
Newsgroups: comp.lang.ruby
Subject: Re: Configuration Files

> > file config.rb: > > ======== > > require 'yaml' > > config = < > plugin: > > player: > > class: CommandPlayer > > command: mpg123 > > txt > > YAML::load(config) > > > > > > ~/eg/ruby > ruby config.rb > > /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load': parse error on line > > 3, col 12: ` command: mpg123' (ArgumentError) > > from /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load' > > from config.rb:8 > > > I just got it :-). However it seems like cheating ;-) -- there were no > tabs in Gavin's example.

it may seem like cheating, but i spent twenty minutes debugging something just
like this after advocating yaml based configs here at work and letting a real
live user configure something - which immeadiately broke my software!

There are lots of issues with TABs in yaml, we all know. The common approach
is just to avoid them alltogether. I usually “untab” config files before
calling YAML::load

well - i now do too. the question is, why doesn’t yaml? currently i’m simply
gsub’ing tabs for eight spaces and figure this shouldn’t breaky anything but
haven’t really looked into further. i posted something a while back wondering
if trailing space is ever required in yaml, eg if it’s o.k.
to do this?

def parse file
buf = file.respond_to?(:read) ? file.read : open(file){|f| f.read}
buf.gsub! %r/\s+$/, ‘’
YAML::load(buf)
end

i guess i need to rtfm…

-a

···

On Fri, 19 Dec 2003, Gennady wrote:

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

I just got it :-). However it seems like cheating :wink: – there were no
tabs in Gavin’s example.

it may seem like cheating, but i spent twenty minutes debugging something just
like this after advocating yaml based configs here at work and letting a real
live user configure something - which immeadiately broke my software!

Interesting. Thanks for the warning.

There are lots of issues with TABs in yaml, we all know. The common approach
is just to avoid them alltogether. I usually “untab” config files before
calling YAML::load

well - i now do too. the question is, why doesn’t yaml? currently i’m simply
gsub’ing tabs for eight spaces and figure this shouldn’t breaky anything but
haven’t really looked into further. i posted something a while back wondering
if trailing space is ever required in yaml

I guess that’s up to the user. Iff you know that no trailing spaces
are allowed in your domain, then remove them.

As for tabs, I would simply error out and tell the user to get rid of
that tabs. Assigning a different number of spaces to a tab means
you’ll get different interpretations of the document, I think.

Perhaps YAML could include one or two methods to do this kind of
common pre-processing, so we don’t all duplicate the code?

Gavin

···

On Friday, December 19, 2003, 9:02:05 AM, Ara.T.Howard wrote:

I use Austin Ziegler’s Text::Format for expanding tabs. Works great for
me, and for yaml :wink:

Gennady.

Gavin Sinclair wrote:

···

On Friday, December 19, 2003, 9:02:05 AM, Ara.T.Howard wrote:

I just got it :-). However it seems like cheating :wink: – there were no
tabs in Gavin’s example.

it may seem like cheating, but i spent twenty minutes debugging something just
like this after advocating yaml based configs here at work and letting a real
live user configure something - which immeadiately broke my software!

Interesting. Thanks for the warning.

There are lots of issues with TABs in yaml, we all know. The common approach
is just to avoid them alltogether. I usually “untab” config files before
calling YAML::load

well - i now do too. the question is, why doesn’t yaml? currently i’m simply
gsub’ing tabs for eight spaces and figure this shouldn’t breaky anything but
haven’t really looked into further. i posted something a while back wondering
if trailing space is ever required in yaml

I guess that’s up to the user. Iff you know that no trailing spaces
are allowed in your domain, then remove them.

As for tabs, I would simply error out and tell the user to get rid of
that tabs. Assigning a different number of spaces to a tab means
you’ll get different interpretations of the document, I think.

Perhaps YAML could include one or two methods to do this kind of
common pre-processing, so we don’t all duplicate the code?

Gavin

exactly what i’m hoping for. it’s easy enough to process tabs in a
particular way, but it makes me queasy since the YAML spec might change, etc.
now, if the methods were part of yaml4r then i can simply use them and
complain to someone else when they break! (sorry _why) :wink:

plus - the file/string doesn’t need processing twice…

my 2cents. for now, i’m simply blowing away tabs.

-a

···

On Fri, 19 Dec 2003, Gavin Sinclair wrote:

Date: Fri, 19 Dec 2003 07:10:20 +0900
From: Gavin Sinclair gsinclair@soyabean.com.au
Newsgroups: comp.lang.ruby
Subject: Re: Configuration Files

On Friday, December 19, 2003, 9:02:05 AM, Ara.T.Howard wrote:

I just got it :-). However it seems like cheating :wink: – there were no
tabs in Gavin’s example.

it may seem like cheating, but i spent twenty minutes debugging something just
like this after advocating yaml based configs here at work and letting a real
live user configure something - which immeadiately broke my software!

Interesting. Thanks for the warning.

There are lots of issues with TABs in yaml, we all know. The common approach
is just to avoid them alltogether. I usually “untab” config files before
calling YAML::load

well - i now do too. the question is, why doesn’t yaml? currently i’m simply
gsub’ing tabs for eight spaces and figure this shouldn’t breaky anything but
haven’t really looked into further. i posted something a while back wondering
if trailing space is ever required in yaml

I guess that’s up to the user. Iff you know that no trailing spaces
are allowed in your domain, then remove them.

As for tabs, I would simply error out and tell the user to get rid of
that tabs. Assigning a different number of spaces to a tab means
you’ll get different interpretations of the document, I think.

Perhaps YAML could include one or two methods to do this kind of
common pre-processing, so we don’t all duplicate the code?

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================