2 # Thierry Parmentelat - INRIA Sophia Antipolis
6 # this works on a spec as defined in a config file
7 # and allows to remap various fields, typically to another testbox
8 # see an example in config_onelab_testbox32.py
15 def __init__ (self,plcs,options):
27 def node_names (self):
30 for site in plc['sites']:
31 for node in site['nodes']:
32 result.append(node['name'])
35 def apply_first_map (self, type, name, obj, maplist):
36 for (map_pattern,rename_dict) in maplist:
37 if utils.match (name,map_pattern):
38 if not self.options.quiet:
39 utils.header("TestMapper/%s : applying rules '%s' on %s"%(type,map_pattern,name))
40 for (k,v) in rename_dict.iteritems():
43 # step down but last step in path
45 for step in path[:-1]:
46 if not o.has_key(step):
48 if not self.options.quiet:
49 utils.header ("WARNING : created step %s in path %s on %s %s"%(
52 # last step is the one for side-effect
54 if not self.options.quiet:
55 if not o.has_key(step):
56 utils.header ("WARNING : inserting key %s for path %s on %s %s"%(
58 # apply formatting if '%s' found in the value
61 if not self.options.quiet:
62 print("TestMapper, rewriting %s: %s into %s"%(name,k,v))
64 # only apply first rule
67 def map (self,mapper):
69 plc_maps = mapper.get('plc',[])
70 node_maps = mapper.get('node',[])
73 name=TestMapper.plc_name(plc)
74 self.apply_first_map ('plc',name,plc,plc_maps)
76 for site in plc['sites']:
77 for node in site['nodes']:
78 nodename = TestMapper.node_name(node)
79 self.apply_first_map('node',nodename,node,node_maps)