1ba991379Sopenharmony_ci# -*- coding:utf-8 -*-
2ba991379Sopenharmony_ci"""
3ba991379Sopenharmony_ci======================================================================================
4ba991379Sopenharmony_cicopyright (C) 2018-2019,  Huawei Technologies Co.
5ba991379Sopenharmony_ci========================================================================================
6ba991379Sopenharmony_ci@文件名称:    config.py
7ba991379Sopenharmony_ci@描述:       加载框架级常量 和 系统级常量
8ba991379Sopenharmony_ci@作者:       zwx503461
9ba991379Sopenharmony_ci@生成日期:    20181021
10ba991379Sopenharmony_ci======================================================================================
11ba991379Sopenharmony_ci"""
12ba991379Sopenharmony_ciimport os
13ba991379Sopenharmony_ciimport platform
14ba991379Sopenharmony_ci
15ba991379Sopenharmony_ci# =========================解析config文件,获取全局常亮========================
16ba991379Sopenharmony_cidef getAllParam(param_file):
17ba991379Sopenharmony_ci    '''
18ba991379Sopenharmony_ci    #===================================================================================
19ba991379Sopenharmony_ci    #   @Method:        getAllParam(param_file)
20ba991379Sopenharmony_ci    #   @Precondition:  none
21ba991379Sopenharmony_ci    #   @Func:          解析参数文件获取所有参数
22ba991379Sopenharmony_ci    #   @PostStatus:    none
23ba991379Sopenharmony_ci    #   @Param:         param_file:参数文件
24ba991379Sopenharmony_ci    #   @eg:            getAllParam(xxx.properties)
25ba991379Sopenharmony_ci    #   @return:        params_dict:所有的参数
26ba991379Sopenharmony_ci    #===================================================================================
27ba991379Sopenharmony_ci    '''
28ba991379Sopenharmony_ci    params_dict = {}
29ba991379Sopenharmony_ci    with open(param_file, 'Ur', encoding="utf-8") as file:
30ba991379Sopenharmony_ci        for line in file.readlines():
31ba991379Sopenharmony_ci            line = line.strip()
32ba991379Sopenharmony_ci            if len(line) != 0:
33ba991379Sopenharmony_ci                if line.find("=") != -1:
34ba991379Sopenharmony_ci                    str_list = line.split('=')
35ba991379Sopenharmony_ci                    if str_list[0].find("#") != -1:
36ba991379Sopenharmony_ci                        continue
37ba991379Sopenharmony_ci                    else:
38ba991379Sopenharmony_ci                        key = str_list[0].strip()
39ba991379Sopenharmony_ci                        value = line[len(str_list[0]) + 1:].strip()
40ba991379Sopenharmony_ci                        if len(key) != 0 and len(value) != 0:
41ba991379Sopenharmony_ci                            params_dict[key] = value
42ba991379Sopenharmony_ci    return params_dict
43ba991379Sopenharmony_ci
44ba991379Sopenharmony_ci
45ba991379Sopenharmony_cicur_path = os.path.dirname(os.path.dirname(__file__))
46ba991379Sopenharmony_ci
47ba991379Sopenharmony_ciadb_config_path = os.path.join(cur_path, 'config', 'config_adb.config')
48ba991379Sopenharmony_cibox_config_path = os.path.join(cur_path, 'config', 'config_box.config')
49ba991379Sopenharmony_cidevice_config_path = os.path.join(cur_path, 'config', 'config_device.config')
50ba991379Sopenharmony_ciglobal_config_path = os.path.join(cur_path, 'config', 'config_global.config')
51ba991379Sopenharmony_cilinux_config_path = os.path.join(cur_path, 'config', 'config_linux.config')
52ba991379Sopenharmony_ciwindows_config_path = os.path.join(cur_path, 'config', 'config_windows.config')
53ba991379Sopenharmony_cierrorcode_config_path = os.path.join(cur_path, 'config', 'config_errorcode.config')
54ba991379Sopenharmony_cierrorcode_device_config_path = os.path.join(cur_path, 'config', 'config_errorcode_device.config')
55ba991379Sopenharmony_ci
56ba991379Sopenharmony_ciadb_config_param = getAllParam(adb_config_path)
57ba991379Sopenharmony_cibox_config_param = getAllParam(box_config_path)
58ba991379Sopenharmony_cidevice_config_param = getAllParam(device_config_path)
59ba991379Sopenharmony_ciglobal_config_param = getAllParam(global_config_path)
60ba991379Sopenharmony_cilinux_config_param = getAllParam(linux_config_path)
61ba991379Sopenharmony_ciwindows_config_param = getAllParam(windows_config_path)
62ba991379Sopenharmony_cierrorcode_config_param = getAllParam(errorcode_config_path)
63ba991379Sopenharmony_cierrorcode_device_config_param = getAllParam(errorcode_device_config_path)
64ba991379Sopenharmony_ci
65ba991379Sopenharmony_ci# print('adb_config_param is %s' % (adb_config_param))
66ba991379Sopenharmony_ci# print('box_config_param is %s' % (box_config_param))
67ba991379Sopenharmony_ci# print('device_config_param is %s' % (device_config_param))
68ba991379Sopenharmony_ci# print('global_config_param is %s' % (global_config_param))
69ba991379Sopenharmony_ci# print('linux_config_param is %s' % (linux_config_param))
70ba991379Sopenharmony_ci# print('windows_config_param is %s' % (windows_config_param))
71ba991379Sopenharmony_ci
72ba991379Sopenharmony_ci# =========================获取框架级常量=======================
73ba991379Sopenharmony_ciSHORT_TIMEOUT = int(adb_config_param.get('SHORT_TIMEOUT'))
74ba991379Sopenharmony_ciINSTALL_APK_TIMEOUT = int(adb_config_param.get('INSTALL_APK_TIMEOUT'))
75ba991379Sopenharmony_ciREMOTE_PATH_MAX_LENGTH = int(adb_config_param.get('REMOTE_PATH_MAX_LENGTH'))
76ba991379Sopenharmony_ciSYNC_DATA_MAX = int(adb_config_param.get('SYNC_DATA_MAX'))
77ba991379Sopenharmony_ciID_OKAY = adb_config_param.get('ID_OKAY').encode('ascii')
78ba991379Sopenharmony_ciID_FAIL = adb_config_param.get('ID_FAIL').encode('ascii')
79ba991379Sopenharmony_ciID_STAT = adb_config_param.get('ID_STAT').encode('ascii')
80ba991379Sopenharmony_ciID_RECV = adb_config_param.get('ID_RECV').encode('ascii')
81ba991379Sopenharmony_ciID_DATA = adb_config_param.get('ID_DATA').encode('ascii')
82ba991379Sopenharmony_ciID_DONE = adb_config_param.get('ID_DONE').encode('ascii')
83ba991379Sopenharmony_ciID_SEND = adb_config_param.get('ID_SEND').encode('ascii')
84ba991379Sopenharmony_ciID_LIST = adb_config_param.get('ID_LIST').encode('ascii')
85ba991379Sopenharmony_ciID_DENT = adb_config_param.get('ID_DENT').encode('ascii')
86ba991379Sopenharmony_ci
87ba991379Sopenharmony_ciGT3000_DEFAULT_PORT = int(box_config_param.get('GT3000_DEFAULT_PORT'))
88ba991379Sopenharmony_ciOK = box_config_param.get('OK')
89ba991379Sopenharmony_ci
90ba991379Sopenharmony_ciDEVICE_STATE_ERECOVERY = device_config_param.get('DEVICE_STATE_ERECOVERY')
91ba991379Sopenharmony_ciDEVICE_STATE_UNKNOW = device_config_param.get('DEVICE_STATE_UNKNOW')
92ba991379Sopenharmony_ciDEVICE_STATE_BOOTLOADER = device_config_param.get('DEVICE_STATE_BOOTLOADER')
93ba991379Sopenharmony_ciDEVICE_STATE_OFFLINE = device_config_param.get('DEVICE_STATE_OFFLINE')
94ba991379Sopenharmony_ciDEVICE_STATE_ONLINE = device_config_param.get('DEVICE_STATE_ONLINE')
95ba991379Sopenharmony_ciDEVICE_STATE_RECOVERY = device_config_param.get('DEVICE_STATE_RECOVERY')
96ba991379Sopenharmony_ciDEVICE_STATE_UNAUTH = device_config_param.get('DEVICE_STATE_UNAUTH')
97ba991379Sopenharmony_ciPLATFORM_HISI = device_config_param.get('PLATFORM_HISI')
98ba991379Sopenharmony_ciPLATFORM_QCOM = device_config_param.get('PLATFORM_QCOM')
99ba991379Sopenharmony_ciPLATFORM_SC = device_config_param.get('PLATFORM_SC')
100ba991379Sopenharmony_ciDEVICE_STATE_FASTBOOT = device_config_param.get('DEVICE_STATE_FASTBOOT')
101ba991379Sopenharmony_ci
102ba991379Sopenharmony_ciDEFAULT_HOST = global_config_param.get('DEFAULT_HOST')
103ba991379Sopenharmony_ciDEFAULT_PORT = int(global_config_param.get('DEFAULT_PORT'))
104ba991379Sopenharmony_ciDEFAULT_ENCODING = global_config_param.get('DEFAULT_ENCODING')
105ba991379Sopenharmony_ciLINUX_ERROR_TITLE = global_config_param.get('LINUX_ERROR_TITLE')
106ba991379Sopenharmony_ciWINDOWS_ERROR_TITLE = global_config_param.get('WINDOWS_ERROR_TITLE')
107ba991379Sopenharmony_ciLOCK_SUFFIX = global_config_param.get('LOCK_SUFFIX')
108ba991379Sopenharmony_ciSUC_FILE = global_config_param.get('SUC_FILE')
109ba991379Sopenharmony_ciFAILED_FILE = global_config_param.get('FAILED_FILE')
110ba991379Sopenharmony_ciARIA2CBIN = global_config_param.get('ARIA2CBIN')
111ba991379Sopenharmony_ci
112ba991379Sopenharmony_ciSUCCESS_CODE = errorcode_config_param.get('SUCCESS_CODE')
113ba991379Sopenharmony_ciERROR_CUSTPARAM_IS_NONE = errorcode_config_param.get('ERROR_CUSTPARAM_IS_NONE')
114ba991379Sopenharmony_ciERROR_PARAMS_NO_SN = errorcode_config_param.get('ERROR_PARAMS_NO_SN')
115ba991379Sopenharmony_ciERROR_VERSION_USE_CHINAESE = errorcode_config_param.get('ERROR_VERSION_USE_CHINAESE')
116ba991379Sopenharmony_ciERROR_VERSION_IS_NONE = errorcode_config_param.get('ERROR_VERSION_IS_NONE')
117ba991379Sopenharmony_ciERROR_VERSION_PATH_TOO_LONG = errorcode_config_param.get('ERROR_VERSION_PATH_TOO_LONG')
118ba991379Sopenharmony_ciERROR_CUSTPARAM_NOT_IN_ALLPARAMS = errorcode_config_param.get('ERROR_CUSTPARAM_NOT_IN_ALLPARAMS')
119ba991379Sopenharmony_ciERROR_DOWNLOAD_IMG_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_IMG_FAIL')
120ba991379Sopenharmony_ciERROR_DOWNLOAD_ROOT_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_ROOT_FAIL')
121ba991379Sopenharmony_ciERROR_DOWNLOAD_APK_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_APK_FAIL')
122ba991379Sopenharmony_ciERROR_MAKE_DIR_FAIL = errorcode_config_param.get('ERROR_MAKE_DIR_FAIL')
123ba991379Sopenharmony_ciERROR_FLASH_IMAGE_FAIL = errorcode_config_param.get('ERROR_FLASH_IMAGE_FAIL')
124ba991379Sopenharmony_ciERROR_FLASH_BASE_FAIL = errorcode_config_param.get('ERROR_FLASH_BASE_FAIL')
125ba991379Sopenharmony_ciERROR_FLASH_CUST_FAIL = errorcode_config_param.get('ERROR_FLASH_CUST_FAIL')
126ba991379Sopenharmony_ciERROR_FLASH_PRELOAD_FAIL = errorcode_config_param.get('ERROR_FLASH_PRELOAD_FAIL')
127ba991379Sopenharmony_ciERROR_NO_IMG_FILE = errorcode_config_param.get('ERROR_NO_IMG_FILE')
128ba991379Sopenharmony_ciERROR_NO_SCRIPT_FILE = errorcode_config_param.get('ERROR_NO_SCRIPT_FILE')
129ba991379Sopenharmony_ciERROR_DEVICE_NOT_FOUND = errorcode_config_param.get('ERROR_DEVICE_NOT_FOUND')
130ba991379Sopenharmony_ciERROR_MODIFY_SCRIPT_FAIL = errorcode_config_param.get('ERROR_MODIFY_SCRIPT_FAIL')
131ba991379Sopenharmony_ciERROR_INVALID_APK_FILE = errorcode_config_param.get('ERROR_INVALID_APK_FILE')
132ba991379Sopenharmony_ciERROR_LOCALPATH_NOT_EXIST = errorcode_config_param.get('ERROR_LOCALPATH_NOT_EXIST')
133ba991379Sopenharmony_ciERROR_INSTALL_APK_FAIL = errorcode_config_param.get('ERROR_INSTALL_APK_FAIL')
134ba991379Sopenharmony_ciERROR_DOWNLOAD_COTA_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_COTA_FAIL')
135ba991379Sopenharmony_ciERROR_DEVICE_UNAUTHORIZE = errorcode_config_param.get('ERROR_DEVICE_UNAUTHORIZE')
136ba991379Sopenharmony_ciERROR_PUSH_FILE_FAIL = errorcode_config_param.get('ERROR_PUSH_FILE_FAIL')
137ba991379Sopenharmony_ciERROR_NO_UPGRADE_FILE_OR_PACKAGE = errorcode_config_param.get('ERROR_NO_UPGRADE_FILE_OR_PACKAGE')
138ba991379Sopenharmony_ciERROR_DOWNLOAD_VERSION_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_VERSION_FAIL')
139ba991379Sopenharmony_ciERROR_BOOT_UP_TIME_OUT = errorcode_config_param.get('ERROR_BOOT_UP_TIME_OUT')
140ba991379Sopenharmony_ciERROR_MODEM_CHECK_FAIL = errorcode_config_param.get('ERROR_MODEM_CHECK_FAIL')
141ba991379Sopenharmony_ciERROR_LAUNCHER_CHECK_FAIL = errorcode_config_param.get('ERROR_LAUNCHER_CHECK_FAIL')
142ba991379Sopenharmony_ciERROR_CANNOT_INTO_FASTBOOT_MODE = errorcode_config_param.get('ERROR_CANNOT_INTO_FASTBOOT_MODE')
143ba991379Sopenharmony_ciERROR_RESETFACTORY_TIME_OUT = errorcode_config_param.get('ERROR_RESETFACTORY_TIME_OUT')
144ba991379Sopenharmony_ciERROR_OTHER_ERROR = errorcode_config_param.get('ERROR_OTHER_ERROR')
145ba991379Sopenharmony_ciERROR_VALIDATEPARAMS_FAIL = errorcode_config_param.get('ERROR_VALIDATEPARAMS_FAIL')
146ba991379Sopenharmony_ciERROR_PARSE_RESOURCEPOOL_PARMS_FAIL = errorcode_config_param.get('ERROR_PARSE_RESOURCEPOOL_PARMS_FAIL')
147ba991379Sopenharmony_ciERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE = errorcode_config_param.get('ERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE')
148ba991379Sopenharmony_ciERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL = errorcode_config_param.get('ERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL')
149ba991379Sopenharmony_ciERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL = errorcode_config_param.get('ERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL')
150ba991379Sopenharmony_ci
151ba991379Sopenharmony_ci
152ba991379Sopenharmony_ciERROR_UNINSTALL_XDEVICE_ERROR = errorcode_device_config_param.get('ERROR_UNINSTALL_XDEVICE_ERROR')
153ba991379Sopenharmony_ciERROR_INSTALL_XDEVICE_ERROR = errorcode_device_config_param.get('ERROR_INSTALL_XDEVICE_ERROR')
154ba991379Sopenharmony_ciERROR_PHONE_START_FAILED = errorcode_config_param.get('ERROR_PHONE_START_FAILED')
155ba991379Sopenharmony_ciERROR_ANDROID_STARTING = errorcode_device_config_param.get('ERROR_ANDROID_STARTING')
156ba991379Sopenharmony_ciERROR_PHONE_FASTBOOT = errorcode_device_config_param.get('EERROR_PHONE_FASTBOOT')
157ba991379Sopenharmony_ciERROR_NO_ROOT_PERMISSION = errorcode_device_config_param.get('ERROR_NO_ROOT_PERMISSION')
158ba991379Sopenharmony_ciERROR_ADB_TIMEOUT = errorcode_device_config_param.get('ERROR_ADB_TIMEOUT')
159ba991379Sopenharmony_ciERROR_PHONE_NOTFOUND = errorcode_device_config_param.get('ERROR_PHONE_NOTFOUND')
160ba991379Sopenharmony_ciERROR_PHONE_SIMULATE_NOTFOUND = errorcode_device_config_param.get('ERROR_PHONE_SIMULATE_NOTFOUND')
161ba991379Sopenharmony_ciERROR_CHECK_PARAM_ERROR = errorcode_device_config_param.get('ERROR_CHECK_PARAM_ERROR')
162ba991379Sopenharmony_ciERROR_PHONE_OTHER_ERROR = errorcode_device_config_param.get('ERROR_PHONE_OTHER_ERROR')
163ba991379Sopenharmony_ci
164ba991379Sopenharmony_ci# =========================获取系统级常量=======================
165ba991379Sopenharmony_cios_name = platform.system()
166ba991379Sopenharmony_ci
167ba991379Sopenharmony_ciPASSWORD = linux_config_param.get('PASSWORD')
168ba991379Sopenharmony_ciACCOUNT = linux_config_param.get('ACCOUNT')
169ba991379Sopenharmony_ciWORKSPACEG = windows_config_param.get('WORKSPACEG')
170ba991379Sopenharmony_ciENV_PATH = windows_config_param.get('ENV_PATH')
171ba991379Sopenharmony_ciLOCAL_APK_PATH = windows_config_param.get('LOCAL_APK_PATH')
172ba991379Sopenharmony_ciLOCAL_COTA_PATH = windows_config_param.get('LOCAL_COTA_PATH')
173ba991379Sopenharmony_ciMST_PATH = windows_config_param.get('MST_PATH')
174ba991379Sopenharmony_ciMST_PATHG = windows_config_param.get('MST_PATHG')
175ba991379Sopenharmony_ciDIR_PATH = windows_config_param.get('DIR_PATH')
176ba991379Sopenharmony_ci
177ba991379Sopenharmony_ci# 检查恢复常量
178ba991379Sopenharmony_ciLINUX_ECM_FILE = linux_config_param.get('LINUX_ECM_FILE')
179ba991379Sopenharmony_ciLINUX_AGENT_FILE = linux_config_param.get('LINUX_ECM_FILE')
180ba991379Sopenharmony_ci
181ba991379Sopenharmony_ciANDROID_ADB_SERVER_PORT = windows_config_param.get('ANDROID_ADB_SERVER_PORT')
182ba991379Sopenharmony_ciDEVICE_TEST_HOME = windows_config_param.get('DEVICE_TEST_HOME')
183ba991379Sopenharmony_ciDEVICETESTOOLS_DIR = windows_config_param.get('DEVICETESTOOLS_DIR')
184ba991379Sopenharmony_ciES_REC_SCRIPT = windows_config_param.get('ES_REC_SCRIPT')
185ba991379Sopenharmony_ciWINDOWS_AGENT_DIR = windows_config_param.get('WINDOWS_AGENT_DIR')
186ba991379Sopenharmony_ciWINDOWS_AGENT_FILE = windows_config_param.get('WINDOWS_AGENT_FILE')
187ba991379Sopenharmony_ciWINDOWS_AGENT_VERSION_FILE = windows_config_param.get('WINDOWS_AGENT_VERSION_FILE')
188ba991379Sopenharmony_ciWINDOWS_ES_DIR = windows_config_param.get('WINDOWS_ES_DIR')
189ba991379Sopenharmony_ciWINDOWS_ES_VERSION_FILE = windows_config_param.get('WINDOWS_ES_VERSION_FILE')
190ba991379Sopenharmony_ciWINDOWS_ECM_DIR = windows_config_param.get('WINDOWS_ECM_DIR')
191ba991379Sopenharmony_ciWINDOWS_ECM_VERSION_FILE = windows_config_param.get('WINDOWS_ECM_VERSION_FILE')
192ba991379Sopenharmony_ci
193ba991379Sopenharmony_ciif os_name == 'Linux':
194ba991379Sopenharmony_ci    SCRIPT_FILE = linux_config_param.get('SCRIPT_FILE')
195ba991379Sopenharmony_ci    TEST_PATH = linux_config_param.get('TEST_PATH')
196ba991379Sopenharmony_ci    WORKSPACE = linux_config_param.get('WORKSPACE')
197ba991379Sopenharmony_ci    FLASH_SCRIPT_PATH = linux_config_param.get('FLASH_SCRIPT_PATH')
198ba991379Sopenharmony_ci    SPLASH2_PATH = linux_config_param.get('SPLASH2_PATH')
199ba991379Sopenharmony_ci    FASTBOOT_EXEC = linux_config_param.get('FASTBOOT_EXEC')
200ba991379Sopenharmony_ci    DEFAULT_BAUDRATE = int(linux_config_param.get('DEFAULT_BAUDRATE'))
201ba991379Sopenharmony_ci    DEFAULT_PORT = int(linux_config_param.get('DEFAULT_PORT'))
202ba991379Sopenharmony_ci    P4_NAME = linux_config_param.get('P4_NAME')
203ba991379Sopenharmony_ci
204ba991379Sopenharmony_ciif os_name == 'Windows':
205ba991379Sopenharmony_ci    SCRIPT_FILE = windows_config_param.get('SCRIPT_FILE')
206ba991379Sopenharmony_ci    WORKSPACE = windows_config_param.get('WORKSPACE')
207ba991379Sopenharmony_ci    TEST_PATH = windows_config_param.get('TEST_PATH')
208ba991379Sopenharmony_ci    FLASH_SCRIPT_PATH = windows_config_param.get('FLASH_SCRIPT_PATH')
209ba991379Sopenharmony_ci    FASTBOOT_EXEC = windows_config_param.get('FASTBOOT_EXEC')
210ba991379Sopenharmony_ci    SPLASH2_PATH = windows_config_param.get('SPLASH2_PATH')
211ba991379Sopenharmony_ci    DEFAULT_BAUDRATE = int(windows_config_param.get('DEFAULT_BAUDRATE'))
212ba991379Sopenharmony_ci    DEFAULT_PORT = int(windows_config_param.get('DEFAULT_PORT'))
213ba991379Sopenharmony_ci    P4_NAME = windows_config_param.get('P4_NAME')
214