|
From: Michael F. <fuz...@vo...> - 2006-09-04 20:20:55
|
Michael Foord wrote: > > > ---------- Forwarded message ---------- > From: *Kong-Jei Kuan* <kj...@ho... <mailto:kj...@ho...>> > Date: 06-Aug-2006 16:55 > Subject: [Configobj-develop] [__INCLUDE__] + allow_overrides > To: con...@li... > <mailto:con...@li...> > > 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: > Hello Jack, Thanks for your suggestion and patch. I've thought about ways of including external files in config files. I don't think adding support directly in ConfigObj is the best way. It adds complexity to the implementation, syntax and API. You could write a fairly simple recursive wrapper that checks for the presence of '__include__' in sections, and use the section method 'merge' to achieve the same thing. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > #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 > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> > > _______________________________________________ > Configobj-develop mailing list > Con...@li... > <mailto:Con...@li...> > https://lists.sourceforge.net/lists/listinfo/configobj-develop > <https://lists.sourceforge.net/lists/listinfo/configobj-develop> > |