Config sections don't cascade

Bug #1211555 reported by Martin Morrison
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EnDroid
Confirmed
Wishlist
Unassigned

Bug Description

When a plugin (bar) requests its config in a given context (room: foo), it should be returned the aggregate of the config from the following sections, in priority order (i.e. a given config item in an earlier section overrides the same config item in any later section):

plugin : bar : room : foo
room : foo : plugin : bar
plugin : bar : room : *
room : * : plugin : bar
plugin : bar
plugin : * : room : foo
room : foo : plugin : *
plugin : *

Similarly, if the core needs any configuration within a given context (room: foo), it should similarly use the following precedence:

room : foo
room : *
Setup

(this latter applies to, e.g. the "plugins" configuration item)

This should all be abstracted by the configparser module.

Revision history for this message
Ben Hutchings (ben-hutchings) wrote :

The configparser module does this to some extent, with the config:

[foo:bar]
var = 0
[foo|far:bar]
var = 2
[*:bar|baz]
var=7
[foo:*]
var = 4
[foo|far:*]
var=5
[foo:bar|baz]
var = 1
[*:bar]
var = 6
[foo|far:bar|baz]
var = 3
[*:*]
var=8

parser.get("foo", "bar", "var", return_all=True)
returns [0,1,2,3,4,5,6,7]

Some sections in usermanagement's read_config file could be changed from:
config = conf.get("room", name, key), which returns only the most relevant result
to something like

def combine(dct, new):
   dct.update(new)
   return dct

config = reduce(combine, reversed(conf.get(..., return_all=True)), {})

Which would combine results from all possibly relevant sections of the config file.

Alternatively there could be an extra kwarg in get that would do this.

Revision history for this message
ChrisD (gingerchris) wrote :

To add a bit more context:

This isn't specific to config items with the same name (as per Ben's comment above), this is also meant for items with different names e.g.:

[foo:bar]
exactly_specified = so
[foo|far:bar]
lvl1_or = long
[*:bar|baz]
lvl1_star_lvl2_or = and
[foo:*]
lvl2_star_wc = thanks
[foo|far:*]
lvl1_2_lvl2_star = for
[foo:bar|baz]
lvl2_or = all
[*:bar]
lvl1_star = the
[foo|far:bar|baz]
lvl1_lvl2_or = fish
[*:*]
everything = fish
exactly_specified = wrong

parser.get("foo","bar") should return a dict containing all the above config items and the value of exactly_sepcified should be "so" not "wrong".

Changed in endroid:
status: New → Confirmed
ChrisD (gingerchris)
Changed in endroid:
importance: Medium → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.