|
| 1 | +# -*- coding: utf-8 -* |
| 2 | + |
| 3 | +import zipfile |
| 4 | +import datetime |
| 5 | +from shutil import copyfile |
| 6 | +import sys |
| 7 | +import os |
| 8 | +import os.path |
| 9 | + |
| 10 | +emptyfile = 'empty' |
| 11 | +open(emptyfile, 'a').close() |
| 12 | +if(len(sys.argv) < 2): |
| 13 | + raise ValueError('You must input one apk') |
| 14 | +originApk = sys.argv[1] |
| 15 | +if not os.path.isfile(originApk): |
| 16 | + raise ValueError('You must input one existing apk') |
| 17 | + |
| 18 | +print 'now generate muti-channal apks for', originApk |
| 19 | + |
| 20 | +beginTime = datetime.datetime.now() |
| 21 | + |
| 22 | +# 渠道名,按需求定义 |
| 23 | +channles = [ |
| 24 | +1,2,3,4,5,6,7,8,9,10, |
| 25 | +11,12,13,14,15,16,17,18,19,20, |
| 26 | +21,22,23,24,25,26,27,28,29,30, |
| 27 | +31,32,33,34,35,36,37,38,39,40, |
| 28 | +41,42,43,44,45,46,47,48,49,50 |
| 29 | +] |
| 30 | + |
| 31 | +for name in channles: |
| 32 | + index = originApk.find('.apk') |
| 33 | + channelX = originApk[:index] + '_' + str(name) + originApk[index:] |
| 34 | + copyfile(originApk, channelX) |
| 35 | + zipped = zipfile.ZipFile(channelX, 'a', zipfile.ZIP_DEFLATED) |
| 36 | + empty_channel_file = "META-INF/channel_{channel}".format(channel=name) |
| 37 | + zipped.write(emptyfile, empty_channel_file) |
| 38 | + print 'Generating ', channelX |
| 39 | + |
| 40 | +print 'Generated channel count ', len(channles) |
| 41 | +print 'Total used time ', datetime.datetime.now() - beginTime |
0 commit comments