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') |
zongqiang.zhang | bfb9c89 | 2019-08-02 14:35:32 +0800 | [diff] [blame] | 31 | zipFile = fileDir+'/posa711dali'+'-'+version+'.zip' |
zongqiang.zhang | 6d65ed0 | 2019-07-23 16:52:00 +0800 | [diff] [blame] | 32 | print('zipFile = '+zipFile) |
| 33 | |
| 34 | zf = zipfile.ZipFile(zipFile,'w',zipfile.ZIP_DEFLATED) |
| 35 | zf.write(fileDir+'/'+hashFileName,hashFileName) |
zongqiang.zhang | be7b25d | 2019-08-02 15:01:19 +0800 | [diff] [blame] | 36 | zf.write(apk,'posa711dali.apk') |
zongqiang.zhang | 6d65ed0 | 2019-07-23 16:52:00 +0800 | [diff] [blame] | 37 | zf.close() |
| 38 | |
| 39 | if __name__ == '__main__': |
zongqiang.zhang | 1fd1534 | 2019-09-16 09:53:26 +0800 | [diff] [blame^] | 40 | if len(sys.argv) < 2: |
| 41 | print('miss parameter:app path!!!') |
| 42 | exit(1) |
| 43 | appFile = sys.argv[1] |
zongqiang.zhang | 6d65ed0 | 2019-07-23 16:52:00 +0800 | [diff] [blame] | 44 | print('appFile = ' + appFile) |
| 45 | |
| 46 | if not path.exists(appFile): |
| 47 | print(appFile +' is not exist') |
| 48 | exit() |
| 49 | sha256_checknum(appFile) |
| 50 | zip_file(appFile) |
| 51 | print('build upgrade zip success!') |