blob: 957fed95f5cff4ded6a747594a89304fe2c835e8 [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')
zongqiang.zhangbfb9c892019-08-02 14:35:32 +080031 zipFile = fileDir+'/posa711dali'+'-'+version+'.zip'
zongqiang.zhang6d65ed02019-07-23 16:52:00 +080032 print('zipFile = '+zipFile)
33
34 zf = zipfile.ZipFile(zipFile,'w',zipfile.ZIP_DEFLATED)
35 zf.write(fileDir+'/'+hashFileName,hashFileName)
zongqiang.zhangbe7b25d2019-08-02 15:01:19 +080036 zf.write(apk,'posa711dali.apk')
zongqiang.zhang6d65ed02019-07-23 16:52:00 +080037 zf.close()
38
39if __name__ == '__main__':
zongqiang.zhang1fd15342019-09-16 09:53:26 +080040 if len(sys.argv) < 2:
41 print('miss parameter:app path!!!')
42 exit(1)
43 appFile = sys.argv[1]
zongqiang.zhang6d65ed02019-07-23 16:52:00 +080044 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!')