blob: 8de756f6f2e3fcff0a88cec442f1726efdb007ad [file] [log] [blame]
zongqiang.zhang6d65ed02019-07-23 16:52:00 +08001#coding=utf-8
2#使用python做升级文件打包
3
4import hashlib
5import sys
6import zipfile
7from os import path
8import subprocess
9
10hashFileName = 'hash256.sign'
11
12
13def 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
28def 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
39if __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!')