Commit 2cd7eb5d authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[trac926] error on duplicate add

parent 4f17845a
......@@ -398,6 +398,8 @@ class BindCmdInterpreter(Cmd):
print("Error: " + str(dte))
except as dnfe:
print("Error: " + str(dnfe))
except as dnfe:
print("Error: " + str(dnfe))
# [XX] TODO: add back
#except KeyError as ke:
# print("Error: missing " + str(ke))
......@@ -22,8 +22,22 @@
import json
class DataNotFoundError(Exception): pass
class DataTypeError(Exception): pass
class DataNotFoundError(Exception):
"""Raised if an identifier does not exist according to a spec file,
or if an item is addressed that is not in the current (or default)
config (such as a nonexistent list or map element)"""
class DataAlreadyPresentError(Exception):
"""Raised if there is an attemt to add an element to a list or a
map that is already present in that list or map (i.e. if 'add'
is used when it should be 'set')"""
class DataTypeError(Exception):
"""Raised if there is an attempt to set an element that is of a
different type than the type specified in the specification."""
def remove_identical(a, b):
"""Removes the values from dict a that are the same as in dict b.
......@@ -441,6 +441,8 @@ class UIModuleCCSession(MultiConfigData):
if value not in cur_list:
self.set_value(identifier, cur_list)
raise + " already in " + identifier)
def _add_value_to_named_map(self, identifier, value):
if value is None:
......@@ -451,15 +453,21 @@ class UIModuleCCSession(MultiConfigData):
cur_map, status = self.get_value(identifier)
if not cur_map:
cur_map = {}
if value not in cur_map:
cur_map[value] = {}
self.set_value(identifier, cur_map)
raise + " already in " + identifier)
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. If value_str is
not given, we add the default as specified by the .spec
file. Raises a DataNotFoundError if the given identifier
is not specified in the specification as a map or list.
Raises a DataAlreadyPresentError if the specified element
already exists."""
module_spec = self.find_spec_part(identifier)
if module_spec is None:
raise"Unknown item " + str(identifier))
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