|
From: Entity R. <ent...@gm...> - 2010-03-17 22:24:05
|
On Wed, 2010-03-17 at 14:53 -0500, Jason Baker wrote:
> On Wed, Mar 17, 2010 at 1:52 PM, Michael Foord
> <fuz...@vo...> wrote:
>
>
> Well - as far as I can tell setdefault is exactly a "magical
> get_by_interpolation function" - so I guess I'm not
> understanding you (setdefault is also a standard dictionary
> method).
>
> Michael
>
> Consider the following config file:
>
> [section]
> foo = 'bar'
> [[subsection]]
> baz = '$foo'
>
> Suppose I have a Section object that represents the subsection
> (configobj['section']['subsection']). Now suppose I do this:
>
> a = subsection['baz']
>
> Since the option baz contains a string '$foo', what happens is
> something like the following:
>
> 1. The interpolater looks in subsection to see if it has a foo
> option.
> 2. When it sees that it doesn't exist, it checks the DEFAULT section.
> 3. When it sees that *that* doesn't exist, it checks the parent
> section
> 4. The parent section has a foo option, so it returns it.
>
> Now suppose I do this:
>
> b = subsection['foo']
>
> What happens is more like the following:
>
> 1. Subsection is searched for a foo option.
> 2. Subsection doesn't have a foo option, so it throws a KeyError.
>
> What I would like is some kind of function such that I can do
> something like this:
>
> c = subsection.get_by_interpolation('foo')
>
> ...that would look for an option named foo, but would look in the same
> places as the first operation. Here's the reason why I want to do
> this. Using envbuilder, I want to write a config file like this:
>
> [project]
> parcel = 'parcel1', 'parcel2'
>
> [[DEFAULT]]
> branch = 'master'
>
> [[parcel1]]
>
> [[parcel2]]
> branch = 'someotherbranch'
>
> [commands]
> [[update]]
> default = 'git pull origin %branch'
>
> Essentially, I've written my own interpolation engine for commands
> such that a variable beginning with % is to be on the parcel. So when
> I run "envb update", it should essentially run:
>
> # Get parcel1 using branch from default
> $ git pull origin master
>
> # Get parcel2 using branch from parcel2
> $ git pull origin someotherbranch
>
> However, parcel1 would throw an exception because it doesn't actually
> have an option named "branch". Of course, I could do something like
> this:
>
> [project]
> parcels = 'parcel1', 'parcel2'
>
> [[DEFAULT]]
> default_branch = 'master'
>
> [[parcel1]]
> branch = '$default_branch'
>
> [[parcel2]]
> branch = 'someotherbranch'
>
> [commands]
> [[update]]
> default = 'git pull origin %branch'
>
> ...but that gets tedious when you start dealing with a nontrivial
> amount of parcels.
>
> Does that make things more clear, or did I just confuse you even
> more? :-)
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________ Configobj-develop mailing list Con...@li... https://lists.sourceforge.net/lists/listinfo/configobj-develop
I as well am interested in this. Auto-interpolation of a tree of
sections. Or rather, start from a specified branch, and then percolate
towards the trunk until a valid variable is found.
My Example: (IRC Bot)
[servers]
nick = BarBaz
# ...
[[Freenode]]
nick = FooBar
# ...
[[EFNet]]
# ...
config['servers']['EFNet'] (or some similar syntax) would return
"BarBaz"
|