File indexing completed on 2023-03-17 11:16:38
0001 from __future__ import print_function
0002
0003 from builtins import range
0004 class difference :
0005
0006 def __init__(self,v):
0007 self.verbose = v
0008 self._diffprocess=[]
0009 self._sameprocess=()
0010 def list_diff(self,aList1, aList2, string1, string2):
0011 "Searches for differences between two modules of the same kind"
0012 differences=[]
0013 for i in range(2,len(aList1)):
0014 for j in range(2,len(aList2)):
0015 if (i==j) and (aList1[i]!=aList2[j]):
0016 if aList1[i][:(aList1[i].index('=')+1)] == aList2[j][:(aList2[j].index('=')+1)]:
0017 if self.verbose==str(2) or self.verbose==str(1):
0018 str1 = aList1[i][2:aList1[i].index('=')+1] + aList1[i][aList1[i].index('=')+1:]+' ['+ string1+']'
0019 str2 = len(aList1[i][2:aList1[i].index('=')+1])*' '+aList2[j][aList2[j].index('=')+1:]+' ['+string2+']'
0020 print(str1,'\n',str2,'\n')
0021 differences.append(str1)
0022 differences.append(str2)
0023
0024 return differences
0025
0026 def module_diff(self,module1,module2, string1, string2):
0027 "Searches for modules which are in both the files but whose parameters are setted at different values"
0028 print('\nList of modules present in both the files with different parameter values\n')
0029 for i in module1.keys():
0030 for j in module2.keys():
0031 if (i==j) and (i=='Processing'):
0032 list= module1[i]
0033 for k in range(len(list)):
0034 process1=module1[i][k].split()
0035 process2=module2[i][k].split()
0036 if process1[0]!= process2[0]:
0037 key1=process1[0]
0038 key2=process2[0]
0039 self._diffprocess.append( (key1,key2) )
0040
0041 if len(self._diffprocess)>1:
0042 print('Differences in the processing history')
0043 for l,m in self._diffprocess:
0044 print(l+' ['+string1+']')
0045 print(m+' ['+string2+']')
0046 print('')
0047 if len(self._diffprocess)==1:
0048 self._sameprocess=self._diffprocess[0]
0049
0050 elif ( (i==j)or (i,j)==self._sameprocess ) and (i!='Processing'):
0051 for name1,value1 in module1[i]:
0052 for name2,value2 in module2[j]:
0053 if (name1==name2) and (value1[1:]!=value2[1:]):
0054 print('Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name1+'"'+'\n')
0055 d=difference(self.verbose)
0056 d.firstvalue=value1
0057 d.secondvalue=value2
0058 self.list_diff(d.firstvalue,d.secondvalue, string1, string2)
0059
0060 self.onefilemodules(module1,module2,'first')
0061 self.onefilemodules(module2,module1,'second')
0062
0063
0064 def onefilemodules(self,module1,module2,string):
0065 "Searches for modules present only in one of the two files"
0066 print('\nModules run only on the '+string+ ' edmfile:'+'\n')
0067 for i in module1.keys():
0068 labelList=[]
0069 if (i not in module2.keys())and (i not in self._sameprocess):
0070 print('\n Process '+i+' not run on edmfile '+string +'\n')
0071 elif i!='Processing':
0072 k=i
0073 if i in self._sameprocess:
0074 if i==self._sameprocess[0]:
0075 k= self._sameprocess[1]
0076 elif i==self._sameprocess[1]:
0077 k= self._sameprocess[0]
0078 labelList2=[module[0] for module in module2[k]]
0079 labelList1=[module[0] for module in module1[i]]
0080 for name, value in module1[i] :
0081 if (name not in labelList2):
0082 print('Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name+'"')
0083 if self.verbose==str(2):
0084 for k in value[1:]:
0085 print(k)
0086
0087
0088