123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import time
- logSdkMapping = {
- 'jrtt': 'com.jmhy.sdk.statistics.JrttStatistics',
- 'gdt': 'com.jmhy.sdk.statistics.GdtStatistics',
- 'ks': 'com.jmhy.sdk.statistics.KsStatistics',
- 'uc': 'com.jmhy.sdk.statistics.UcStatistics',
- 'bd': 'com.jmhy.sdk.statistics.BaiduStatistics'
- }
- def checkConfig(config):
- """
- 检查配置
- """
- print('check config ...')
- if type(config) == dict:
- return checkChannelConfig(config)
- elif type(config) == list:
- for itemConfig in config:
- if not checkChannelConfig(itemConfig):
- return False
- return True
- def checkChannelConfig(config):
- if 'name' not in config or 'packageName' not in config:
- print('name or packageName not exists in config')
- return False
- if 'subChannel' not in config:
- print('subChannel not exists in config')
- return False
- # 默认值
- if 'changeIcon' not in config:
- config['changeIcon'] = False
- if 'switchIcon' not in config:
- config['switchIcon'] = False
- if 'addLauncher' not in config:
- config['addLauncher'] = False
- if 'splitDex' not in config:
- config['splitDex'] = True
- if 'clearCache' not in config:
- config['clearCache'] = True
- if 'aapt2disable' not in config:
- config['aapt2disable'] = False
- if 'v2disable' not in config:
- config['v2disable'] = False
- if 'screenOrientation' not in config:
- config['screenOrientation'] = 'landscape'
- if 'outName' not in config:
- config['outName'] = config['name']
- if 'logSdk' in config:
- log = config['logSdk']
- setLog(config, log)
- return True
- def setLog(config, log_sdk):
- clazzList = []
- for log in log_sdk:
- if log in logSdkMapping:
- clazzList.append(logSdkMapping[log])
- configData = None
- if 'configData' in config:
- configData = config['configData']
- configData['jm_log_sdk'] = clazzList
- else:
- config['configData'] = {
- 'jm_log_sdk': clazzList
- }
- def replaceArgs(config):
- """
- 替换占位符
- """
- if type(config) == dict:
- replaceItemArgs(config)
- elif type(config) == list:
- # 遍历数组
- for arg in config:
- replaceItemArgs(arg)
- def replaceItemArgs(config):
- """
- 替换占位符
- """
- # 遍历字典
- for arg in config:
- if type(config[arg]) == dict:
- replaceArgs(config[arg])
- elif type(config[arg]) == str:
- replaceString(config, arg)
- def replaceString(config, arg):
- """
- 替换占位符
- """
- content = config[arg]
- if '${DATE}' in content:
- content = content.replace('${DATE}', getDate())
- config[arg] = content
- def getDate():
- """
- 获取日期
- """
- return time.strftime("%Y%m%d", time.localtime())
- def getTime(seconds):
- """
- 获取时间
- """
- time = int(seconds)
- if time < 60:
- return str(time) + '秒'
- else:
- return str(round(time / 60)) + '分' + str(time % 60) + '秒'
|