On 02/07/10 12:12 +0300, Elver Loho wrote:
> On 2 July 2010 11:53, Cédric Krier <[email protected]> wrote:
> > 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()
> 
> CONFIG.parse() calls optparse.OptionParser().parse_args() without
> arguments, which means it works directly on sys.args:
> http://docs.python.org/library/optparse.html#parsing-arguments
> 
> Therefore calling CONFIG.parse() directly when using trytond as a
> module would be a Bad Idea as it could conflict with any options
> you're passing to your own script.

Yes that is why I want to move the optparse in the server script.

> 
> >> 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.
> 
> Can I expect...
> 
> from trytond.config import CONFIG
> CONFIG.load()
> 
> ...to work properly in future versions of Tryton as it does with my patch?
> 
> I don't want to have to worry about my import script breaking after an 
> upgrade.

I think.


-- 
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: pgpN7b5M5j1E5.pgp
Description: PGP signature

Reply via email to