[svn] commit: r3932 - in /branches/trac384/src/lib/python/isc: cc/data.py config/config_data.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 21 14:06:37 UTC 2010
Author: jelte
Date: Tue Dec 21 14:06:37 2010
New Revision: 3932
Log:
improve asking for and printing lists
Modified:
branches/trac384/src/lib/python/isc/cc/data.py
branches/trac384/src/lib/python/isc/config/config_data.py
Modified: branches/trac384/src/lib/python/isc/cc/data.py
==============================================================================
--- branches/trac384/src/lib/python/isc/cc/data.py (original)
+++ branches/trac384/src/lib/python/isc/cc/data.py Tue Dec 21 14:06:37 2010
@@ -100,8 +100,8 @@
i = id_str.find('[')
if i < 0:
- if identifier.find(']') >= 0:
- raise DataTypeError("Bad format in identifier: " + str(identifier))
+ if id_str.find(']') >= 0:
+ raise DataTypeError("Bad format in identifier (] but no [): " + str(identifier))
return identifier, None
# keep the non-index part of that to replace later
@@ -110,7 +110,7 @@
while i >= 0:
e = id_str.find(']')
if e < i + 1:
- raise DataTypeError("Bad format in identifier: " + str(identifier))
+ raise DataTypeError("Bad format in identifier (] before [): " + str(identifier))
try:
indices.append(int(id_str[i+1:e]))
except ValueError:
@@ -118,9 +118,9 @@
id_str = id_str[e + 1:]
i = id_str.find('[')
if i > 0:
- raise DataTypeError("Bad format in identifier: " + str(identifier))
+ raise DataTypeError("Bad format in identifier ([ within []): " + str(identifier))
if id.find(']') >= 0 or len(id_str) > 0:
- raise DataTypeError("Bad format in identifier: " + str(identifier))
+ raise DataTypeError("Bad format in identifier (extra ]): " + str(identifier))
# we replace the final part of the original identifier with
# the stripped string
Modified: branches/trac384/src/lib/python/isc/config/config_data.py
==============================================================================
--- branches/trac384/src/lib/python/isc/config/config_data.py (original)
+++ branches/trac384/src/lib/python/isc/config/config_data.py Tue Dec 21 14:06:37 2010
@@ -121,6 +121,7 @@
# strip list selector part
# don't need it for the spec part, so just drop it
id, list_indices = isc.cc.data.split_identifier_list_indices(id_part)
+ # is this part still needed? (see below)
if type(cur_el) == dict and 'map_item_spec' in cur_el.keys():
found = False
for cur_el_item in cur_el['map_item_spec']:
@@ -129,11 +130,20 @@
found = True
if not found:
raise isc.cc.data.DataNotFoundError(id + " in " + str(cur_el))
+ elif type(cur_el) == dict and 'list_item_spec' in cur_el.keys():
+ cur_el = cur_el['list_item_spec']
elif type(cur_el) == list:
found = False
for cur_el_item in cur_el:
if cur_el_item['item_name'] == id:
cur_el = cur_el_item
+ # if we need to go further, we may need to 'skip' a step here
+ # but not if we're done
+ if id_parts[-1] != id_part and type(cur_el) == dict:
+ if "map_item_spec" in cur_el:
+ cur_el = cur_el["map_item_spec"]
+ elif "list_item_spec" in cur_el:
+ cur_el = cur_el["list_item_spec"]
found = True
if not found:
raise isc.cc.data.DataNotFoundError(id + " in " + str(cur_el))
@@ -406,6 +416,56 @@
return value, self.DEFAULT
return None, self.NONE
+ def _append_value_item(self, result, spec_part, identifier):
+ if type(spec_part) == list:
+ # list of items to show
+ for item in spec_part:
+ value, status = self.get_value("/" + identifier\
+ + "/" + item['item_name'])
+ entry = _create_value_map_entry(identifier + "/" + item['item_name'],
+ item['item_type'],
+ value, status)
+ result.append(entry)
+ elif type(spec_part) == dict:
+ # Two 'special cases' for easier viewing;
+ # If the item is a map, show the first-level contents
+ #
+ # If the item is a list, show all elements (with index in the name).
+ #
+ item = spec_part
+ if item['item_type'] == 'list':
+ li_spec = item['list_item_spec']
+ value, status = self.get_value("/" + identifier)
+ if type(value) == list:
+ i = 0;
+ for list_value in value:
+ result_part2 = _create_value_map_entry(
+ "%s[%d]" % (identifier, i),
+ li_spec['item_type'],
+ list_value)
+ result.append(result_part2)
+ i = i + 1
+ elif value is not None:
+ self._append_value_item(result, li_spec, identifier)
+ elif item['item_type'] == 'map':
+ map_name = item['item_name'] + '/'
+ for map_item in item['map_item_spec']:
+ value, status = self.get_value('/' + identifier + '/' + map_item['item_name'])
+ entry = _create_value_map_entry(
+ identifier + "/" + map_item['item_name'],
+ map_item['item_type'],
+ value,
+ status)
+ result.append(entry)
+ else:
+ value, status = self.get_value("/" + identifier)
+ if value is not None:
+ entry = _create_value_map_entry(
+ identifier,
+ item['item_type'],
+ value, status)
+ result.append(entry)
+
def get_value_maps(self, identifier = None):
"""Returns a list of dicts, containing the following values:
name: name of the entry (string)
@@ -429,56 +489,7 @@
spec = self.get_module_spec(module)
if spec:
spec_part = find_spec_part(spec.get_config_spec(), id)
- if type(spec_part) == list:
- # list of items to show
- for item in spec_part:
- value, status = self.get_value("/" + identifier\
- + "/" + item['item_name'])
- entry = _create_value_map_entry(item['item_name'],
- item['item_type'],
- value, status)
- result.append(entry)
- elif type(spec_part) == dict:
- # Two 'special cases' for easier viewing;
- # If the item is a map, show the first-level contents
- #
- # If the item is a list, show all elements (with index in the name).
- #
- item = spec_part
- if item['item_type'] == 'list':
- li_spec = item['list_item_spec']
- value, status = self.get_value("/" + identifier)
- if type(value) == list:
- for list_value in value:
- result_part2 = _create_value_map_entry(
- li_spec['item_name'],
- li_spec['item_type'],
- list_value)
- result.append(result_part2)
- elif value is not None:
- entry = _create_value_map_entry(
- li_spec['item_name'],
- li_spec['item_type'],
- value, status)
- result.append(entry)
- elif item['item_type'] == 'map':
- map_name = item['item_name'] + '/'
- for map_item in item['map_item_spec']:
- value, status = self.get_value('/' + identifier + '/' + map_item['item_name'])
- entry = _create_value_map_entry(
- map_name + map_item['item_name'],
- map_item['item_type'],
- value,
- status)
- result.append(entry)
- else:
- value, status = self.get_value("/" + identifier)
- if value is not None:
- entry = _create_value_map_entry(
- item['item_name'],
- item['item_type'],
- value, status)
- result.append(entry)
+ self._append_value_item(result, spec_part, identifier)
return result
def set_value(self, identifier, value):
More information about the bind10-changes
mailing list