sdk_script.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import file_utils
  2. import common_utils
  3. import xml_utils
  4. import os.path
  5. import xml.etree.ElementTree as ET
  6. import zipfile
  7. namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
  8. encoding = 'UTF-8'
  9. def execute(game, sdk, config):
  10. if not checkConfig(config):
  11. return 1
  12. subChannel = config['subChannel']
  13. createJmhyProperties(game, sdk, subChannel, config)
  14. common_utils.changeApplication(game, sdk, subChannel, config, 'com.tygame.tianyu.TYApplication')
  15. changePlaceholders(game, sdk, subChannel, config)
  16. return 0
  17. def checkConfig(config):
  18. '''
  19. 检查配置
  20. '''
  21. if 'properties' not in config:
  22. print('properties not exists in config')
  23. return False
  24. properties = config['properties']
  25. if 'agent' not in properties or 'version' not in properties:
  26. print('agent or version not exists in properties')
  27. return False
  28. return True
  29. def createJmhyProperties(game, sdk, subChannel, config):
  30. '''
  31. 创建jmhy.properties
  32. '''
  33. print('create jmhy.properties')
  34. propValue = config['properties']
  35. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  36. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  37. content = ''
  38. for key in propValue:
  39. content = '%s%s=%s\n' % (content, key, propValue[key])
  40. file_utils.createFile(properties, content)
  41. return 0
  42. def changePlaceholders(game, sdk, subChannel, config):
  43. '''
  44. 处理掉占位符
  45. '''
  46. if 'placeholders' not in config:
  47. return 0
  48. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  49. json = os.path.join(decompliePath, 'assets','tycollect.json')
  50. placeholders = config['placeholders']
  51. for placeholder in placeholders:
  52. oldText = '${%s}' % placeholder
  53. newText = placeholders[placeholder]
  54. print('change placeholder %s -> %s' % (oldText, newText))
  55. file_utils.replaceContent(json, oldText, newText)
  56. return 0