[FIX] tools/config: properly cast config file values.
bzr revid: vmt@openerp.com-20110601074400-hv1jrgoqw2ji0yah
This commit is contained in:
parent
039af62c64
commit
6d1753a734
|
@ -72,6 +72,9 @@ class configmanager(object):
|
|||
['publisher_warranty_url', 'load_language', 'root_path',
|
||||
'init', 'save', 'config', 'update'])
|
||||
|
||||
# dictionary mapping option destination (keys in self.options) to MyOptions.
|
||||
self.casts = {}
|
||||
|
||||
self.misc = {}
|
||||
self.config_file = fname
|
||||
self.has_ssl = check_ssl()
|
||||
|
@ -251,6 +254,7 @@ class configmanager(object):
|
|||
for group in parser.option_groups:
|
||||
for option in group.option_list:
|
||||
self.options[option.dest] = option.my_default
|
||||
self.casts[option.dest] = option
|
||||
|
||||
self.parse_config()
|
||||
|
||||
|
@ -314,8 +318,12 @@ class configmanager(object):
|
|||
]
|
||||
|
||||
for arg in keys:
|
||||
# Copy the command-line argument...
|
||||
if getattr(opt, arg):
|
||||
self.options[arg] = getattr(opt, arg)
|
||||
# ... or keep, but cast, the config file value.
|
||||
elif isinstance(self.options[arg], basestring) and self.casts[arg].type in optparse.Option.TYPE_CHECKER:
|
||||
self.options[arg] = optparse.Option.TYPE_CHECKER[self.casts[arg].type](self.casts[arg], arg, self.options[arg])
|
||||
|
||||
keys = [
|
||||
'language', 'translate_out', 'translate_in', 'overwrite_existing_translations',
|
||||
|
@ -327,8 +335,12 @@ class configmanager(object):
|
|||
]
|
||||
|
||||
for arg in keys:
|
||||
# Copy the command-line argument...
|
||||
if getattr(opt, arg) is not None:
|
||||
self.options[arg] = getattr(opt, arg)
|
||||
# ... or keep, but cast, the config file value.
|
||||
elif isinstance(self.options[arg], basestring) and self.casts[arg].type in optparse.Option.TYPE_CHECKER:
|
||||
self.options[arg] = optparse.Option.TYPE_CHECKER[self.casts[arg].type](self.casts[arg], arg, self.options[arg])
|
||||
|
||||
if opt.assert_exit_level:
|
||||
self.options['assert_exit_level'] = self._LOGLEVELS[opt.assert_exit_level]
|
||||
|
|
Loading…
Reference in New Issue