mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] runbot: allow specifying section for config option
When adding config option, allow to specify it's section (default to odoo standard 'options' section)
This commit is contained in:
parent
6e1fc61781
commit
f8ef025807
@ -74,9 +74,9 @@ class Command():
|
|||||||
cmd_chain += [' '.join(final) for final in self.finals if final]
|
cmd_chain += [' '.join(final) for final in self.finals if final]
|
||||||
return ' ; '.join(cmd_chain)
|
return ' ; '.join(cmd_chain)
|
||||||
|
|
||||||
def add_config_tuple(self, option, value):
|
def add_config_tuple(self, option, value, section=None):
|
||||||
assert '-' not in option
|
assert '-' not in option
|
||||||
self.config_tuples.append((option, value))
|
self.config_tuples.append((option, value, section or 'options'))
|
||||||
|
|
||||||
def get_config(self, starting_config=''):
|
def get_config(self, starting_config=''):
|
||||||
""" returns a config file content based on config tuples and
|
""" returns a config file content based on config tuples and
|
||||||
@ -84,10 +84,10 @@ class Command():
|
|||||||
"""
|
"""
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read_string(starting_config)
|
config.read_string(starting_config)
|
||||||
if self.config_tuples and not config.has_section('options'):
|
for option, value, section in self.config_tuples:
|
||||||
config.add_section('options')
|
if not config.has_section(section):
|
||||||
for option, value in self.config_tuples:
|
config.add_section(section)
|
||||||
config.set('options', option, value)
|
config.set(section, option, value)
|
||||||
res = io.StringIO()
|
res = io.StringIO()
|
||||||
config.write(res)
|
config.write(res)
|
||||||
res.seek(0)
|
res.seek(0)
|
||||||
|
@ -27,12 +27,16 @@ class Test_Command(common.TransactionCase):
|
|||||||
self.assertIn('bar', cmd.cmd)
|
self.assertIn('bar', cmd.cmd)
|
||||||
cmd.add_config_tuple('x', 'y')
|
cmd.add_config_tuple('x', 'y')
|
||||||
|
|
||||||
|
cmd.add_config_tuple('yy', 'zz', section='other')
|
||||||
|
|
||||||
content = cmd.get_config(starting_config=CONFIG)
|
content = cmd.get_config(starting_config=CONFIG)
|
||||||
|
|
||||||
self.assertIn('[options]', content)
|
self.assertIn('[options]', content)
|
||||||
self.assertIn('foo = bar', content)
|
self.assertIn('foo = bar', content)
|
||||||
self.assertIn('a = b', content)
|
self.assertIn('a = b', content)
|
||||||
self.assertIn('x = y', content)
|
self.assertIn('x = y', content)
|
||||||
|
self.assertIn('[other]', content)
|
||||||
|
self.assertIn('yy = zz', content)
|
||||||
|
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
cmd.add_config_tuple('http-interface', '127.0.0.1')
|
cmd.add_config_tuple('http-interface', '127.0.0.1')
|
||||||
|
Loading…
Reference in New Issue
Block a user