[svn] commit: r4123 - in /branches/trac384/src: bin/bindctl/bindcmd.py bin/bindctl/bindctl-source.py.in lib/python/isc/config/ccsession.py lib/python/isc/config/config_data.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jan 3 14:29:56 UTC 2011
Author: jelte
Date: Mon Jan 3 14:29:55 2011
New Revision: 4123
Log:
make value optional for 'config add <list>'; add the default value that is specified in the spec file in that case
always show map contents for 'config show <map>', not just the map name
Modified:
branches/trac384/src/bin/bindctl/bindcmd.py
branches/trac384/src/bin/bindctl/bindctl-source.py.in
branches/trac384/src/lib/python/isc/config/ccsession.py
branches/trac384/src/lib/python/isc/config/config_data.py
Modified: branches/trac384/src/bin/bindctl/bindcmd.py
==============================================================================
--- branches/trac384/src/bin/bindctl/bindcmd.py (original)
+++ branches/trac384/src/bin/bindctl/bindcmd.py Mon Jan 3 14:29:55 2011
@@ -590,7 +590,10 @@
data, default = self.config_data.get_value(identifier)
print(json.dumps(data))
elif cmd.command == "add":
- self.config_data.add_value(identifier, cmd.params['value'])
+ if 'value' in cmd.params:
+ self.config_data.add_value(identifier, cmd.params['value'])
+ else:
+ self.config_data.add_value(identifier)
elif cmd.command == "remove":
if 'value' in cmd.params:
self.config_data.remove_value(identifier, cmd.params['value'])
Modified: branches/trac384/src/bin/bindctl/bindctl-source.py.in
==============================================================================
--- branches/trac384/src/bin/bindctl/bindctl-source.py.in (original)
+++ branches/trac384/src/bin/bindctl/bindctl-source.py.in Mon Jan 3 14:29:55 2011
@@ -48,10 +48,10 @@
cmd.add_param(param)
module.add_command(cmd)
- cmd = CommandInfo(name = "add", desc = "Add entry to configuration list")
+ cmd = CommandInfo(name = "add", desc = "Add an entry to configuration list. If no value is given, a default value is added.")
param = ParamInfo(name = "identifier", type = "string", optional=True)
cmd.add_param(param)
- param = ParamInfo(name = "value", type = "string", optional=False)
+ param = ParamInfo(name = "value", type = "string", optional=True)
cmd.add_param(param)
module.add_command(cmd)
Modified: branches/trac384/src/lib/python/isc/config/ccsession.py
==============================================================================
--- branches/trac384/src/lib/python/isc/config/ccsession.py (original)
+++ branches/trac384/src/lib/python/isc/config/ccsession.py Mon Jan 3 14:29:55 2011
@@ -374,19 +374,34 @@
self._set_current_config(config)
- def add_value(self, identifier, value_str):
+ def add_value(self, identifier, value_str = None):
"""Add a value to a configuration list. Raises a DataTypeError
if the value does not conform to the list_item_spec field
- of the module config data specification"""
+ of the module config data specification. If value_str is
+ not given, we add the default as specified by the .spec
+ file."""
module_spec = self.find_spec_part(identifier)
if (type(module_spec) != dict or "list_item_spec" not in module_spec):
raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list")
- value = isc.cc.data.parse_value_str(value_str)
+
cur_list, status = self.get_value(identifier)
if not cur_list:
cur_list = []
+
+ # Hmm. Do we need to check for duplicates?
+ value = None
+ if value_str is not None:
+ value = isc.cc.data.parse_value_str(value_str)
+ else:
+ if "item_default" in module_spec["list_item_spec"]:
+ value = module_spec["list_item_spec"]["item_default"]
+
+ if value is None:
+ raise isc.cc.data.DataNotFoundError("No value given and no default for " + str(identifier))
+
if value not in cur_list:
cur_list.append(value)
+
self.set_value(identifier, cur_list)
def remove_value(self, identifier, value_str):
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 Mon Jan 3 14:29:55 2011
@@ -432,7 +432,7 @@
spec_part_list = spec_part['list_item_spec']
list_value, status = self.get_value(identifier)
if list_value is None:
- print("Error: %s not found" % identifier)
+ print("Error: identifier '%s' not found" % identifier)
return
if type(list_value) != list:
# the identifier specified a single element
@@ -448,18 +448,10 @@
for i in range(len(list_value)):
self._append_value_item(result, spec_part_list, "%s[%d]" % (identifier, i), all)
elif item_type == "map":
+ # just show the specific contents of a map, we are
+ # almost never interested in just its name
spec_part_map = spec_part['map_item_spec']
- value, status = self.get_value(identifier)
- # if there are no contents, simply add the value
- # as one empty element, otherwise append them
- # individually
- if value != {}:
- self._append_value_item(result, spec_part_map, identifier, all)
- else:
- entry = _create_value_map_entry(identifier,
- item_type,
- {}, status)
- result.append(entry)
+ self._append_value_item(result, spec_part_map, identifier, all)
else:
value, status = self.get_value(identifier)
entry = _create_value_map_entry(identifier,
More information about the bind10-changes
mailing list