Beispiel #1
0
 def _change_value(self, root, lines, action):
     """Change value to speciffied"""
     try:
         node = root.get_node_at_path(action['parameters']['path'])
     except:
         return False
     if node.implementation != DataNode.Implementation.scalar:
         self._add_notification(
             "Specified path '{0}',  is not scalar type node, action is ignored".format(
             self._get_paths_str(action, 'path')),  self._Severity.warning , action, node
         )
         return False
     old = action['parameters']['old_value'] 
     new = action['parameters']['new_value']
     l1, c1, l2, c2 =  StructureChanger.value_pos(node)
     return StructureChanger.replace(lines, new,  old,  l1, c1, l2, c2 )
Beispiel #2
0
 def _replace_value(self, root, lines, action):
     """Rename type transformation"""
     try:
         node = root.get_node_at_path(action['parameters']['path'])
     except:
         return False
     if node.implementation != DataNode.Implementation.scalar:
         self._add_notification(
             "Specified path '{0}',  is not scalar type node, action is ignored".format(
             self._get_paths_str(action, 'path')),  self._Severity.warning , action, node
         )
         return False
     pattern = action['parameters']['pattern'] 
     replacement = action['parameters']['replacement']
     old = str(node.value)
     new = re.sub( pattern, replacement, old)
     if new != old:
         l1, c1, l2, c2 =  StructureChanger.value_pos(node)
         return StructureChanger.replace(lines, new,  old,  l1, c1, l2, c2 )
     return False    
Beispiel #3
0
 def _scale_value(self, root, lines, action):
     """Multiply value by set scale"""
     try:
         node = root.get_node_at_path(action['parameters']['path'])
         scale = float(action['parameters']['scale'])
     except:
         return False
     if node.implementation != DataNode.Implementation.scalar:
         self._add_notification(
             "Specified path '{0}', is not scalar type node, action is ignored".format(
             self._get_paths_str(action, 'path')),  self._Severity.warning , action, node
         )
         return False
     try:
         value =  float(node.value)
     except ValueError:
         self._add_notification(
             "Type of value in specified path '{0}', is not numeric, action is ignored".format(
             self._get_paths_str(action, 'path')),  self._Severity.warning , action, node
         )
         return False
     l1, c1, l2, c2 =  StructureChanger.value_pos(node)
     return StructureChanger.replace(lines, str(scale*value),   lines[l1][c1:c2],  l1, c1, l2, c2 )