|
From: Kong-Jei K. <kj...@ho...> - 2006-08-06 15:56:38
|
Hi all,
thanks for the great project! Just like to share some ideas.
Due to a requirement of my personal project, I added an option,
"allow_overrides", to ConfigObj. The option, if True, allows duplicate
sections at the same depth and also duplicate scalars in the same section.
Later scalars of the same name in the same section override earlier ones,
and later sections of the same name and depth update earlier ones.
This is done during the parsing of a configuration file.
Then, I added a merge_includes function to configobj.py which basically look
for special sections named, "__INCLUDE__", and merge the configuration file
specified by the "file" scalar of that section. The merge is done so that
all the top level scalars in the included file override the scalars of the
including section(the section that has the __INCLUDE__ sub section). The
__INCLUDE__ section is "replace" with sections from the included file. Some
cares have been taken so that this include feature works with the
'allow_overrides' feature in an expected way. For example:
#The file "x.ini" is:
a=1
b=2
[sec1]
c=3
[[__INCLUDE__]]
file=inc.ini
[[sec1.1]]
d=4
#where the file, "inc.ini" is:
a=0
[sec1.1]
c=5
d=6
[sec1.2]
x=a
y=b
z=c
and the result of merge_includes(ConfigObj("x.ini")) is:
a=1
b=2
[sec1]
c=3
a=0
[[sec1.1]]
c=5
d=4
[[sec1.2]]
x=a
y=b
z=c
I needed these two features because I would like to include some base
configuration files in a "child" configuration file but have the child
override some values defined in the base configurations. I've attached my
modified(against 4.3.2) configobj.py, which includes the merge_includes
function and the allow_overrides option to this mail for anyone interested.
Best regards,
Jack
|