Advertisement
TShiva

анализатор ебаный

Jul 19th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | None | 0 0
  1. import os
  2. import filecmp
  3.  
  4. def file_list(dir):
  5.     path_f = set()
  6.     for d, dirs, files in os.walk(dir, True):
  7.         for f in files:
  8.             #path = os.path.join(d, f)
  9.             path_f.add(f) #path
  10.     return path_f
  11.  
  12.  
  13.  
  14. def diff(file1, file2,fold,file_n):
  15.     l1=len(open(file1, 'r').readlines())
  16.     l2=len(open(file2, 'r').readlines())
  17.  
  18.     if l1 == l2:
  19.         f1 = list(open(file1).readlines())
  20.         f2 = list(open(file2).readlines())
  21.         if filecmp.cmp(file1,file2) == True:
  22.             pass
  23.         else:
  24.             newfile = open(name_dir+'\\reports\\diffs'+fold+file_n, 'w')
  25.             for i in range(0, l1-1):
  26.                 if f1[i] == f2[i]:
  27.                     continue
  28.                 else:
  29.                     newfile.write("Номер строки " + str(i) + "\n")
  30.                     newfile.write('\nВ 2.3\n')
  31.                     newfile.write(f1[i])
  32.                     newfile.write('\nВ 3.0\n')
  33.                     newfile.write(f2[i])
  34.             newfile.close()
  35.     else:
  36.         return True
  37.     return False
  38.  
  39.  
  40. def check_inter_and_write(inter,fold):
  41.     count=0
  42.     for i in inter:
  43.         print(count)
  44.         count+=1
  45.         file1 = name_dir + '\\2.3'+fold + i
  46.         file2 = name_dir + '\\3.0\\'+fold + i
  47.         if diff(file1,file2, fold,i) == True:
  48.             total_analytics.write(i + ' ')
  49.  
  50. #name_dir = 'C:\\Users\\ngorbunov\\Documents\\csv_comparator'
  51. name_dir = os.getcwd()
  52. f23_indic = file_list(name_dir+'\\2.3\\IndicatorsOutput')
  53. f23_strat = file_list(name_dir+'\\2.3\\StrategiesOutput')
  54. f30_indic = file_list(name_dir+'\\3.0\\IndicatorsOutput')
  55. f30_strat = file_list(name_dir+'\\3.0\\StrategiesOutput')
  56.  
  57. if os.path.exists(name_dir+'\\reports\\diffs\\IndicatorsOutput') and os.path.exists(name_dir+'\\reports\\diffs\\StrategiesOutput'):
  58.     pass
  59. else:
  60.     os.makedirs(name_dir+'\\reports\\diffs\\IndicatorsOutput')
  61.     os.makedirs(name_dir+'\\reports\\diffs\\StrategiesOutput')
  62.  
  63.  
  64. inter_indic = f23_indic & f30_indic
  65. inter_strat = f23_strat & f30_strat
  66. only_f23 = (f23_indic | f23_strat) - (f30_strat | f30_indic)
  67. only_f30 =(f30_strat | f30_indic) - (f23_indic | f23_strat)
  68. inter=len(inter_indic|inter_strat)
  69. print(inter)
  70. total_analytics = open(name_dir+'\\reports\\total_analytics.txt', 'w')
  71. total_analytics.write("Cписок файлов у которых совпадают названия и содержание:\n\n")
  72.  
  73. fold1 = '\\IndicatorsOutput\\'
  74. check_inter_and_write(inter_indic, fold1)
  75. fold2 = '\\StrategiesOutput\\'
  76. check_inter_and_write(inter_strat, fold2)
  77.  
  78.  
  79. total_analytics.write("\n\nCписок файлов которые есть только в 2.3:\n\n")
  80. for i in only_f23:
  81.     total_analytics.write(i+' ')
  82. total_analytics.write("\n\nCписок файлов которые есть только в 3.0:\n\n")
  83. for i in only_f30:
  84.     total_analytics.write(i+' ')
  85.  
  86. total_analytics.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement