| #coding=utf-8 |
| #使用python做升级文件打包 |
| |
| import hashlib |
| import sys |
| import zipfile |
| from os import path |
| import subprocess |
| |
| hashFileName = 'hash256.sign' |
| |
| |
| def sha256_checknum(apk): |
| hash256 = hashlib.sha256() |
| srcFile = open(apk,'rb') |
| with srcFile as f: |
| for block in iter(lambda:f.read(4096),b''): |
| hash256.update(block); |
| srcFile.close() |
| hash256.update(b'nzoqPYMIu91VViA/mEIG5FtJXi8=') |
| |
| hashFile = path.dirname(apk)+'/'+hashFileName |
| print('hashFile = '+hashFile) |
| destFile = open(hashFile,'w+') |
| destFile.write(hash256.hexdigest()) |
| destFile.close() |
| |
| def zip_file(apk): |
| fileDir = path.dirname(apk) |
| version = subprocess.check_output(['git', 'describe', '--abbrev=4','--dirty','--always','--tags']).strip().decode('utf-8') |
| zipFile = fileDir+'/posa711dali'+'-'+version+'.zip' |
| print('zipFile = '+zipFile) |
| |
| zf = zipfile.ZipFile(zipFile,'w',zipfile.ZIP_DEFLATED) |
| zf.write(fileDir+'/'+hashFileName,hashFileName) |
| zf.write(apk,'posa711dali.apk') |
| zf.close() |
| |
| if __name__ == '__main__': |
| if len(sys.argv) < 2: |
| print('miss parameter:app path!!!') |
| exit(1) |
| appFile = sys.argv[1] |
| print('appFile = ' + appFile) |
| |
| if not path.exists(appFile): |
| print(appFile +' is not exist') |
| exit() |
| sha256_checknum(appFile) |
| zip_file(appFile) |
| print('build upgrade zip success!') |