package_utils.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. # 安卓游戏打包脚本
  2. # 1.用apktool解包
  3. # 2.复制res资源、assets资源、jniLib资源
  4. # 3.修改包名、app名、渠道文件
  5. # 4.添加app icon、合并AndroidManifest文件
  6. # 5.添加app启动图,修改AndroidManifest文件
  7. # 6.生成新的R文件
  8. # 7.将新的R文件编译,生成dex,再用baksmali生成smali,替换旧的R文件
  9. # 8.将jar资源打包成dex,再用baksmali生成smali,拷贝到smali目录下
  10. # 9.统计方法量,并分割dex(将smali文件拷贝到目录smali_classes2)
  11. # 10.用apktool回包
  12. # 11.重新签名
  13. import file_utils
  14. import xml_utils
  15. import smali_utils
  16. import config_utils
  17. import game_utils
  18. import os
  19. import os.path
  20. import json
  21. import sys
  22. import importlib
  23. import uuid
  24. import zipfile
  25. ignoreLauncher = ['jm_ysdk', 'jm_yijie', 'jm_quick', 'jm_beiyu', 'jm_xq_jrtt']
  26. def pack(game, sdk, config):
  27. config['cache'] = uuid.uuid1()
  28. subChannel = config['subChannel']
  29. # 解包
  30. ret = decomplie(game, sdk, subChannel, config)
  31. if ret:
  32. return ret
  33. # 删除旧代码
  34. ret = removeOldCode(game, sdk, subChannel, config)
  35. if ret:
  36. return ret
  37. # 删除一些不支持的属性
  38. ret = removeNoSupportAttr(game, sdk, subChannel, config)
  39. if ret:
  40. return ret
  41. # 删除一些不支持的配置
  42. ret = fixUnSupportConfig(game, sdk, subChannel, config)
  43. if ret:
  44. return ret
  45. # 合并Drawable-v4目录
  46. ret = mergeDrawableRes(game, sdk, subChannel, config)
  47. if ret:
  48. return ret
  49. # 移除相同的资源
  50. ret = removeSameRes(game, sdk, subChannel, config)
  51. if ret:
  52. return ret
  53. # 复制res资源
  54. ret = copyRes(game, sdk, subChannel, config)
  55. if ret:
  56. return ret
  57. # 合并主文件
  58. ret = mergeManifestRes(game, sdk, subChannel, config)
  59. if ret:
  60. return ret
  61. # 替换占位符
  62. ret = changePlaceholders(game, sdk, subChannel, config)
  63. if ret:
  64. return ret
  65. # 添加meta-data
  66. ret = addMetaData(game, sdk, subChannel, config)
  67. if ret:
  68. return ret
  69. # 增加配置文件
  70. ret = addConfig(game, sdk, subChannel, config)
  71. if ret:
  72. return ret
  73. # 复制app res资源
  74. ret = copyAppRes(game, sdk, subChannel, config)
  75. if ret:
  76. return ret
  77. # 更改包名
  78. if 'packageName' in config and config['packageName'] != '':
  79. ret = changePackageName(game, sdk, subChannel, config)
  80. if ret:
  81. return ret
  82. # 更改app名
  83. if 'name' in config and config['name'] != '':
  84. ret = changeAppName(game, sdk, subChannel, config)
  85. if ret:
  86. return ret
  87. # 更改app icon
  88. if config['changeIcon']:
  89. ret = changeAppIcon(game, sdk, subChannel, config)
  90. if ret:
  91. return ret
  92. # 添加启动图操作
  93. if config['addLauncher']:
  94. ret = addLauncher(game, sdk, subChannel, config)
  95. if ret:
  96. return ret
  97. # 添加多图标
  98. #ret = addMoreIcon(game, sdk, subChannel, config)
  99. #if ret:
  100. # return ret
  101. # 打包lib依赖
  102. ret = packJar(game, sdk, subChannel, config)
  103. if ret:
  104. return ret
  105. # sdk脚本处理
  106. ret = doSDKPostScript(game, sdk, config)
  107. if ret:
  108. return ret
  109. # 乐变sdk的特殊处理
  110. ret = game_utils.sdkLebianChange(game, sdk, config)
  111. if ret:
  112. return ret
  113. # 游戏脚本处理
  114. ret = doGamePostScript(game, sdk, config)
  115. if ret:
  116. return ret
  117. # log sdk
  118. if 'logSdk' in config:
  119. for log in config['logSdk']:
  120. ret = addLogSdk(game, sdk, subChannel, config, log)
  121. if ret:
  122. return ret
  123. # 生成R文件
  124. '''ret = generateNewRFile(game, sdk, subChannel, config)
  125. if ret:
  126. return ret'''
  127. # 添加MultiDex支持
  128. if config['splitDex']:
  129. ret = splitDex(game, sdk, subChannel, config)
  130. if ret:
  131. return ret
  132. # 更改版本号
  133. ret = changeVersion(game, sdk, subChannel, config)
  134. if ret:
  135. return ret
  136. # 回编译
  137. ret = recomplie(game, sdk, subChannel, config)
  138. if ret:
  139. return ret
  140. # 对齐apk
  141. ret = alignApk(game, sdk, subChannel, config)
  142. if ret:
  143. return ret
  144. # 签名
  145. ret = apksignerApk(game, sdk, subChannel, config)
  146. if ret:
  147. return ret
  148. # 添加渠道信息
  149. ret = addChannel(game, sdk, subChannel, config)
  150. if ret:
  151. return ret
  152. # 清理产生的中间文件
  153. if config['clearCache']:
  154. clearTemp(game, sdk, subChannel, config)
  155. return 0
  156. def decomplie(game, sdk, subChannel, config):
  157. '''
  158. 解包
  159. '''
  160. apktoolPath = file_utils.getApkToolPath()
  161. gamePath = file_utils.getFullGameApk(game)
  162. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  163. if os.path.exists(decompliePath):
  164. print('delete decomplie folder...')
  165. file_utils.deleteFolder(decompliePath)
  166. print('decomplie apk...')
  167. return file_utils.execJarCmd(apktoolPath, 'd -f "%s" -o "%s"' % (gamePath, decompliePath))
  168. def removeOldCode(game, sdk, subChannel, config):
  169. '''
  170. 删除旧代码
  171. '''
  172. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  173. codePath = os.path.join(decompliePath, 'smali', 'com', 'jmhy', 'sdk')
  174. #file_utils.deleteFolder(codePath)
  175. allFiles = []
  176. allFiles = file_utils.list_files(codePath, allFiles)
  177. for f in allFiles:
  178. fpath, fname = os.path.split(f) #分离文件名和路径
  179. if fname == 'R.smali' or fname.startswith('R$'):
  180. continue
  181. os.remove(f)
  182. print('remove %s' % f)
  183. return 0
  184. def copyRes(game, sdk, subChannel, config):
  185. '''
  186. 复制res资源
  187. '''
  188. # 拷贝sdk资源
  189. print('copy res...')
  190. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  191. sdkPath = file_utils.getFullSDKPath(sdk)
  192. resPath = os.path.join(sdkPath, 'res')
  193. decomplieResPath = file_utils.getFullPath(decompliePath, 'res')
  194. for d in os.listdir(resPath):
  195. copyResWithType(resPath, decomplieResPath, d)
  196. # 拷贝assets
  197. print('copy assets...')
  198. assetsPath = file_utils.getFullPath(sdkPath, 'assets')
  199. decomplieAssetsPath = file_utils.getFullPath(decompliePath, 'assets')
  200. if os.path.exists(assetsPath):
  201. ret = file_utils.copyFileAllDir(assetsPath, decomplieAssetsPath)
  202. if ret:
  203. return ret
  204. # 拷贝jniLib
  205. print('copy jniLibs...')
  206. jniPath = file_utils.getFullPath(sdkPath, 'jniLibs')
  207. decomplieJniPath = file_utils.getFullPath(decompliePath, 'lib')
  208. abiFilters = []
  209. if os.path.exists(decomplieJniPath):
  210. for abi in os.listdir(decomplieJniPath):
  211. if abi == 'armeabi-v7a' or abi == 'armeabi':
  212. abiFilters.append(abi)
  213. else:
  214. abiFilters = ['armeabi-v7a']
  215. if os.path.exists(jniPath):
  216. ret = file_utils.copyFileAllDir(jniPath, decomplieJniPath, False, abiFilters)
  217. if ret:
  218. return ret
  219. return 0
  220. def mergeDrawableRes(game, sdk, subChannel, config):
  221. '''
  222. 合并Drawable-v4目录
  223. '''
  224. print('merge drawable path...')
  225. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  226. resPath = os.path.join(decompliePath, 'res')
  227. for path in os.listdir(resPath):
  228. print('res path %s' % path)
  229. if (path.startswith('drawable') or path.startswith('mipmap')) and path.endswith('-v4'):
  230. print('merge path %s' % path)
  231. v4DrawablePath = os.path.join(resPath, path)
  232. drawablePath = os.path.join(resPath, path[:-3])
  233. if os.path.exists(drawablePath):
  234. ret = file_utils.copyFileAllDir(v4DrawablePath, drawablePath, True)
  235. if ret:
  236. return ret
  237. else:
  238. os.rename(v4DrawablePath, drawablePath)
  239. return 0
  240. def removeSameRes(game, sdk, subChannel, config):
  241. '''
  242. 移除相同的资源
  243. '''
  244. # 读取sdk的资源
  245. print('remove same res...')
  246. sdkPath = file_utils.getFullSDKPath(sdk)
  247. sdkResPath = os.path.join(sdkPath, 'res')
  248. resList = []
  249. for path in os.listdir(sdkResPath):
  250. if not path.startswith('values'):
  251. continue
  252. absPath = os.path.join(sdkResPath, path)
  253. for resFile in os.listdir(absPath):
  254. '''if not resFile.startswith('jm_'):
  255. continue'''
  256. resList = xml_utils.readAllRes(os.path.join(absPath, resFile), resList)
  257. if len(resList) == 0:
  258. print('no same res found')
  259. return 0
  260. # 移除相同的资源
  261. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  262. resPath = os.path.join(decompliePath, 'res')
  263. for path in os.listdir(resPath):
  264. if not path.startswith('values'):
  265. continue
  266. absPath = os.path.join(resPath, path)
  267. for resFile in os.listdir(absPath):
  268. xml_utils.removeSameRes(os.path.join(absPath, resFile), resList)
  269. return 0
  270. def mergeManifestRes(game, sdk, subChannel, config):
  271. '''
  272. 合并主文件
  273. '''
  274. print('merge AndroidManifest...')
  275. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  276. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  277. sdkPath = file_utils.getFullSDKPath(sdk)
  278. libManifest = file_utils.getFullPath(sdkPath, 'manifest.xml')
  279. return xml_utils.mergeManifestRes(manifest, libManifest)
  280. def copyAppRes(game, sdk, subChannel, config):
  281. '''
  282. 拷贝app的资源,比如app icon、启动图等
  283. '''
  284. channelPath = file_utils.getSubChannelPath(game, sdk, subChannel)
  285. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  286. # assets
  287. print('copy assets...')
  288. assetsPath = file_utils.getFullPath(channelPath, 'assets')
  289. decomplieAssetsPath = file_utils.getFullPath(decompliePath, 'assets')
  290. if os.path.exists(assetsPath):
  291. ret = file_utils.copyFileAllDir(assetsPath, decomplieAssetsPath)
  292. if ret:
  293. return ret
  294. # icon
  295. print('copy icon...')
  296. ret = copyAppResWithType(decompliePath, channelPath, 'icon')
  297. if ret:
  298. return ret
  299. # 启动图
  300. print('copy splash...')
  301. ret = copyAppResWithType(decompliePath, channelPath, 'splash')
  302. if ret:
  303. return ret
  304. # 其他图片
  305. print('copy image...')
  306. ret = copyAppResWithType(decompliePath, channelPath, 'image')
  307. if ret:
  308. return ret
  309. return 0
  310. def copyAppResWithType(decompliePath, channelPath, typeName):
  311. decomplieResPath = os.path.join(decompliePath, 'res')
  312. iconPath = os.path.join(channelPath, typeName)
  313. if not os.path.exists(iconPath):
  314. print('dir "%s" not exists' % iconPath)
  315. return 0
  316. for d in os.listdir(iconPath):
  317. ret = copyResWithType(iconPath, decomplieResPath, d)
  318. if ret:
  319. return ret
  320. return 0
  321. def copyResWithType(resPath, decomplieResPath, typeName):
  322. # appt的打包目录会带-v4后缀
  323. resDir = os.path.join(resPath, typeName)
  324. target = os.path.join(decomplieResPath, typeName)
  325. targetV4 = os.path.join(decomplieResPath, typeName + '-v4')
  326. if not os.path.exists(target) and not os.path.exists(targetV4):
  327. os.makedirs(target)
  328. return file_utils.copyFileAllDir(resDir, target, False)
  329. elif not os.path.exists(target):
  330. return file_utils.copyFileAllDir(resDir, targetV4, False)
  331. else:
  332. return file_utils.copyFileAllDir(resDir, target, False)
  333. def removeNoSupportAttr(game, sdk, subChannel, config):
  334. '''
  335. 删除一些不支持的属性
  336. '''
  337. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  338. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  339. xml_utils.removeRootAttr(manifest, 'compileSdkVersion')
  340. xml_utils.removeRootAttr(manifest, 'compileSdkVersionCodename')
  341. return 0
  342. def fixUnSupportConfig(game, sdk, subChannel, config):
  343. '''
  344. 删除一些不支持的配置
  345. '''
  346. # 检查minSdkVersion
  347. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  348. yml = os.path.join(decompliePath, 'apktool.yml')
  349. minSdkVersion = 15
  350. file_utils.changeMinSdkVersion(yml, minSdkVersion)
  351. resPath = os.path.join(decompliePath, 'res')
  352. tag = '-v'
  353. for res in os.listdir(resPath):
  354. print('res = ' + res)
  355. if res.startswith('values') and tag in res:
  356. start = res.index(tag)
  357. version = res[start+len(tag):]
  358. if not version.isdigit():
  359. continue
  360. version = int(version)
  361. print('version = %d' % version)
  362. if version < minSdkVersion:
  363. unSopportPath = os.path.join(resPath, res)
  364. print('unSopportPath = ' + unSopportPath)
  365. file_utils.deleteFolder(unSopportPath)
  366. print('deleteFolder = ' + unSopportPath)
  367. return 0
  368. def changePackageName(game, sdk, subChannel, config):
  369. '''
  370. 更改包名
  371. '''
  372. # 全局替换AndroidManifest里面的包名
  373. newPackageName = config['packageName']
  374. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  375. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  376. packageName = xml_utils.getPackageName(manifest)
  377. xml_utils.changePackageName(manifest, newPackageName)
  378. print('change package name %s --> %s' % (packageName, newPackageName))
  379. return 0
  380. def changeAppName(game, sdk, subChannel, config):
  381. '''
  382. 更改app名
  383. '''
  384. # 生成string.xml文件
  385. name = config['name']
  386. resName = 'common_sdk_name'
  387. if 'outName' in config:
  388. resName = resName + '_' + config['outName']
  389. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  390. stringFile = os.path.join(decompliePath, 'res', 'values', 'sdk_strings_temp.xml')
  391. content = '<?xml version="1.0" encoding="utf-8"?><resources><string name="%s">%s</string></resources>' % (resName, name)
  392. file_utils.createFile(stringFile, content)
  393. # 修改主文件的app名的值
  394. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  395. xml_utils.changeAppName(manifest, '@string/%s' % resName)
  396. print('change app name %s' % name)
  397. return 0
  398. def changeAppIcon(game, sdk, subChannel, config):
  399. '''
  400. 更改app icon
  401. '''
  402. print('change app icon...')
  403. resName = 'common_sdk_icon'
  404. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  405. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  406. xml_utils.changeAppIcon(manifest, '@mipmap/%s' % resName)
  407. return 0
  408. def addMetaData(game, sdk, subChannel, config):
  409. '''
  410. 添加meta-data
  411. '''
  412. if 'metaData' not in config:
  413. return 0
  414. print('add meta-data...')
  415. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  416. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  417. xml_utils.addMetaData(manifest, config['metaData'])
  418. return 0
  419. def addConfig(game, sdk, subChannel, config):
  420. '''
  421. 添加config.json
  422. '''
  423. if 'configData' not in config:
  424. return 0
  425. print('add config.json...')
  426. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  427. configJson = os.path.join(decompliePath, 'assets', 'jmhy_config.json')
  428. jsonText = json.dumps(config['configData'], ensure_ascii=False)
  429. file_utils.createFile(configJson, jsonText)
  430. return 0
  431. def changePlaceholders(game, sdk, subChannel, config):
  432. '''
  433. 处理掉占位符
  434. '''
  435. if 'placeholders' not in config:
  436. return 0
  437. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  438. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  439. placeholders = config['placeholders']
  440. for placeholder in placeholders:
  441. oldText = '${%s}' % placeholder
  442. newText = placeholders[placeholder]
  443. print('change placeholder %s -> %s' % (oldText, newText))
  444. file_utils.replaceContent(manifest, oldText, newText)
  445. return 0
  446. def addLauncher(game, sdk, subChannel, config):
  447. '''
  448. 添加启动图
  449. '''
  450. # ysdk的特殊处理
  451. if sdk in ignoreLauncher:
  452. return 0
  453. channelPath = file_utils.getSubChannelPath(game, sdk, subChannel)
  454. splashPath = os.path.join(channelPath, 'splash')
  455. if len(os.listdir(splashPath)) == 0:
  456. print('dir splash is empty')
  457. return 0
  458. print('add launcher...')
  459. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  460. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  461. activity = xml_utils.getLauncherActivityName(manifest)
  462. if activity == 'com.jmhy.sdk.template.LauncherActivity':
  463. print('add launcher already exist...')
  464. return 1
  465. # 添加关联资源
  466. internalPath = file_utils.getFullInternalPath()
  467. ret = copyAppResWithType(decompliePath, internalPath, 'launcher_res')
  468. if ret:
  469. return ret
  470. # 拷贝代码
  471. print('copy launcher code...')
  472. codePath = os.path.join(internalPath, 'launcher_code', 'smali')
  473. smaliPath = file_utils.getFullPath(decompliePath, 'smali')
  474. ret = file_utils.copyFileAllDir(codePath, smaliPath)
  475. if ret:
  476. return ret
  477. # 修改主文件信息
  478. print('change launcher config...')
  479. orientation = xml_utils.getScreenOrientation(manifest)
  480. activity = xml_utils.removeLauncherActivity(manifest)
  481. xml_utils.addLauncherActivity(manifest, orientation, 'com.jmhy.sdk.template.LauncherActivity')
  482. # 修改跳转的
  483. launcherActivity = os.path.join(decompliePath, 'smali', 'com', 'jmhy', 'sdk', 'template', 'LauncherActivity.smali')
  484. file_utils.replaceContent(launcherActivity, '{class}', activity)
  485. print('change launcher %s to %s' % (activity, 'com.jmhy.sdk.template.LauncherActivity'))
  486. # config['oldLauncher'] = activity
  487. if 'launcherTime' in config:
  488. timeHex = formatHex(config['launcherTime'])
  489. file_utils.replaceContent(launcherActivity, '0x0BB8', timeHex)
  490. return 0
  491. def addMoreIcon(game, sdk, subChannel, config):
  492. '''
  493. 添加多个图标
  494. '''
  495. print('add more icon support...')
  496. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  497. icon = '@mipmap/common_sdk_icon'
  498. if not config['changeIcon']:
  499. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  500. icon = xml_utils.getApplicationAttr(manifest, 'icon')
  501. switchIcon = icon
  502. if config['switchIcon']:
  503. switchIcon = '@mipmap/common_sdk_icon2'
  504. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  505. return xml_utils.addMoreIcon(manifest, icon, switchIcon)
  506. def formatHex(millisecond):
  507. '''
  508. 将毫秒转为16进制,4位格式
  509. '''
  510. timeHex = str(hex(millisecond)).upper()
  511. timeHex = timeHex[2:]
  512. formatHex = ''
  513. if len(timeHex) == 3:
  514. formatHex = '0x0' + timeHex
  515. elif len(timeHex) == 4:
  516. formatHex = '0x' + timeHex
  517. else:
  518. formatHex = '0x0BB8'
  519. return formatHex
  520. def doSDKPostScript(game, sdk, config):
  521. '''
  522. 执行sdk相关特殊处理脚本
  523. '''
  524. sdkPath = file_utils.getFullSDKPath(sdk)
  525. scriptPath = os.path.join(sdkPath, 'script')
  526. targetScript = os.path.join(scriptPath, 'sdk_script.py')
  527. if not os.path.exists(targetScript):
  528. print('sdk_script no exists')
  529. return 0
  530. print('doSDKPostScript...')
  531. sys.path.append(scriptPath)
  532. module = importlib.import_module('sdk_script')
  533. ret = module.execute(game, sdk, config)
  534. sys.path.remove(scriptPath)
  535. return ret
  536. def doGamePostScript(game, sdk, config):
  537. '''
  538. 执行游戏相关特殊处理脚本
  539. '''
  540. channelPath = file_utils.getFullGamePath(game)
  541. scriptPath = os.path.join(channelPath, 'script')
  542. targetScript = os.path.join(scriptPath, 'game_script.py')
  543. if not os.path.exists(targetScript):
  544. print('game_script no exists')
  545. return 0
  546. print('doGamePostScript...')
  547. sys.path.append(scriptPath)
  548. module = importlib.import_module('game_script')
  549. ret = module.execute(game, sdk, config)
  550. sys.path.remove(scriptPath)
  551. return ret
  552. def addLogSdk(game, sdk, subChannel, config, logSdk):
  553. # 拷贝jniLibs
  554. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  555. sdkPath = file_utils.getFullLogSDKPath(logSdk)
  556. print('copy log jniLibs...')
  557. jniPath = file_utils.getFullPath(sdkPath, 'jniLibs')
  558. decomplieJniPath = file_utils.getFullPath(decompliePath, 'lib')
  559. abiFilters = []
  560. if os.path.exists(decomplieJniPath):
  561. for abi in os.listdir(decomplieJniPath):
  562. if abi == 'armeabi-v7a' or abi == 'armeabi':
  563. abiFilters.append(abi)
  564. else:
  565. abiFilters = ['armeabi-v7a']
  566. if os.path.exists(jniPath):
  567. ret = file_utils.copyFileAllDir(jniPath, decomplieJniPath, False, abiFilters)
  568. if ret:
  569. return ret
  570. print('merge log AndroidManifest...')
  571. libManifest = file_utils.getFullPath(sdkPath, 'manifest.xml')
  572. if os.path.exists(libManifest):
  573. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  574. ret = xml_utils.mergeManifestRes(manifest, libManifest)
  575. if ret:
  576. return ret
  577. return packLogJar(game, sdk, subChannel, config, logSdk)
  578. def generateNewRFile(game, sdk, subChannel, config):
  579. '''
  580. 生成新的R文件
  581. '''
  582. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  583. androidPlatforms = file_utils.getAndroidCompileToolPath()
  584. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  585. decomplieResPath = file_utils.getFullPath(decompliePath, 'res')
  586. compliePath = file_utils.getFullPath(decompliePath, 'gen')
  587. if not os.path.exists(compliePath):
  588. os.makedirs(compliePath)
  589. # 生成R文件
  590. print('create R.java ...')
  591. if config['aapt2disable']:
  592. aapt = file_utils.getAAPTPath()
  593. ret = file_utils.getExecPermission(aapt)
  594. if ret:
  595. return ret
  596. createRCmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (aapt, compliePath, decomplieResPath, androidPlatforms, manifest)
  597. ret = file_utils.execFormatCmd(createRCmd)
  598. if ret:
  599. return ret
  600. else:
  601. # compile
  602. aapt = file_utils.getAAPT2Path()
  603. ret = file_utils.getExecPermission(aapt)
  604. if ret:
  605. return ret
  606. print('compiled res ...')
  607. complieResPath = os.path.join(compliePath, 'compiled')
  608. complieResCmd = '"%s" compile --dir "%s" -o "%s"' % (aapt, decomplieResPath, complieResPath)
  609. file_utils.execFormatCmd(complieResCmd)
  610. # unzip
  611. print('unzip compiled res ...')
  612. unzipResPath = os.path.join(compliePath, 'aapt2_res')
  613. with zipfile.ZipFile(complieResPath) as zf:
  614. zf.extractall(unzipResPath)
  615. print('create unzip %s' % unzipResPath)
  616. # link
  617. print('link res ...')
  618. outApk = os.path.join(compliePath, 'res.apk')
  619. linkResCmd = '"%s" link -o "%s" -I "%s" --manifest "%s" --java "%s" --auto-add-overlay' % (aapt, outApk, androidPlatforms, manifest, compliePath)
  620. for filename in os.listdir(unzipResPath):
  621. linkResCmd += ' %s' % filename
  622. print('link cmd len is %s' % len(linkResCmd))
  623. ret = file_utils.execFormatCmd(linkResCmd, unzipResPath)
  624. if ret:
  625. return ret
  626. # 编译R文件
  627. print('complie R.java ...')
  628. packageName = xml_utils.getPackageName(manifest)
  629. packagePath = file_utils.getPackagePath(compliePath, packageName)
  630. RSourceFile = os.path.join(packagePath, 'R.java')
  631. complieRCmd = 'javac -source 1.8 -target 1.8 -encoding UTF-8 "%s"' % RSourceFile
  632. ret = file_utils.execFormatCmd(complieRCmd)
  633. if ret:
  634. return ret
  635. # 生成dex
  636. print('dex R.class ...')
  637. outDex = os.path.join(compliePath, 'classes.dex')
  638. if config['aapt2disable']:
  639. dx = file_utils.getDxPath()
  640. dexCmd = '--dex --no-warning --output="%s" "%s"' % (outDex, compliePath)
  641. else:
  642. dx = file_utils.getD8Path()
  643. clazz = os.path.join(packagePath, '*.class')
  644. dexCmd = '--lib "%s" --output "%s" %s' % (androidPlatforms, compliePath, clazz)
  645. ret = file_utils.execJarCmd(dx, dexCmd)
  646. if ret:
  647. return ret
  648. # 反向dex生成smali
  649. # 存放在out目录
  650. print('baksmali classes.dex ...')
  651. baksmaliPath = file_utils.getBaksmaliPath()
  652. outPath = file_utils.getFullPath(decompliePath, 'out')
  653. ret = file_utils.execJarCmd(baksmaliPath, 'd "%s" -o "%s"' % (outDex, outPath))
  654. if ret:
  655. return ret
  656. # 将生成的文件拷贝到目标目录
  657. print('copy R.smali ...')
  658. smaliPath = file_utils.getFullPath(decompliePath, 'smali')
  659. file_utils.copyFileAllDir(outPath, smaliPath)
  660. return 0
  661. def packJar(game, sdk, subChannel, config):
  662. '''
  663. 打包所有的jar
  664. '''
  665. splitDex = config['splitDex']
  666. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  667. outPath = file_utils.getFullPath(decompliePath, 'gen')
  668. if not os.path.exists(outPath):
  669. os.makedirs(outPath)
  670. if config['aapt2disable']:
  671. dx = file_utils.getDxPath()
  672. dexCmd = '--dex --multi-dex --no-warning --output="%s"' % outPath
  673. else:
  674. dx = file_utils.getD8Path()
  675. androidPlatforms = file_utils.getAndroidCompileToolPath()
  676. dexCmd = '--lib "%s" --output "%s"' % (androidPlatforms, outPath)
  677. # 找到所有lib依赖
  678. sdkPath = file_utils.getFullSDKPath(sdk)
  679. libs = os.path.join(sdkPath, 'libs')
  680. libConfig = os.path.join(libs, 'config.json')
  681. # 存在配置文件
  682. if os.path.exists(libConfig):
  683. jsonText = file_utils.readFile(libConfig)
  684. libConf = json.loads(jsonText)
  685. if 'libConfig' in config and config['libConfig'] in libConf:
  686. conf = config['libConfig']
  687. libList = libConf[conf]
  688. for jar in libList:
  689. dexCmd += ' ' + os.path.join(libs, jar)
  690. elif 'default' in libConf:
  691. libList = libConf['default']
  692. for jar in libList:
  693. dexCmd += ' ' + os.path.join(libs, jar)
  694. else:
  695. for jar in os.listdir(libs):
  696. if not jar.endswith('.jar'):
  697. continue
  698. dexCmd += ' ' + os.path.join(libs, jar)
  699. else:
  700. for jar in os.listdir(libs):
  701. if not jar.endswith('.jar'):
  702. continue
  703. dexCmd += ' ' + os.path.join(libs, jar)
  704. # multidex.jar
  705. if splitDex:
  706. dexCmd += ' ' + file_utils.getMultiDexPath()
  707. # sdk实现类
  708. print('packageing all jar ...')
  709. dexCmd += ' ' + os.path.join(sdkPath, '%s.jar' % sdk)
  710. ret = file_utils.execJarCmd(dx, dexCmd)
  711. if ret:
  712. return ret
  713. # 反向dex生成smali
  714. # 存放在out目录
  715. print('baksmali classes.dex ...')
  716. outDex = os.path.join(outPath, 'classes.dex')
  717. baksmaliPath = file_utils.getBaksmaliPath()
  718. outPath = file_utils.getFullPath(decompliePath, 'out')
  719. ret = file_utils.execJarCmd(baksmaliPath, 'd "%s" -o "%s"' % (outDex, outPath))
  720. if ret:
  721. return ret
  722. # 将生成的文件拷贝到目标目录
  723. print('copy all smali ...')
  724. smaliPath = file_utils.getFullPath(decompliePath, 'smali')
  725. ret = file_utils.copyFileAllDir(outPath, smaliPath, True)
  726. if ret:
  727. return ret
  728. return 0
  729. def packLogJar(game, sdk, subChannel, config, logSdk):
  730. '''
  731. 打包所有的jar
  732. '''
  733. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  734. outPath = file_utils.getFullPath(decompliePath, 'gen')
  735. if not os.path.exists(outPath):
  736. os.makedirs(outPath)
  737. if config['aapt2disable']:
  738. dx = file_utils.getDxPath()
  739. dexCmd = '--dex --multi-dex --no-warning --output="%s"' % outPath
  740. else:
  741. dx = file_utils.getD8Path()
  742. androidPlatforms = file_utils.getAndroidCompileToolPath()
  743. dexCmd = '--lib "%s" --output "%s"' % (androidPlatforms, outPath)
  744. # 找到所有lib依赖
  745. sdkPath = file_utils.getFullLogSDKPath(logSdk)
  746. libs = os.path.join(sdkPath, 'libs')
  747. libConfig = os.path.join(libs, 'config.json')
  748. # 存在配置文件
  749. if os.path.exists(libConfig):
  750. jsonText = file_utils.readFile(libConfig)
  751. libList = json.loads(jsonText)
  752. for jar in libList:
  753. if not jar.endswith('.jar'):
  754. continue
  755. dexCmd += ' ' + os.path.join(libs, jar)
  756. else:
  757. for jar in os.listdir(libs):
  758. if not jar.endswith('.jar'):
  759. continue
  760. dexCmd += ' ' + os.path.join(libs, jar)
  761. # sdk实现类
  762. print('packageing all log jar ...')
  763. dexCmd += ' ' + os.path.join(sdkPath, '%s.jar' % logSdk)
  764. ret = file_utils.execJarCmd(dx, dexCmd)
  765. if ret:
  766. return ret
  767. # 反向dex生成smali
  768. # 存放在out目录
  769. print('baksmali classes.dex ...')
  770. outDex = os.path.join(outPath, 'classes.dex')
  771. baksmaliPath = file_utils.getBaksmaliPath()
  772. outPath = file_utils.getFullPath(decompliePath, 'out')
  773. ret = file_utils.execJarCmd(baksmaliPath, 'd "%s" -o "%s"' % (outDex, outPath))
  774. if ret:
  775. return ret
  776. # 将生成的文件拷贝到目标目录
  777. print('copy all log smali ...')
  778. smaliPath = file_utils.getFullPath(decompliePath, 'smali')
  779. ret = file_utils.copyFileAllDir(outPath, smaliPath, True)
  780. if ret:
  781. return ret
  782. return 0
  783. def splitDex(game, sdk, subChannel, config):
  784. '''
  785. 分割dex
  786. '''
  787. # 判断是否已经存在application
  788. # 存在,则往原application添加内容
  789. # 不存在,则拷贝一个默认的android.support.multidex.MultiDexApplication
  790. print('add MultiDex support...')
  791. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  792. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  793. application = xml_utils.getApplicationAttr(manifest, 'name')
  794. if application is None:
  795. ret = xml_utils.changeApplicationAttr(manifest, 'name', 'android.support.multidex.MultiDexApplication')
  796. if ret:
  797. return ret
  798. else:
  799. smaliPath = os.path.join(decompliePath, 'smali')
  800. applicationFile = file_utils.getPackagePath(smaliPath, application)
  801. applicationFile += '.smali'
  802. ret = changeApplicationDex(applicationFile)
  803. if ret:
  804. return ret
  805. return splitSmali(game, sdk, subChannel, config, application)
  806. def changeApplicationDex(file):
  807. '''
  808. 修改application的smali文件,增加MultiDex操作
  809. '''
  810. index = file_utils.getApplicationSmaliIndex(file)
  811. file_utils.insertApplicationSmali(file, index)
  812. return 0
  813. def splitSmali(game, sdk, subChannel, config, application):
  814. '''
  815. 如果函数上限超过限制,自动拆分smali,以便生成多个dex文件
  816. '''
  817. print('splitSmali...')
  818. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  819. smaliPath = os.path.join(decompliePath, 'smali')
  820. appPackage = None
  821. if application:
  822. appPackage = application[:application.rfind('.')]
  823. appPackage = appPackage.replace('.', '/')
  824. allFiles = []
  825. allFiles = file_utils.list_files(smaliPath, allFiles)
  826. #print('file count is %d' % len(allFiles))
  827. #maxFuncNum = 65535
  828. # 留一点空间,防止计算误差
  829. maxFuncNum = 64000
  830. currFucNum = 0
  831. totalFucNum = 0
  832. currDexIndex = 1
  833. allRefs = []
  834. #保证Application等类在第一个classex.dex文件中
  835. for f in allFiles:
  836. f = f.replace('\\', '/')
  837. if (appPackage and appPackage in f) or '/android/support/multidex' in f:
  838. currFucNum += smali_utils.get_smali_method_count(f, allRefs)
  839. totalFucNum = currFucNum
  840. for f in allFiles:
  841. f = f.replace('\\', '/')
  842. if not f.endswith('.smali'):
  843. continue
  844. if (appPackage and appPackage in f) or '/android/support/multidex' in f:
  845. continue
  846. thisFucNum = smali_utils.get_smali_method_count(f, allRefs)
  847. totalFucNum += thisFucNum
  848. #print('%d # %d ==> %s' % (thisFucNum, currDexIndex, f))
  849. #print('totalFucNum is %d' % totalFucNum)
  850. if currFucNum + thisFucNum >= maxFuncNum:
  851. currFucNum = thisFucNum
  852. currDexIndex += 1
  853. newDexPath = os.path.join(decompliePath, 'smali_classes%d' % currDexIndex)
  854. os.makedirs(newDexPath)
  855. else:
  856. currFucNum += thisFucNum
  857. if currDexIndex > 1:
  858. newDexPath = os.path.join(decompliePath, 'smali_classes%d' % currDexIndex)
  859. targetFile = newDexPath + f[len(smaliPath):]
  860. file_utils.copyFile(f, targetFile, True)
  861. return 0
  862. def changeVersion(game, sdk, subChannel, config):
  863. '''
  864. 更改版本号
  865. '''
  866. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  867. yml = os.path.join(decompliePath, 'apktool.yml')
  868. versionCode = None
  869. versionName = None
  870. targetSdkVersion = None
  871. if 'versionCode' in config:
  872. versionCode = config['versionCode']
  873. if 'versionName' in config:
  874. versionName = config['versionName']
  875. if 'targetSdkVersion' in config:
  876. targetSdkVersion = config['targetSdkVersion']
  877. print('changeVersion versionCode=%s,versionName=%s,targetSdkVersion=%s' % (versionCode, versionName, targetSdkVersion))
  878. return file_utils.changeVersion(yml, versionCode, versionName, targetSdkVersion)
  879. def recomplie(game, sdk, subChannel, config):
  880. '''
  881. 回编译
  882. '''
  883. print('recomplie apk...')
  884. apktoolPath = file_utils.getApkToolPath()
  885. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  886. outApk = file_utils.getOutApkPath(game, sdk, subChannel, config['cache'])
  887. useAppt2 = ' --use-aapt2'
  888. if config['aapt2disable']:
  889. useAppt2 = ''
  890. return file_utils.execJarCmd(apktoolPath, 'b -f "%s" -o "%s"%s' % (decompliePath, outApk, useAppt2))
  891. def alignApk(game, sdk, subChannel, config):
  892. '''
  893. 对齐apk
  894. '''
  895. print('align apk...')
  896. outApk = file_utils.getOutApkPath(game, sdk, subChannel, config['cache'])
  897. alignApk = file_utils.getAlignApkPath(game, sdk, subChannel, config['cache'])
  898. alignapkTool = file_utils.getAlignPath()
  899. if os.path.exists(alignApk):
  900. os.remove(alignApk)
  901. ret = file_utils.getExecPermission(alignapkTool)
  902. if ret:
  903. return ret
  904. # zipalign.exe -v -p 4 input.apk output.apk
  905. return file_utils.execFormatCmd('"%s" -f -p 4 "%s" "%s"' % (alignapkTool, outApk, alignApk))
  906. def apksignerApk(game, sdk, subChannel, config):
  907. '''
  908. 签名apk
  909. '''
  910. print('sign apk...')
  911. path = os.path.join(file_utils.getCurrentPath(), 'keystore', 'key.json')
  912. jsonText = file_utils.readFile(path)
  913. signConfig = json.loads(jsonText)
  914. keystore = {}
  915. if game in signConfig:
  916. if sdk in signConfig[game] and subChannel in signConfig[game][sdk]:
  917. keystore = signConfig[game][sdk][subChannel]
  918. else:
  919. keystore = signConfig['default']
  920. else:
  921. keystore = signConfig['default']
  922. print('storeFile is "%s"' % keystore['storeFile'])
  923. apksigner = file_utils.getApksignerPath()
  924. alignApk = file_utils.getAlignApkPath(game, sdk, subChannel, config['cache'])
  925. signedApk = file_utils.getSignApkPath(game, sdk, subChannel, config['cache'])
  926. storeFile = os.path.join(file_utils.getCurrentPath(), 'keystore', keystore['storeFile'])
  927. if 'outName' in config and 'outPath' in config:
  928. if not os.path.exists(config['outPath']):
  929. os.makedirs(config['outPath'])
  930. signedApk = os.path.join(config['outPath'], config['outName'] + '.apk')
  931. elif 'outName' in config:
  932. signedApk = file_utils.getRenameApkPath(game, sdk, config['cache'], config['outName'])
  933. # java -jar apksigner.jar sign --ks key.jks --ks-key-alias releasekey --ks-pass pass:pp123456 --key-pass pass:pp123456 --out output.apk input.apk
  934. v2disable = ''
  935. if 'v2disable' in config and config['v2disable']:
  936. v2disable = ' --v2-signing-enabled=false'
  937. return file_utils.execJarCmd(apksigner, 'sign%s --ks "%s" --ks-key-alias %s --ks-pass pass:%s --key-pass pass:%s --out "%s" "%s"' % (v2disable, storeFile, keystore['keyAlias'], keystore['storePassword'], keystore['keyPassword'], signedApk, alignApk))
  938. def addChannel(game, sdk, subChannel, config):
  939. '''
  940. 添加渠道信息
  941. '''
  942. if 'v2disable' in config and config['v2disable']:
  943. return 0
  944. walle = file_utils.getWallePath()
  945. signedApk = file_utils.getSignApkPath(game, sdk, subChannel, config['cache'])
  946. if 'outName' in config and 'outPath' in config:
  947. signedApk = os.path.join(config['outPath'], config['outName'] + '.apk')
  948. elif 'outName' in config:
  949. signedApk = file_utils.getRenameApkPath(game, sdk, config['cache'], config['outName'])
  950. properties = config['properties']
  951. appid = ''
  952. appkey = ''
  953. host = ''
  954. if 'appid' in properties:
  955. appid = properties['appid']
  956. if 'appkey' in properties:
  957. appkey = properties['appkey']
  958. if 'host' in properties:
  959. host = properties['host']
  960. return file_utils.execJarCmd(walle, 'put -e version=%s,agent=%s,appid=%s,appkey=%s,host=%s "%s" "%s"' % (config_utils.getDate(), properties['agent'], appid, appkey, host, signedApk, signedApk))
  961. def clearTemp(game, sdk, subChannel, config):
  962. '''
  963. 清空中间产生的文件
  964. '''
  965. print('clear temp...')
  966. alignApk = file_utils.getAlignApkPath(game, sdk, subChannel, config['cache'])
  967. outApk = file_utils.getOutApkPath(game, sdk, subChannel, config['cache'])
  968. if os.path.exists(alignApk):
  969. os.remove(alignApk)
  970. if os.path.exists(outApk):
  971. os.remove(outApk)
  972. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  973. file_utils.deleteFolder(decompliePath)
  974. print('clear temp end')
  975. def packConsoleInput():
  976. '''
  977. 控制台打包
  978. '''
  979. if len(sys.argv) < 3:
  980. print('argument is missing')
  981. return 1
  982. # 校验参数
  983. game = sys.argv[1]
  984. sdk = sys.argv[2]
  985. # 可选参数,没有则默认打全部渠道
  986. subChannel = None
  987. if len(sys.argv) > 3:
  988. subChannel = sys.argv[3]
  989. return packConsole(game, sdk, subChannel)
  990. def packConsole(game, sdk, subChannel):
  991. '''
  992. 控制台打包
  993. '''
  994. if not os.path.exists(file_utils.getFullGameApk(game)):
  995. print('game "%s" not exists' % game)
  996. return 1
  997. if not os.path.exists(file_utils.getFullSDKPath(sdk)):
  998. print('sdk "%s" not exists' % sdk)
  999. return 1
  1000. # 读取配置
  1001. channelPath = file_utils.getChannelPath(game, sdk)
  1002. configPath = os.path.join(channelPath, 'config.json')
  1003. if not os.path.exists(configPath):
  1004. print('%s not exists' % configPath)
  1005. return 1
  1006. jsonText = file_utils.readFile(configPath)
  1007. config = json.loads(jsonText)
  1008. # 检查参数
  1009. if not config_utils.checkConfig(config):
  1010. return 1
  1011. # 处理参数
  1012. config_utils.replaceArgs(config)
  1013. successCount = 0
  1014. failureCount = 0
  1015. if type(config) == dict:
  1016. if subChannel is None or config['subChannel'] == subChannel:
  1017. ret = pack(game, sdk, config)
  1018. if ret:
  1019. failureCount += 1
  1020. else:
  1021. successCount += 1
  1022. else:
  1023. print('subChannel "%s" no found' % subChannel)
  1024. return 1
  1025. elif type(config) == list:
  1026. found = False
  1027. for itemConfig in config:
  1028. if subChannel is None or itemConfig['subChannel'] == subChannel:
  1029. found = True
  1030. ret = pack(game, sdk, itemConfig)
  1031. if ret:
  1032. failureCount += 1
  1033. else:
  1034. successCount += 1
  1035. if not found:
  1036. print('subChannel "%s" no found' % subChannel)
  1037. return 1
  1038. print('success %d, failure %d' % (successCount, failureCount))
  1039. return 0