Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- import glob
- import os
- import sys
- def md5(filename):
- """ return a hash of file """
- hash_md5 = hashlib.md5()
- with open(filename, "rb") as file:
- for ped in iter(lambda: file.read(4096), b""):
- hash_md5.update(ped)
- return hash_md5.hexdigest()
- def list_files():
- """ list files for compare after """
- mds = {}
- for f in glob.glob('*.sh'):
- mds[f] = md5(f)
- return mds
- def create_changelog():
- """ create a changelog, default filaname: AndroidStudio-0.1.sh, name, version and ext """
- with open('CHANGELOG', 'w') as log:
- for fname in glob.glob('*.sh'):
- log.write("{NAME}{VERSION}/{HASH}\n" .format(NAME=fname[:fname.find('-'):], VERSION=fname[fname.find('-')::], HASH=md5(fname)))
- def compare():
- """ compare md5 of files with changelog official :d """
- mds = list_files()
- if os.path.isfile('CHANGELOG'):
- with open('CHANGELOG') as log:
- lines = log.readlines()
- for l in lines:
- fname_current = l[:l.find('/'):]
- for key in mds:
- if key in fname_current:
- current_md5 = mds[key]
- if current_md5 in l[l.find('/')+1::]:
- return True
- else:
- return False
- else:
- sys.exit(0)
- compare()
Advertisement
Add Comment
Please, Sign In to add comment