Commit 71fb1054 authored by Jelte Jansen's avatar Jelte Jansen

[trac926] tab-completion for named_map entries

parent 834d4886
......@@ -193,11 +193,15 @@ def spec_name_list(spec, prefix="", recurse=False):
result.extend(spec_name_list(map_el['map_item_spec'], prefix + map_el['item_name'], recurse))
else:
result.append(prefix + name)
elif 'named_map_item_spec' in spec:
# we added a '/' above, but in this one case we don't want it
result.append(prefix[:-1])
pass
else:
for name in spec:
result.append(prefix + name + "/")
if recurse:
result.extend(spec_name_list(spec[name],name, recurse))
result.extend(spec_name_list(spec[name], name, recurse))
elif type(spec) == list:
for list_el in spec:
if 'item_name' in list_el:
......@@ -209,7 +213,7 @@ def spec_name_list(spec, prefix="", recurse=False):
else:
raise ConfigDataError("Bad specification")
else:
raise ConfigDataError("Bad specication")
raise ConfigDataError("Bad specification")
return result
class ConfigData:
......@@ -660,7 +664,28 @@ class MultiConfigData:
cur_value)
cur_id_part = cur_id_part + id_part + "/"
isc.cc.data.set(self._local_changes, identifier, value)
def _get_list_items(self, item_name):
"""This method is used in get_config_item_list, to add list
indices and named_map names to the completion list. If
the given item_name is for a list or named_map, it'll
return a list of those (appended to item_name), otherwise
the list will only contain the item_name itself."""
spec_part = self.find_spec_part(item_name)
if 'item_type' in spec_part and \
spec_part['item_type'] == 'named_map':
subslash = ""
if spec_part['named_map_item_spec']['item_type'] == 'map' or\
spec_part['named_map_item_spec']['item_type'] == 'named_map':
subslash = "/"
values, status = self.get_value(item_name)
if len(values) > 0:
return [ item_name + "/" + v + subslash for v in values.keys() ]
else:
return [ item_name ]
else:
return [ item_name ]
def get_config_item_list(self, identifier = None, recurse = False):
"""Returns a list of strings containing the item_names of
the child items at the given identifier. If no identifier is
......@@ -671,7 +696,11 @@ class MultiConfigData:
if identifier.startswith("/"):
identifier = identifier[1:]
spec = self.find_spec_part(identifier)
return spec_name_list(spec, identifier + "/", recurse)
spec_list = spec_name_list(spec, identifier + "/", recurse)
result_list = []
for spec_name in spec_list:
result_list.extend(self._get_list_items(spec_name))
return result_list
else:
if recurse:
id_list = []
......
......@@ -618,6 +618,24 @@ class TestMultiConfigData(unittest.TestCase):
config_items = self.mcd.get_config_item_list("Spec2", True)
self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5', 'Spec2/item6/value1', 'Spec2/item6/value2'], config_items)
def test_get_config_item_list_named_map(self):
config_items = self.mcd.get_config_item_list()
self.assertEqual([], config_items)
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec32.spec")
self.mcd.set_specification(module_spec)
config_items = self.mcd.get_config_item_list()
self.assertEqual(['Spec32'], config_items)
config_items = self.mcd.get_config_item_list(None, False)
self.assertEqual(['Spec32'], config_items)
config_items = self.mcd.get_config_item_list(None, True)
self.assertEqual(['Spec32/named_map_item'], config_items)
self.mcd.set_value('Spec32/named_map_item', { "aaaa": 4, "aabb": 5, "bbbb": 6})
config_items = self.mcd.get_config_item_list("/Spec32/named_map_item", True)
self.assertEqual(['Spec32/named_map_item/aaaa',
'Spec32/named_map_item/aabb',
'Spec32/named_map_item/bbbb',
], config_items)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment