def get_variables(self): config = self._load_config() variables = dict(config) os_variant = DotDict( pretty=config.OS_VARIANT, nospace=config.OS_VARIANT.replace(' ', ''), underscore=config.OS_VARIANT.replace(' ', '_')) variables['OS_VARIANT'] = os_variant sdk_variant = DotDict( pretty=config.SDK_VARIANT, nospace=config.SDK_VARIANT.replace(' ', ''), underscore=config.SDK_VARIANT.replace(' ', '_')) variables['SDK_VARIANT'] = sdk_variant sdk_install_dir = config.SDK_INSTALL_DIR sdk_install_dir = os.path.expanduser(sdk_install_dir) variables['SDK_INSTALL_DIR'] = sdk_install_dir device_is_emulator = config.DEVICE_TYPE == 'emulator' device_os_version = config.DEVICE_OS_VERSION os_version = config.OS_VERSION.get(device_os_version, device_os_version) if config.DEVICE_OS_VERSION == 'ea': os_version_suffix = 'EA' else: os_version_suffix = '' build_target = (os_variant.nospace + '-' + os_version + os_version_suffix + '-' + config.DEVICE_ARCH) if device_is_emulator: # FIXME: Emulator names do not match package names # FIXME: There are no EA emulators #name = os_variant.nospace + '-' + os_version + os_version_suffix device_name = os_variant.pretty + ' Emulator ' + os_version + os_version_suffix else: device_name = build_target device = DotDict( name=device_name, is_emulator=device_is_emulator, arch=config.DEVICE_ARCH, build_target=build_target, user=config.DEVICE_USER) variables['DEVICE'] = device # Encourage use of DEVICE.* instead del variables['DEVICE_TYPE'] del variables['DEVICE_ARCH'] del variables['DEVICE_OS_VERSION'] del variables['DEVICE_USER'] variables['SDK_CONFIG_DIR'] = os.path.expanduser('~/.config/' + sdk_variant.nospace) variables['SDK_MAINTENANCE_TOOL'] = sdk_install_dir + '/SDKMaintenanceTool' variables['SFDK'] = sdk_install_dir + '/bin/sfdk' return variables
async def wait_for_response_url(self, url, status=200, body=None, timeout=None): url = str2str(url) status = str2int(status) res = await self.library_ctx.get_current_page().get_page( ).waitForResponse( lambda res: re.search(url, res.url ) is not None and res.status == status, options={ 'timeout': self.timestr_to_secs_for_default_timeout(timeout) * 1000 }) try: res_text = (await res.text()) except: res_text = '' if body is None or re.search(body, res_text.replace('\n', '')): log_str = 'Wait for request url: ' + res.url if res_text != '': log_str += '\n' + res_text self.info(log_str) else: raise Exception('Can\'t match response body with ' + body + ' \n ' + res_text) return DotDict({ 'url': res.url, 'status': res.status, 'body': res_text })
async def wait_for_request_url(self, url, method='GET', body=None, timeout=None): url = str2str(url) method = str2str(method) req = await self.library_ctx.get_current_page().get_page( ).waitForRequest( lambda req: re.search(url, req.url ) is not None and req.method == method, options={ 'timeout': self.timestr_to_secs_for_default_timeout(timeout) * 1000 }) try: pos_data = (await req.postData()) except: pos_data = '' if body is None or re.search(body, pos_data.replace('\n', '')): log_str = 'Wait for request url: ' + req.method + ' - ' + req.url if pos_data != '': log_str + '\n' + pos_data self.info(log_str) else: raise Exception('Can\'t match request body with ' + body + ' \n ' + pos_data) return DotDict({ 'url': req.url, 'method': req.method, 'body': pos_data })
def _load_config(self): """Load config.py as a variable file in a way that the individual variables can be overriden on command line as if it was loaded explicitly as a variables file. """ source_dir = os.path.dirname(os.path.abspath(__file__)) # Config file is meant to live in the output directory... config_file = os.path.abspath('config.py') if not os.path.exists(config_file): # ...but look also into the sources to allow RED to do its job config_file = os.path.join(source_dir, 'config.py') if not os.path.exists(config_file): configure = os.path.join(source_dir, 'configure') configure = os.path.relpath(configure) raise ConfigurationError("Configuration file not found. Forgot to run '{}'?" .format(configure)) config = Variables() config.set_from_file(config_file) try: global_variables = BuiltIn().get_variables() for name in config.as_dict(): if name in global_variables: config[name] = global_variables[name] except RobotNotRunningError: # Use the defaults when the IDE queries variables pass return DotDict(config.as_dict(decoration=False))
def _convert_resp_to_dict(response): new_response = { item: getattr(response, item) for item in dir(response) if item[0] != '_' } return DotDict(new_response)
def _load_config(self): """Load config.py as a variable file in a way that the individual variables can be overriden on command line as if it was loaded explicitly as a variables file. """ config_dir = os.path.dirname(os.path.abspath(__file__)) config_file = os.path.join(config_dir, 'config.py') config = Variables() config.set_from_file(config_file) try: global_variables = BuiltIn().get_variables() for name in config.as_dict(): if name in global_variables: config[name] = global_variables[name] except RobotNotRunningError: # Use the defaults when the IDE queries variables pass return DotDict(config.as_dict(decoration=False))
def _convert_resp_to_dict(response): new_response = {} for item in dir(response): if item[0] != '_': new_response[item] = getattr(response, item) return DotDict(new_response)