Я создаю сценарий Python для развертывания, сравнивая две папки (dev
, prodmirror
) для создания дельта-файлов, а затем сохраняю резервные копии существующих файлов и копирую в папку prodmirror
также ftp delta на сервер.
Ниже приведен код ..
Выпуск : def diff_dict (Dict_A, Dict_B) должен идентифицировать только AB, но также возвращать, если файл изменился в B (т.е. prodmirror), необходимонекоторая помощь / указатели здесь.
import os
import hashlib
srcdir = 'C:\dev'
tgtdir = 'C:\prodmirror'
# definition of function to retrieve MD5 using small chunks of file
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname,'rb') as f:
for chunk in iter(lambda: f.read(2 ** 20), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
# definition of function to find dictionaries difference,i.e present in A not in B
def difference_dict(Dict_A, Dict_B):
output_dict = {}
for key in Dict_A.keys():
if key not in Dict_B.keys():
output_dict[key] = Dict_A[key]
return output_dict
srcdict={}
for path, subdirs, files in os.walk(srcdir):
for filename in files:
f = os.path.join(path, filename)
srcdict[md5(f)]= f
print("SRC Dict :"+str(srcdict))
tgtdict={}
for path, subdirs, files in os.walk(tgtdir):
for filename in files:
f = os.path.join(path, filename)
tgtdict[md5(f)]= f
print("TGT Dict :"+str(tgtdict))
print("DIFF Dict :"+str(difference_dict(srcdict,tgtdict)))