Open bokov opened 8 years ago
Bleah. Tried to write my first doctest, but can't get it to be recognized by doctest.testmod()
. On the other hand, if I manually execute these commands, the results match the ones shown here and are what they should be.
"""
This one iterates over all the options in the 'foo' section (except 'in_use')
>>> [cnf.rxget(cnf.get('foo',ii)) for ii in cnf.options('foo') if ii != 'in_use']
['simple value', 'another simple value', 'the zebra returns a simple value', 'the water buffalo likes to cuddle with the gazelles']
Ditto for 'foo_subfoo'. Note the circular reference for foo_subfoo:opte, on which rxget()
eventually gives up and returns the raw value.
>>> [cnf.rxget(cnf.get('foo_subfoo',ii)) for ii in cnf.options('foo_subfoo') if ii != 'in_use']
['${foo_subfoo:optE}', 'the water buffalo likes to cuddle']
Ditto for 'bar'
>>> [cnf.rxget(cnf.get('bar',ii)) for ii in cnf.options('bar') if ii != 'in_use']
['another simple value', 'the giraffe also returns a simple value and another simple value and then another simple value']
Testing out shortcut replacement
>>> [cnf.rxget(ii) for ii in cnf.shortcuts]
['left join (select pn,', 'left join (select distinct pn,sd,', 'left join (select pn,sd,']
"""
Long story short, you can now interpolate multiple places in the same string having the pattern ${foo:bar} where foo is any config section and bar is any option in that section. You can also interpoalate a few selected magic words, or shortcuts.
Background: config file requires deployers of DataFinisher to write SQL fragments. Many of them can be replaced with references to re-usable boilerplate. This ticket, as other tickets outside our internal tracker at this time, is more for documentation purposes than for a specific task. It will be closed when this feature is implemented.
Pseudocode:
Sample config sections (assuming a self.shortcuts of {'AAA':123,'BBB':'foo:optC'}):
...there, got it out of my head, hopefully I can get some peace now.