Discussion:
Module Config Sections
Nick Nachefski
2011-03-08 15:32:52 UTC
Permalink
Hello,

How can I get a func module to parse config items from a section other than "[main]"?

Say I have this module:

class Testing(func_module.FuncModule):
version = "0.0.1"
api_version = "0.0.1"
description = "Testing Module"

class Config(BaseConfig):
main_var = Option()
other_var = Option()

def configdump(self):
return self.config_items()

And this corresponding config file:

[main]
main_var = "some string"

[other]
other_var = "some other string"


When I run the configdump method, the variable under [other] never gets populated.

I see in the BaseConfig class that the populate method is hard coded to "main"

opts.populate(confparser, 'main')


I'm converting a stand-alone python script to a func module and have quite a few variables to store in the config file. It would be nice if I could section these out. Is this possible?

________________________________
Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments. Email transmission cannot be guaranteed to be secure or error-free. Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments. This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.
Léon Keijser
2011-03-09 06:28:17 UTC
Permalink
Post by Nick Nachefski
How can I get a func module to parse config items from a section other
than “[main]”?
Without checking what func uses to store/retrieve configuration
settings, this is what i always use:


from configobj import ConfigObj
config = ConfigObj('your_config_file')
section = config['other']
other_var = section['other_var']
print "The value is %s" % other_var

HTH

regards,

Léon

Loading...