zongqiang.zhang | 6d65ed0 | 2019-07-23 16:52:00 +0800 | [diff] [blame^] | 1 | #coding=utf-8 |
| 2 | #使用python做升级文件打包 |
| 3 | |
| 4 | import hashlib |
| 5 | import sys |
| 6 | import zipfile |
| 7 | from os import path |
| 8 | import subprocess |
| 9 | |
| 10 | hashFileName = 'hash256.sign' |
| 11 | |
| 12 | |
| 13 | def sha256_checknum(apk): |
| 14 | hash256 = hashlib.sha256() |
| 15 | srcFile = open(apk,'rb') |
| 16 | with srcFile as f: |
| 17 | for block in iter(lambda:f.read(4096),b''): |
| 18 | hash256.update(block); |
| 19 | srcFile.close() |
| 20 | hash256.update(b'nzoqPYMIu91VViA/mEIG5FtJXi8=') |
| 21 | |
| 22 | hashFile = path.dirname(apk)+'/'+hashFileName |
| 23 | print('hashFile = '+hashFile) |
| 24 | destFile = open(hashFile,'w+') |
| 25 | destFile.write(hash256.hexdigest()) |
| 26 | destFile.close() |
| 27 | |
| 28 | def zip_file(apk): |
| 29 | fileDir = path.dirname(apk) |
| 30 | version = subprocess.check_output(['git', 'describe', '--abbrev=4','--dirty','--always','--tags']).strip().decode('utf-8') |
| 31 | zipFile = fileDir+'/posa711'+'-'+version+'.zip' |
| 32 | print('zipFile = '+zipFile) |
| 33 | |
| 34 | zf = zipfile.ZipFile(zipFile,'w',zipfile.ZIP_DEFLATED) |
| 35 | zf.write(fileDir+'/'+hashFileName,hashFileName) |
| 36 | zf.write(apk,'posa711.apk') |
| 37 | zf.close() |
| 38 | |
| 39 | if __name__ == '__main__': |
| 40 | appFile = './app/release/app-release.apk' |
| 41 | print('appFile = ' + appFile) |
| 42 | |
| 43 | if not path.exists(appFile): |
| 44 | print(appFile +' is not exist') |
| 45 | exit() |
| 46 | sha256_checknum(appFile) |
| 47 | zip_file(appFile) |
| 48 | print('build upgrade zip success!') |