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, typically to another testbox
10 # see an example in config_onelab_testbox32.py
17 def __init__ (self,plcs,options):
29 def node_names (self):
32 for site in plc['sites']:
33 for node in site['nodes']:
34 result.append(node['name'])
37 def apply_first_map (self, type, name, obj, maplist):
38 for (map_pattern,rename_dict) in maplist:
39 if utils.match (name,map_pattern):
40 if self.options.verbose:
41 utils.header("TestMapper/%s : applying rules '%s' on %s"%(type,map_pattern,name))
42 for (k,v) in rename_dict.iteritems():
45 # step down but last step in path
47 for step in path[:-1]:
48 if not o.has_key(step):
50 if self.options.verbose:
51 utils.header ("WARNING : created step %s in path %s on %s %s"%(
54 # last step is the one for side-effect
56 if self.options.verbose:
57 if not o.has_key(step):
58 utils.header ("WARNING : inserting key %s for path %s on %s %s"%(
60 # apply formatting if '%s' found in the value
63 if self.options.verbose:
64 print("TestMapper, rewriting %s: %s into %s"%(name,k,v))
66 # only apply first rule
69 def map (self,mapper):
71 plc_maps = mapper.get('plc',[])
72 node_maps = mapper.get('node',[])
75 name=TestMapper.plc_name(plc)
76 self.apply_first_map ('plc',name,plc,plc_maps)
78 for site in plc['sites']:
79 for node in site['nodes']:
80 nodename = TestMapper.node_name(node)
81 self.apply_first_map('node',nodename,node,node_maps)