config_utils_record.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import time
  2. def checkConfig(config):
  3. '''
  4. 检查配置
  5. '''
  6. print('check config ...')
  7. if type(config) == dict:
  8. return checkChannelConfig(config)
  9. elif type(config) == list:
  10. for itemConfig in config:
  11. if not checkChannelConfig(itemConfig):
  12. return False
  13. return True
  14. def checkChannelConfig(config):
  15. if 'name' not in config or 'packageName' not in config:
  16. print('name or packageName not exists in config')
  17. return False
  18. if 'subChannel' not in config:
  19. print('subChannel not exists in config')
  20. return False
  21. # 默认值
  22. if 'changeIcon' not in config:
  23. config['changeIcon'] = False
  24. if 'switchIcon' not in config:
  25. config['switchIcon'] = False
  26. if 'addLauncher' not in config:
  27. config['addLauncher'] = False
  28. if 'splitDex' not in config:
  29. config['splitDex'] = True
  30. if 'clearCache' not in config:
  31. config['clearCache'] = True
  32. if 'screenOrientation' not in config:
  33. config['screenOrientation'] = 'landscape'
  34. if 'outName' not in config:
  35. config['outName'] = config['name']
  36. return True
  37. def replaceArgs(config):
  38. '''
  39. 替换占位符
  40. '''
  41. if type(config) == dict:
  42. replaceItemArgs(config)
  43. elif type(config) == list:
  44. # 遍历数组
  45. for arg in config:
  46. replaceItemArgs(arg)
  47. def replaceItemArgs(config):
  48. '''
  49. 替换占位符
  50. '''
  51. # 遍历字典
  52. for arg in config:
  53. if type(config[arg]) == dict:
  54. replaceArgs(config[arg])
  55. elif type(config[arg]) == str:
  56. replaceString(config, arg)
  57. def replaceString(config, arg):
  58. '''
  59. 替换占位符
  60. '''
  61. content = config[arg]
  62. if '${DATE}' in content:
  63. content = content.replace('${DATE}', getDate())
  64. config[arg] = content
  65. def getDate():
  66. '''
  67. 获取日期
  68. '''
  69. return time.strftime("%Y%m%d", time.localtime())