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):
28 def node_names (self):
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/%s : applying rules '%s' on %s"%(type,map_pattern,name))
41 for (k,v) in rename_dict.iteritems():
44 # step down but last step in path
46 for step in path[:-1]:
47 if not o.has_key(step):
49 if self.options.verbose:
50 utils.header ("WARNING : created step %s in path %s on %s %s"%(
53 # last step is the one for side-effect
55 if self.options.verbose:
56 if not o.has_key(step):
57 utils.header ("WARNING : inserting key %s for path %s on %s %s"%(
59 # apply formatting if '%s' found in the value
61 if self.options.verbose: print "TestMapper WARNING - None value - ignored, key=",k
65 if self.options.verbose:
66 print("TestMapper, rewriting %s: %s into %s"%(name,k,v))
68 # only apply first rule
71 def map (self,mapper):
73 plc_maps = mapper.get('plc',[])
74 node_maps = mapper.get('node',[])
77 name=TestMapper.plc_name(plc)
78 self.apply_first_map ('plc',name,plc,plc_maps)
80 for site in plc['sites']:
81 for node in site['nodes']:
82 nodename = TestMapper.node_name(node)
83 self.apply_first_map('node',nodename,node,node_maps)