1# -*- coding:utf-8 -*- 2""" 3====================================================================================== 4copyright (C) 2018-2019, Huawei Technologies Co. 5======================================================================================== 6@文件名称: config.py 7@描述: 加载框架级常量 和 系统级常量 8@作者: zwx503461 9@生成日期: 20181021 10====================================================================================== 11""" 12import os 13import platform 14 15# =========================解析config文件,获取全局常亮======================== 16def getAllParam(param_file): 17 ''' 18 #=================================================================================== 19 # @Method: getAllParam(param_file) 20 # @Precondition: none 21 # @Func: 解析参数文件获取所有参数 22 # @PostStatus: none 23 # @Param: param_file:参数文件 24 # @eg: getAllParam(xxx.properties) 25 # @return: params_dict:所有的参数 26 #=================================================================================== 27 ''' 28 params_dict = {} 29 with open(param_file, 'Ur', encoding="utf-8") as file: 30 for line in file.readlines(): 31 line = line.strip() 32 if len(line) != 0: 33 if line.find("=") != -1: 34 str_list = line.split('=') 35 if str_list[0].find("#") != -1: 36 continue 37 else: 38 key = str_list[0].strip() 39 value = line[len(str_list[0]) + 1:].strip() 40 if len(key) != 0 and len(value) != 0: 41 params_dict[key] = value 42 return params_dict 43 44 45cur_path = os.path.dirname(os.path.dirname(__file__)) 46 47adb_config_path = os.path.join(cur_path, 'config', 'config_adb.config') 48box_config_path = os.path.join(cur_path, 'config', 'config_box.config') 49device_config_path = os.path.join(cur_path, 'config', 'config_device.config') 50global_config_path = os.path.join(cur_path, 'config', 'config_global.config') 51linux_config_path = os.path.join(cur_path, 'config', 'config_linux.config') 52windows_config_path = os.path.join(cur_path, 'config', 'config_windows.config') 53errorcode_config_path = os.path.join(cur_path, 'config', 'config_errorcode.config') 54errorcode_device_config_path = os.path.join(cur_path, 'config', 'config_errorcode_device.config') 55 56adb_config_param = getAllParam(adb_config_path) 57box_config_param = getAllParam(box_config_path) 58device_config_param = getAllParam(device_config_path) 59global_config_param = getAllParam(global_config_path) 60linux_config_param = getAllParam(linux_config_path) 61windows_config_param = getAllParam(windows_config_path) 62errorcode_config_param = getAllParam(errorcode_config_path) 63errorcode_device_config_param = getAllParam(errorcode_device_config_path) 64 65# print('adb_config_param is %s' % (adb_config_param)) 66# print('box_config_param is %s' % (box_config_param)) 67# print('device_config_param is %s' % (device_config_param)) 68# print('global_config_param is %s' % (global_config_param)) 69# print('linux_config_param is %s' % (linux_config_param)) 70# print('windows_config_param is %s' % (windows_config_param)) 71 72# =========================获取框架级常量======================= 73SHORT_TIMEOUT = int(adb_config_param.get('SHORT_TIMEOUT')) 74INSTALL_APK_TIMEOUT = int(adb_config_param.get('INSTALL_APK_TIMEOUT')) 75REMOTE_PATH_MAX_LENGTH = int(adb_config_param.get('REMOTE_PATH_MAX_LENGTH')) 76SYNC_DATA_MAX = int(adb_config_param.get('SYNC_DATA_MAX')) 77ID_OKAY = adb_config_param.get('ID_OKAY').encode('ascii') 78ID_FAIL = adb_config_param.get('ID_FAIL').encode('ascii') 79ID_STAT = adb_config_param.get('ID_STAT').encode('ascii') 80ID_RECV = adb_config_param.get('ID_RECV').encode('ascii') 81ID_DATA = adb_config_param.get('ID_DATA').encode('ascii') 82ID_DONE = adb_config_param.get('ID_DONE').encode('ascii') 83ID_SEND = adb_config_param.get('ID_SEND').encode('ascii') 84ID_LIST = adb_config_param.get('ID_LIST').encode('ascii') 85ID_DENT = adb_config_param.get('ID_DENT').encode('ascii') 86 87GT3000_DEFAULT_PORT = int(box_config_param.get('GT3000_DEFAULT_PORT')) 88OK = box_config_param.get('OK') 89 90DEVICE_STATE_ERECOVERY = device_config_param.get('DEVICE_STATE_ERECOVERY') 91DEVICE_STATE_UNKNOW = device_config_param.get('DEVICE_STATE_UNKNOW') 92DEVICE_STATE_BOOTLOADER = device_config_param.get('DEVICE_STATE_BOOTLOADER') 93DEVICE_STATE_OFFLINE = device_config_param.get('DEVICE_STATE_OFFLINE') 94DEVICE_STATE_ONLINE = device_config_param.get('DEVICE_STATE_ONLINE') 95DEVICE_STATE_RECOVERY = device_config_param.get('DEVICE_STATE_RECOVERY') 96DEVICE_STATE_UNAUTH = device_config_param.get('DEVICE_STATE_UNAUTH') 97PLATFORM_HISI = device_config_param.get('PLATFORM_HISI') 98PLATFORM_QCOM = device_config_param.get('PLATFORM_QCOM') 99PLATFORM_SC = device_config_param.get('PLATFORM_SC') 100DEVICE_STATE_FASTBOOT = device_config_param.get('DEVICE_STATE_FASTBOOT') 101 102DEFAULT_HOST = global_config_param.get('DEFAULT_HOST') 103DEFAULT_PORT = int(global_config_param.get('DEFAULT_PORT')) 104DEFAULT_ENCODING = global_config_param.get('DEFAULT_ENCODING') 105LINUX_ERROR_TITLE = global_config_param.get('LINUX_ERROR_TITLE') 106WINDOWS_ERROR_TITLE = global_config_param.get('WINDOWS_ERROR_TITLE') 107LOCK_SUFFIX = global_config_param.get('LOCK_SUFFIX') 108SUC_FILE = global_config_param.get('SUC_FILE') 109FAILED_FILE = global_config_param.get('FAILED_FILE') 110ARIA2CBIN = global_config_param.get('ARIA2CBIN') 111 112SUCCESS_CODE = errorcode_config_param.get('SUCCESS_CODE') 113ERROR_CUSTPARAM_IS_NONE = errorcode_config_param.get('ERROR_CUSTPARAM_IS_NONE') 114ERROR_PARAMS_NO_SN = errorcode_config_param.get('ERROR_PARAMS_NO_SN') 115ERROR_VERSION_USE_CHINAESE = errorcode_config_param.get('ERROR_VERSION_USE_CHINAESE') 116ERROR_VERSION_IS_NONE = errorcode_config_param.get('ERROR_VERSION_IS_NONE') 117ERROR_VERSION_PATH_TOO_LONG = errorcode_config_param.get('ERROR_VERSION_PATH_TOO_LONG') 118ERROR_CUSTPARAM_NOT_IN_ALLPARAMS = errorcode_config_param.get('ERROR_CUSTPARAM_NOT_IN_ALLPARAMS') 119ERROR_DOWNLOAD_IMG_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_IMG_FAIL') 120ERROR_DOWNLOAD_ROOT_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_ROOT_FAIL') 121ERROR_DOWNLOAD_APK_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_APK_FAIL') 122ERROR_MAKE_DIR_FAIL = errorcode_config_param.get('ERROR_MAKE_DIR_FAIL') 123ERROR_FLASH_IMAGE_FAIL = errorcode_config_param.get('ERROR_FLASH_IMAGE_FAIL') 124ERROR_FLASH_BASE_FAIL = errorcode_config_param.get('ERROR_FLASH_BASE_FAIL') 125ERROR_FLASH_CUST_FAIL = errorcode_config_param.get('ERROR_FLASH_CUST_FAIL') 126ERROR_FLASH_PRELOAD_FAIL = errorcode_config_param.get('ERROR_FLASH_PRELOAD_FAIL') 127ERROR_NO_IMG_FILE = errorcode_config_param.get('ERROR_NO_IMG_FILE') 128ERROR_NO_SCRIPT_FILE = errorcode_config_param.get('ERROR_NO_SCRIPT_FILE') 129ERROR_DEVICE_NOT_FOUND = errorcode_config_param.get('ERROR_DEVICE_NOT_FOUND') 130ERROR_MODIFY_SCRIPT_FAIL = errorcode_config_param.get('ERROR_MODIFY_SCRIPT_FAIL') 131ERROR_INVALID_APK_FILE = errorcode_config_param.get('ERROR_INVALID_APK_FILE') 132ERROR_LOCALPATH_NOT_EXIST = errorcode_config_param.get('ERROR_LOCALPATH_NOT_EXIST') 133ERROR_INSTALL_APK_FAIL = errorcode_config_param.get('ERROR_INSTALL_APK_FAIL') 134ERROR_DOWNLOAD_COTA_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_COTA_FAIL') 135ERROR_DEVICE_UNAUTHORIZE = errorcode_config_param.get('ERROR_DEVICE_UNAUTHORIZE') 136ERROR_PUSH_FILE_FAIL = errorcode_config_param.get('ERROR_PUSH_FILE_FAIL') 137ERROR_NO_UPGRADE_FILE_OR_PACKAGE = errorcode_config_param.get('ERROR_NO_UPGRADE_FILE_OR_PACKAGE') 138ERROR_DOWNLOAD_VERSION_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_VERSION_FAIL') 139ERROR_BOOT_UP_TIME_OUT = errorcode_config_param.get('ERROR_BOOT_UP_TIME_OUT') 140ERROR_MODEM_CHECK_FAIL = errorcode_config_param.get('ERROR_MODEM_CHECK_FAIL') 141ERROR_LAUNCHER_CHECK_FAIL = errorcode_config_param.get('ERROR_LAUNCHER_CHECK_FAIL') 142ERROR_CANNOT_INTO_FASTBOOT_MODE = errorcode_config_param.get('ERROR_CANNOT_INTO_FASTBOOT_MODE') 143ERROR_RESETFACTORY_TIME_OUT = errorcode_config_param.get('ERROR_RESETFACTORY_TIME_OUT') 144ERROR_OTHER_ERROR = errorcode_config_param.get('ERROR_OTHER_ERROR') 145ERROR_VALIDATEPARAMS_FAIL = errorcode_config_param.get('ERROR_VALIDATEPARAMS_FAIL') 146ERROR_PARSE_RESOURCEPOOL_PARMS_FAIL = errorcode_config_param.get('ERROR_PARSE_RESOURCEPOOL_PARMS_FAIL') 147ERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE = errorcode_config_param.get('ERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE') 148ERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL = errorcode_config_param.get('ERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL') 149ERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL = errorcode_config_param.get('ERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL') 150 151 152ERROR_UNINSTALL_XDEVICE_ERROR = errorcode_device_config_param.get('ERROR_UNINSTALL_XDEVICE_ERROR') 153ERROR_INSTALL_XDEVICE_ERROR = errorcode_device_config_param.get('ERROR_INSTALL_XDEVICE_ERROR') 154ERROR_PHONE_START_FAILED = errorcode_config_param.get('ERROR_PHONE_START_FAILED') 155ERROR_ANDROID_STARTING = errorcode_device_config_param.get('ERROR_ANDROID_STARTING') 156ERROR_PHONE_FASTBOOT = errorcode_device_config_param.get('EERROR_PHONE_FASTBOOT') 157ERROR_NO_ROOT_PERMISSION = errorcode_device_config_param.get('ERROR_NO_ROOT_PERMISSION') 158ERROR_ADB_TIMEOUT = errorcode_device_config_param.get('ERROR_ADB_TIMEOUT') 159ERROR_PHONE_NOTFOUND = errorcode_device_config_param.get('ERROR_PHONE_NOTFOUND') 160ERROR_PHONE_SIMULATE_NOTFOUND = errorcode_device_config_param.get('ERROR_PHONE_SIMULATE_NOTFOUND') 161ERROR_CHECK_PARAM_ERROR = errorcode_device_config_param.get('ERROR_CHECK_PARAM_ERROR') 162ERROR_PHONE_OTHER_ERROR = errorcode_device_config_param.get('ERROR_PHONE_OTHER_ERROR') 163 164# =========================获取系统级常量======================= 165os_name = platform.system() 166 167PASSWORD = linux_config_param.get('PASSWORD') 168ACCOUNT = linux_config_param.get('ACCOUNT') 169WORKSPACEG = windows_config_param.get('WORKSPACEG') 170ENV_PATH = windows_config_param.get('ENV_PATH') 171LOCAL_APK_PATH = windows_config_param.get('LOCAL_APK_PATH') 172LOCAL_COTA_PATH = windows_config_param.get('LOCAL_COTA_PATH') 173MST_PATH = windows_config_param.get('MST_PATH') 174MST_PATHG = windows_config_param.get('MST_PATHG') 175DIR_PATH = windows_config_param.get('DIR_PATH') 176 177# 检查恢复常量 178LINUX_ECM_FILE = linux_config_param.get('LINUX_ECM_FILE') 179LINUX_AGENT_FILE = linux_config_param.get('LINUX_ECM_FILE') 180 181ANDROID_ADB_SERVER_PORT = windows_config_param.get('ANDROID_ADB_SERVER_PORT') 182DEVICE_TEST_HOME = windows_config_param.get('DEVICE_TEST_HOME') 183DEVICETESTOOLS_DIR = windows_config_param.get('DEVICETESTOOLS_DIR') 184ES_REC_SCRIPT = windows_config_param.get('ES_REC_SCRIPT') 185WINDOWS_AGENT_DIR = windows_config_param.get('WINDOWS_AGENT_DIR') 186WINDOWS_AGENT_FILE = windows_config_param.get('WINDOWS_AGENT_FILE') 187WINDOWS_AGENT_VERSION_FILE = windows_config_param.get('WINDOWS_AGENT_VERSION_FILE') 188WINDOWS_ES_DIR = windows_config_param.get('WINDOWS_ES_DIR') 189WINDOWS_ES_VERSION_FILE = windows_config_param.get('WINDOWS_ES_VERSION_FILE') 190WINDOWS_ECM_DIR = windows_config_param.get('WINDOWS_ECM_DIR') 191WINDOWS_ECM_VERSION_FILE = windows_config_param.get('WINDOWS_ECM_VERSION_FILE') 192 193if os_name == 'Linux': 194 SCRIPT_FILE = linux_config_param.get('SCRIPT_FILE') 195 TEST_PATH = linux_config_param.get('TEST_PATH') 196 WORKSPACE = linux_config_param.get('WORKSPACE') 197 FLASH_SCRIPT_PATH = linux_config_param.get('FLASH_SCRIPT_PATH') 198 SPLASH2_PATH = linux_config_param.get('SPLASH2_PATH') 199 FASTBOOT_EXEC = linux_config_param.get('FASTBOOT_EXEC') 200 DEFAULT_BAUDRATE = int(linux_config_param.get('DEFAULT_BAUDRATE')) 201 DEFAULT_PORT = int(linux_config_param.get('DEFAULT_PORT')) 202 P4_NAME = linux_config_param.get('P4_NAME') 203 204if os_name == 'Windows': 205 SCRIPT_FILE = windows_config_param.get('SCRIPT_FILE') 206 WORKSPACE = windows_config_param.get('WORKSPACE') 207 TEST_PATH = windows_config_param.get('TEST_PATH') 208 FLASH_SCRIPT_PATH = windows_config_param.get('FLASH_SCRIPT_PATH') 209 FASTBOOT_EXEC = windows_config_param.get('FASTBOOT_EXEC') 210 SPLASH2_PATH = windows_config_param.get('SPLASH2_PATH') 211 DEFAULT_BAUDRATE = int(windows_config_param.get('DEFAULT_BAUDRATE')) 212 DEFAULT_PORT = int(windows_config_param.get('DEFAULT_PORT')) 213 P4_NAME = windows_config_param.get('P4_NAME') 214