On 02/07/10 11:44 +0300, Elver Loho wrote:
> On 1 July 2010 21:05, Cédric Krier <[email protected]> wrote:
> > I have updated the wiki page to add load of config.
> 
> You seem to have added the two lines:
> 
> from trytond.config import CONFIG
> CONFIG.load()
> 
> But that fails on me the exact same way and when I look at the
> trytond.config source code (which is amazingly clean! my hat is off to
> you!) then it makes sense, too:
> 
> 1. The CONFIG object that you call load() on is an instance of the
> ConfigManager class.
> 2. ConfigManager.__init__() sets self.options to a dictionary of default 
> values.
> 3. ConfigManager.__init__() sets self.configfile = None
> 4. CONFIG.load() is ConfigManager.load() which, as the first thing it
> does, is check if self.configfile is set.
> 5. Because self.configfile == None, then load() simply returns.
> 6. The CONFIG object contains only default values.
> 
> This works as a temporary fix:
> 
> from trytond.config import CONFIG
> CONFIG.configfile = "/etc/trytond.conf"  # Bad Hack!
> CONFIG.load()

I think better to put:

from trytond.config import CONFIG
CONFIG.parse()

> 
> Looking at ConfigManager.parse() leads me to believe that this is the
> main function you're usually calling. And it also sets self.configfile
> properly.
> 
> So I dove right in and created a patch that is doing what you intended
> in the wiki:
> 
> http://codereview.appspot.com/1692048/diff/1/2

Good. But I will prefer to remove the optparse from this module and put it on
server.py and make config just load from file.

> 
> Now using trytond as a module works great with only a CONFIG.load()
> 

Great :-)

-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpQcY8vY3Y2b.pgp
Description: PGP signature

Reply via email to