package_channel_douyou.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import file_utils
  2. import config_utils
  3. import sys
  4. import os.path
  5. import json
  6. def packageChannel():
  7. if len(sys.argv) < 2:
  8. print('argument is missing')
  9. return 1
  10. channelConfig = sys.argv[1]
  11. jsonText = file_utils.readFile(channelConfig)
  12. config = json.loads(jsonText)
  13. print('*************config*****************')
  14. print(jsonText)
  15. print('************************************')
  16. # 检查配置
  17. if not checkConfig(config):
  18. return 1
  19. # 检查文件
  20. gameApk = config['package']
  21. if not os.path.exists(gameApk):
  22. print('%s not exists' % gameApk)
  23. return 1
  24. if supportSignV2(gameApk):
  25. packageChannelV2(gameApk, config)
  26. return 0
  27. else:
  28. print('apk not support Signature Scheme v2' % gameApk)
  29. return 1
  30. def supportSignV2(gameApk):
  31. '''
  32. 验证是否APK Signature Scheme v2
  33. '''
  34. apksigner = file_utils.getApksignerPath()
  35. ret = getJavaResult(apksigner, 'verify --verbose "%s"' % gameApk)
  36. if '(APK Signature Scheme v2): true' in ret:
  37. return True
  38. return False
  39. def packageChannelV2(gameApk, config):
  40. print('add channel package ...')
  41. walle = file_utils.getWallePath()
  42. if not os.path.exists(config['outPath']):
  43. os.makedirs(config['outPath'])
  44. successCount = 0
  45. failureCount = 0
  46. channels = config['channel']
  47. for channel in channels:
  48. print('add channel package %s --> %s...' % (channel['agent'], channel['outName']))
  49. signedApk = os.path.join(config['outPath'], channel['outName'] + '.apk')
  50. ret = file_utils.execJarCmd(walle, 'put -c %s "%s" "%s"' % (channel['agent'], gameApk, signedApk))
  51. if ret:
  52. failureCount += 1
  53. else:
  54. successCount += 1
  55. print('success %d, failure %d' % (successCount, failureCount))
  56. def checkConfig(config):
  57. if 'package' not in config:
  58. print('package not exists in config')
  59. return False
  60. if 'outPath' not in config:
  61. print('outPath not exists in config')
  62. return False
  63. if 'channel' not in config:
  64. print('channel not exists in config')
  65. return False
  66. return True
  67. def getJavaResult(jar, cmd):
  68. return getCmdResult('java -jar "%s" %s' % (jar, cmd))
  69. def getCmdResult(cmd):
  70. p = os.popen(cmd)
  71. content = p.read()
  72. return content
  73. packageChannel()