On Aug 11, 3:38 pm, Erik Bray <[email protected]> wrote: > On Tue, Aug 11, 2009 at 4:03 AM, alind<[email protected]> wrote: > > > After some more searching I found a library python-configobj > >http://www.voidspace.org.uk/python/configobj.html#downloading > > Am I suppose to use some other thing. > > IMHO this will work fine for me. > > Thanks. > > > On Aug 11, 12:42 pm, alind sharma <[email protected]> wrote: > >> I want to edit trac.ini using python/shell. Whats the best way to do it. > >> Want something like I should be able to read trac.ini into some sort of > >> dictionary/list, check if some option is present in the dictionary, and > >> edit its value. There are some options that I want to add like > >> track.hg* = enabled, > >> webauth plugin = disbaled > >> webadming = enabled > >> etc. If something like this is already present then it will be fine, > >> otherwise i will write one myself. Can anybody guide me towards the best > >> way of achieving this. Thanks in advance. > > >> Alind Sharma > > Why bother? If you already have Trac, just use what Trac uses: from > trac.config import Configuration.
I second that, however, generally when I want to read ini files, I use the good 'ol ConfigParser library. as a matter of fact, I think I still use this recipe, or a variant of it: http://code.activestate.com/recipes/65334/ you only need the LoadConfig method to read it, the rest is just code to support the python standard "main()" function with some values: <pre> def LoadConfig(file, config={}): """ returns a dictionary with key's of the form <section>.<option> and the values """ config = config.copy() cp = ConfigParser.ConfigParser() cp.read(file) for sec in cp.sections(): name = string.lower(sec) for opt in cp.options(sec): config[name + "." + string.lower(opt)] = string.strip (cp.get(sec, opt)) return config </pre> and the commented/follow up tighter "write" method looks like the way to write. lets you do this: assming your object is cfg print cfg.sectionX.parameterY.value and cfg.sectionX.parameterY.value=newvalue type addressing, with this type or recipe. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Trac Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/trac-users?hl=en -~----------~----~----~----~------~----~------~--~---
