config_utils.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import time
  2. logSdkMapping = {
  3. 'jrtt':'com.jmhy.sdk.statistics.JrttStatistics',
  4. 'gdt':'com.jmhy.sdk.statistics.GdtStatistics',
  5. 'ks':'com.jmhy.sdk.statistics.KsStatistics',
  6. 'uc':'com.jmhy.sdk.statistics.UcStatistics',
  7. 'bd':'com.jmhy.sdk.statistics.BaiduStatistics'
  8. }
  9. def checkConfig(config):
  10. '''
  11. 检查配置
  12. '''
  13. print('check config ...')
  14. if type(config) == dict:
  15. return checkChannelConfig(config)
  16. elif type(config) == list:
  17. for itemConfig in config:
  18. if not checkChannelConfig(itemConfig):
  19. return False
  20. return True
  21. def checkChannelConfig(config):
  22. if 'name' not in config or 'packageName' not in config:
  23. print('name or packageName not exists in config')
  24. return False
  25. if 'subChannel' not in config:
  26. print('subChannel not exists in config')
  27. return False
  28. # 默认值
  29. if 'changeIcon' not in config:
  30. config['changeIcon'] = False
  31. if 'switchIcon' not in config:
  32. config['switchIcon'] = False
  33. if 'addLauncher' not in config:
  34. config['addLauncher'] = False
  35. if 'splitDex' not in config:
  36. config['splitDex'] = True
  37. if 'clearCache' not in config:
  38. config['clearCache'] = True
  39. if 'aapt2disable' not in config:
  40. config['aapt2disable'] = False
  41. if 'v2disable' not in config:
  42. config['v2disable'] = False
  43. if 'screenOrientation' not in config:
  44. config['screenOrientation'] = 'landscape'
  45. if 'outName' not in config:
  46. config['outName'] = config['name']
  47. if 'logSdk' in config:
  48. log = config['logSdk']
  49. setLog(config, log)
  50. return True
  51. def setLog(config, logSdk):
  52. clazzList = []
  53. for log in logSdk:
  54. if log in logSdkMapping:
  55. clazzList.append(logSdkMapping[log])
  56. configData = None
  57. if 'configData' in config:
  58. configData = config['configData']
  59. configData['jm_log_sdk'] = clazzList
  60. else:
  61. config['configData'] = {
  62. 'jm_log_sdk':clazzList
  63. }
  64. def replaceArgs(config):
  65. '''
  66. 替换占位符
  67. '''
  68. if type(config) == dict:
  69. replaceItemArgs(config)
  70. elif type(config) == list:
  71. # 遍历数组
  72. for arg in config:
  73. replaceItemArgs(arg)
  74. def replaceItemArgs(config):
  75. '''
  76. 替换占位符
  77. '''
  78. # 遍历字典
  79. for arg in config:
  80. if type(config[arg]) == dict:
  81. replaceArgs(config[arg])
  82. elif type(config[arg]) == str:
  83. replaceString(config, arg)
  84. def replaceString(config, arg):
  85. '''
  86. 替换占位符
  87. '''
  88. content = config[arg]
  89. if '${DATE}' in content:
  90. content = content.replace('${DATE}', getDate())
  91. config[arg] = content
  92. def getDate():
  93. '''
  94. 获取日期
  95. '''
  96. return time.strftime("%Y%m%d", time.localtime())
  97. def getTime(seconds):
  98. '''
  99. 获取时间
  100. '''
  101. time = int(seconds)
  102. if time < 60:
  103. return str(time) + '秒'
  104. else:
  105. return str(round(time/60)) + '分' + str(time%60) + '秒'