def alter(data, system):
    """Alter data in dm format devices"""
    device = data[0]
    action = data[1]
    if data[2] == '*':
        data[2] = '.*'
    regex = re.compile(data[2])
    prop = data[3]
    value = float(data[4])
    if action == 'MUL':
        for item in range(system.__dict__[device].n):
            if regex.search(system.__dict__[device].name[item]):
                system.__dict__[device].__dict__[prop][item] *= value
    elif action == 'REP':
        for item in range(system.__dict__[device].n):
            if regex.search(system.__dict__[device].name[item]):
                system.__dict__[device].__dict__[prop][item] = value
    elif action == 'DIV':
        if not value:
            return
        for item in range(system.__dict__[device].n):
            if regex.search(system.__dict__[device].name[item]):
                system.__dict__[device].__dict__[prop][item] /= value
    elif action == 'SUM':
        for item in range(system.__dict__[device].n):
            if regex.search(system.__dict__[device].name[item]):
                system.__dict__[device].__dict__[prop][item] += value
    elif action == 'SUB':
        for item in range(system.__dict__[device].n):
            if regex.search(system.__dict__[device].name[item]):
                system.__dict__[device].__dict__[prop][item] -= value
    elif action == 'POW':
        for item in range(system.__dict__[device].n):
            if regex.search(system.__dict__[device].name[item]):
                system.__dict__[device].__dict__[prop][item] **= value
    else:
        print('ALTER action <%s> is not defined', action)
def alter ( data , system ) : device = data [ 0 ] action = data [ 1 ] if data [ 2 ] == '*' : data [ 2 ] = '.*' regex = re . compile ( data [ 2 ] ) prop = data [ 3 ] value = float ( data [ 4 ] ) if action == 'MUL' : for item in range ( system . __dict__ [ device ] . n ) : if regex . search ( system . __dict__ [ device ] . name [ item ] ) : system . __dict__ [ device ] . __dict__ [ prop ] [ item ] *= value elif action == 'REP' : for item in range ( system . __dict__ [ device ] . n ) : if regex . search ( system . __dict__ [ device ] . name [ item ] ) : system . __dict__ [ device ] . __dict__ [ prop ] [ item ] = value elif action == 'DIV' : if not value : return for item in range ( system . __dict__ [ device ] . n ) : if regex . search ( system . __dict__ [ device ] . name [ item ] ) : system . __dict__ [ device ] . __dict__ [ prop ] [ item ] /= value elif action == 'SUM' : for item in range ( system . __dict__ [ device ] . n ) : if regex . search ( system . __dict__ [ device ] . name [ item ] ) : system . __dict__ [ device ] . __dict__ [ prop ] [ item ] += value elif action == 'SUB' : for item in range ( system . __dict__ [ device ] . n ) : if regex . search ( system . __dict__ [ device ] . name [ item ] ) : system . __dict__ [ device ] . __dict__ [ prop ] [ item ] -= value elif action == 'POW' : for item in range ( system . __dict__ [ device ] . n ) : if regex . search ( system . __dict__ [ device ] . name [ item ] ) : system . __dict__ [ device ] . __dict__ [ prop ] [ item ] **= value else : print ( 'ALTER action <%s> is not defined' , action )
Alter data in dm format devices