2 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
3 # Copyright (C) 2010 INRIA
8 # this works on a spec as defined in a config file
9 # and allows to remap various fields on the local substrate
16 def __init__(self,plcs,options):
18 self.options = options
31 for site in plc['sites']:
32 for node in site['nodes']:
33 result.append(node['name'])
36 def apply_first_map(self, type, name, obj, maplist):
37 for (map_pattern,rename_dict) in maplist:
38 if utils.match (name,map_pattern):
39 if self.options.verbose:
40 utils.header("TestMapper/{} : applying rules '{}' on {}"\
41 .format(type, map_pattern, name))
42 for (k,v) in rename_dict.items():
45 # step down but last step in path
47 for step in path[:-1]:
50 if self.options.verbose:
51 utils.header ("WARNING : created step {} in path {} on {} {}"\
52 .format(step,path,type,name))
54 # last step is the one for side-effect
56 if self.options.verbose:
58 utils.header ("WARNING : inserting key {} for path {} on {} {}"\
59 .format(step, path, type, name))
60 # apply formatting if '%s' found in the value
62 if self.options.verbose: print("TestMapper WARNING - None value - ignored, key=",k)
66 if self.options.verbose:
67 print(("TestMapper, rewriting {}: {} into {}"\
70 # only apply first rule
73 def map(self, mapper):
75 plc_maps = mapper.get('plc',[])
76 node_maps = mapper.get('node',[])
79 name = TestMapper.plc_name(plc)
80 self.apply_first_map('plc', name, plc, plc_maps)
82 for site in plc['sites']:
83 for node in site['nodes']:
84 nodename = TestMapper.node_name(node)
85 self.apply_first_map('node', nodename, node, node_maps)