15def deduplicate(newComp, compList):
16 """Merge newComp with compList. If a matching component is found it is updated
17 in compList. Otherwise a new component is added to compList.
18
19 Returns True if a new component has been added, otherwise False. If merging fails,
20 an exception is raised.
21 """
22
23 for idx, comp in enumerate(compList):
24 if comp.__cpp_type__==newComp.__cpp_type__ and comp.name==newComp.name:
25 exception = None
26 try:
27 newComp.merge(comp)
28 except Exception as e:
29 exception = e
30 if exception:
31 raiseWithCurrentContext(exception)
32
33
34
35 _msg.verbose("Reconciled configuration of component %s", comp.name)
36 compList[idx] = newComp
37 return False
38
39
40 _msg.debug("Adding component %s/%s to the job", newComp.__cpp_type__, newComp.name)
41 compList.append(newComp)
42 return True
43
44