My first post here, couldn't figure out a way to respond to the
original thread ( can multiple config files be read / or included ? )

I basically have the same problem for needing mulitple config files.
The test.ini solution helps a bit there, however, its not complete: It
does not include logging configuration, so we loose that. I looked at
the pylons code, but to actually support multiple configs, there was a
good amount of work required.

The best method that I have found till now is to have a small python
script to merge the .ini files before starting the paster app,
something like:

==
import ConfigParser, sys, getopt
def merge_configs(files, output):
    config = ConfigParser.ConfigParser()
    for f in files:
        config.readfp(open(f))

    of = open(output, "w")
    config.write(of)
    of.close()

def usage():
    print "Usage: merge_configs.py -o <output file> <config files...>"

def main(args):
    try:
        opts, args = getopt.getopt(args, "o:")
    except getopt.GetOptError, e:
        print str(e)
        usage()
        return

    for o, v in opts:
        if o == "-o":
            output = v

    merge_configs(args, output)

if __name__ == "__main__":
    main(sys.argv[1:])
==

Then create a script like 'start_paster.sh' with:
==
python merge_configs.py -o config_merged.ini development.ini
development_override.ini
paster serve --reload config_merged.ini
==

The  benefit of this method is it works like true overriding.. you can
add just one parameter of one section in override.ini, and it will
just replace that parameter instead of the entire section.

You will have to manually reload the app. if there is a change to the
source configuration files.

Hope this helps.. would love to know if there is a better solution.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to