diffingerprints.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. import sys
  3. import re
  4. def computeUniqueFingerprints(fingerprints):
  5. i = 0
  6. uniqueFingerprints = list()
  7. while i < len(fingerprints):
  8. fingerprint = fingerprints[i]
  9. j = i
  10. while (j < len(fingerprints)) and (fingerprint == fingerprints[j]):
  11. j = j + 1
  12. uniqueFingerprints.append([j-1, fingerprint])
  13. i = j
  14. return uniqueFingerprints
  15. def readFingerprints1(eventlogFile):
  16. "RegExp version"
  17. regExp = re.compile("^E # (\d+) t .+ m \d+ ce \d+ msg \d+ f ([0-z]{4}-[0-z]{4})")
  18. fingerprints = list()
  19. for line in eventlogFile:
  20. match = regExp.match(line)
  21. if match:
  22. fingerprint = match.group(2)
  23. fingerprints.append(fingerprint)
  24. return fingerprints
  25. def isNewEvent(line):
  26. return len(line) >= 4 and line[0:4] == "E # "
  27. def getFingerprint(line):
  28. n = len(line) - 1
  29. return line[(n-14):(n-5)]
  30. def readFingerprints2(eventlogFile):
  31. fingerprints = list()
  32. eventlogFile.readline() # skip the first line
  33. for line in eventlogFile:
  34. if isNewEvent(line):
  35. fingerprint = getFingerprint(line)
  36. fingerprints.append(fingerprint)
  37. return fingerprints
  38. def diffingerprint(elog1Fingerprints, elog2Fingerprints):
  39. minSize = min(len(elog1Fingerprints), len(elog2Fingerprints)) - 1
  40. for i in range(0,minSize):
  41. elog1Fingerprint = elog1Fingerprints[i]
  42. elog2Fingerprint = elog2Fingerprints[i]
  43. if elog1Fingerprint[1] != elog2Fingerprint[1]:
  44. return "Diff elog1: " + str(elog1Fingerprint[0]) + " fingerprint = " + elog1Fingerprint[1] + ", elog2: " + str(elog2Fingerprint[0]) + " fingerprint = " + elog2Fingerprint[1]
  45. return "No differences"
  46. elog1FilePath = sys.argv[1]
  47. elog2FilePath = sys.argv[2]
  48. elog1File = open(elog1FilePath)
  49. elog2File = open(elog2FilePath)
  50. uniqueElog1Fingerprints = computeUniqueFingerprints(readFingerprints1(elog1File))
  51. uniqueElog2Fingerprints = computeUniqueFingerprints(readFingerprints1(elog2File))
  52. print(diffingerprint(uniqueElog1Fingerprints, uniqueElog2Fingerprints))
  53. elog1File.close()
  54. elog2File.close()