Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import filecmp
- def file_list(dir):
- path_f = set()
- for d, dirs, files in os.walk(dir, True):
- for f in files:
- #path = os.path.join(d, f)
- path_f.add(f) #path
- return path_f
- def diff(file1, file2,fold,file_n):
- l1=len(open(file1, 'r').readlines())
- l2=len(open(file2, 'r').readlines())
- if l1 == l2:
- f1 = list(open(file1).readlines())
- f2 = list(open(file2).readlines())
- if filecmp.cmp(file1,file2) == True:
- pass
- else:
- newfile = open(name_dir+'\\reports\\diffs'+fold+file_n, 'w')
- for i in range(0, l1-1):
- if f1[i] == f2[i]:
- continue
- else:
- newfile.write("Номер строки " + str(i) + "\n")
- newfile.write('\nВ 2.3\n')
- newfile.write(f1[i])
- newfile.write('\nВ 3.0\n')
- newfile.write(f2[i])
- newfile.close()
- else:
- return True
- return False
- def check_inter_and_write(inter,fold):
- count=0
- for i in inter:
- print(count)
- count+=1
- file1 = name_dir + '\\2.3'+fold + i
- file2 = name_dir + '\\3.0\\'+fold + i
- if diff(file1,file2, fold,i) == True:
- total_analytics.write(i + ' ')
- #name_dir = 'C:\\Users\\ngorbunov\\Documents\\csv_comparator'
- name_dir = os.getcwd()
- f23_indic = file_list(name_dir+'\\2.3\\IndicatorsOutput')
- f23_strat = file_list(name_dir+'\\2.3\\StrategiesOutput')
- f30_indic = file_list(name_dir+'\\3.0\\IndicatorsOutput')
- f30_strat = file_list(name_dir+'\\3.0\\StrategiesOutput')
- if os.path.exists(name_dir+'\\reports\\diffs\\IndicatorsOutput') and os.path.exists(name_dir+'\\reports\\diffs\\StrategiesOutput'):
- pass
- else:
- os.makedirs(name_dir+'\\reports\\diffs\\IndicatorsOutput')
- os.makedirs(name_dir+'\\reports\\diffs\\StrategiesOutput')
- inter_indic = f23_indic & f30_indic
- inter_strat = f23_strat & f30_strat
- only_f23 = (f23_indic | f23_strat) - (f30_strat | f30_indic)
- only_f30 =(f30_strat | f30_indic) - (f23_indic | f23_strat)
- inter=len(inter_indic|inter_strat)
- print(inter)
- total_analytics = open(name_dir+'\\reports\\total_analytics.txt', 'w')
- total_analytics.write("Cписок файлов у которых совпадают названия и содержание:\n\n")
- fold1 = '\\IndicatorsOutput\\'
- check_inter_and_write(inter_indic, fold1)
- fold2 = '\\StrategiesOutput\\'
- check_inter_and_write(inter_strat, fold2)
- total_analytics.write("\n\nCписок файлов которые есть только в 2.3:\n\n")
- for i in only_f23:
- total_analytics.write(i+' ')
- total_analytics.write("\n\nCписок файлов которые есть только в 3.0:\n\n")
- for i in only_f30:
- total_analytics.write(i+' ')
- total_analytics.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement