config_utils_record.py 2.0 KB

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