@@ -0,0 +1,1349 @@
+import re%0A%0Adef alarm_adjust(alarms):%0A    relations = %5B%5D%0A    f = open('alarm.txt')%0A    line = f.readline().strip('%5Cn')%0A    while line:%0A        conditions,relation = line.split(':')%0A        if alarm_match(conditions, alarms):%0A            relations.append(relation)%0A            #alarms = replace_alarms(relation, alarms)%0A        line = f.readline().strip('%5Cn')%0A    f.close()%0A    %0A    for relation in relations:%0A        alarms = replace_alarms(relation, alarms)%0A    %0A    return alarms%0A    %0Adef replace_alarms(relation, alarms):%0A    alarms = ',' + alarms + ','%0A    name = relation.split('=')%5B0%5D%0A    relation_with_comma = ',' + relation + ','%0A    if re.search(',%25s=%5Cd,'%25name, alarms):%0A        return re.sub(',%25s=%5Cd,'%25name, relation_with_comma, alarms)%5B1:-1%5D%0A    else: return alarms%5B1:len(alarms)%5D + relation%0A    %0Adef alarm_match(conditions, alarms):%0A    alarms = ',' + alarms + ','%0A    cons = conditions.split(',')%0A    for condition in cons:%0A        condition = ',' + condition + ','%0A        if -1 == alarms.find(condition):return False%0A    return True%0A    %0Aif __name__ == '__main__':%0A    assert('loflom=0,ais=1,lck=0,tim=0,bbe=0,bdi=0,aais=1,abdi=1,arei=1' == alarm_adjust('loflom=0,ais=1,lck=0,tim=1,bbe=1,bdi=0'))%0A    assert('loflom=0,ais=1,lck=0,tim=0,bbe=0,bdi=0,aais=1,abdi=1' == alarm_adjust('loflom=0,ais=1,lck=0,tim=1,bbe=1,bdi=1'))%0A            %0A

Create alarm.py