def fetch_assets(test_file, klass=None, method=None, logger=None): """ Fetches the assets based on keywords listed on FetchAssetHandler.calls. :param test_file: File name of instrumented test to be evaluated :type test_file: str :returns: list of names that were successfully fetched and list of fails. """ cache_dirs = data_dir.get_cache_dirs() success = [] fail = [] handler = FetchAssetHandler(test_file, klass, method) for call in handler.calls: expire = call.pop('expire', None) if expire is not None: expire = data_structures.time_to_seconds(str(expire)) # make dictionary unpacking compatible with python 3.4 as it does # not support constructions like: # Asset(**call, cache_dirs=cache_dirs, expire=expire) call['cache_dirs'] = cache_dirs call['expire'] = expire try: asset_obj = Asset(**call) if logger is not None: logger.info('Fetching asset from %s:%s.%s', test_file, klass, method) asset_obj.fetch() success.append(call['name']) except (OSError, ValueError) as failed: fail.append(failed) return success, fail
def fetch_assets(test_file, klass=None, method=None, logger=None): """Fetches the assets based on keywords listed on FetchAssetHandler.calls. :param test_file: File name of instrumented test to be evaluated :type test_file: str :returns: list of names that were successfully fetched and list of fails. """ cache_dirs = settings.as_dict().get('datadir.paths.cache_dirs') timeout = settings.as_dict().get('assets.fetch.timeout') success = [] fail = [] handler = FetchAssetHandler(test_file, klass, method) for call in handler.calls: expire = call.pop('expire', None) if expire is not None: expire = data_structures.time_to_seconds(str(expire)) try: asset_obj = Asset(**call, cache_dirs=cache_dirs, expire=expire) if logger is not None: logger.info('Fetching asset from %s:%s.%s', test_file, klass, method) asset_obj.fetch(timeout) success.append(call['name']) except (OSError, ValueError) as failed: fail.append(failed) return success, fail
def main(): configure_logging_settings() for version in ['3.6', '3.7', '3.8', '3.9', '3.10']: url = get_egg_url(python_version=version) asset = Asset(url, cache_dirs=CACHE_DIRS) asset.fetch() return True
def handle_register(config): cache_dirs = config.get("datadir.paths.cache_dirs") name = config.get("assets.register.name") asset_hash = config.get("assets.register.sha1_hash") location = config.get("assets.register.url") # Adding a twice the location is a small hack due the current logic to # return "by_name". This needs to be improved soon. asset = Asset( name=name, asset_hash=asset_hash, locations=[location, location], cache_dirs=cache_dirs, ) try: asset.find_asset_file() LOG_UI.error("Asset with name %s already registered.", name) return exit_codes.AVOCADO_WARNING except OSError: try: asset.fetch() LOG_UI.info("Done. Now you can reference it by name %s", name) return exit_codes.AVOCADO_ALL_OK except OSError as e: LOG_UI.error(e) return exit_codes.AVOCADO_FAIL
def fetch_assets(test_file, klass=None, method=None, logger=None): """ Fetches the assets based on keywords listed on FetchAssetHandler.calls. :param test_file: File name of instrumented test to be evaluated :type test_file: str :returns: list of names that were successfully fetched and list of fails. """ def validate_parameters(call): """ Validate the parameters to make sure we have a supported case. :param call: List of parameter to the Asset object. :type call: dict :returns: True or False """ name = call.get('name', None) locations = call.get('locations', None) # probably, parameter name was defined as a class attribute if ((name is None) or # probably, parameter locations was defined as a class attribute (not urllib.parse.urlparse(name).scheme and locations is None)): return False return True cache_dirs = data_dir.get_cache_dirs() success = [] fail = [] handler = FetchAssetHandler(test_file, klass, method) for call in handler.calls: # validate the parameters if not validate_parameters(call): continue expire = call.pop('expire', None) if expire is not None: expire = data_structures.time_to_seconds(str(expire)) try: # make dictionary unpacking compatible with python 3.4 as it does # not support constructions like: # Asset(**call, cache_dirs=cache_dirs, expire=expire) call['cache_dirs'] = cache_dirs call['expire'] = expire asset_obj = Asset(**call) if logger is not None: logger.info('Fetching asset from %s:%s.%s', test_file, klass, method) asset_obj.fetch() success.append(call['name']) except (OSError, ValueError) as failed: fail.append(failed) return success, fail
def handle_register(self, config): cache_dirs = data_dir.get_cache_dirs() name = config.get('assets.register.name') asset_hash = config.get('assets.register.sha1_hash') location = config.get('assets.register.url') # Adding a twice the location is a small hack due the current logic to # return "by_name". This needs to be improved soon. asset = Asset(name=name, asset_hash=asset_hash, locations=[location, location], cache_dirs=cache_dirs) try: asset.find_asset_file() LOG_UI.error("Asset with name %s already registered.", name) except OSError: try: asset.fetch() LOG_UI.info("Done. Now you can reference it by name %s", name) except OSError as e: LOG_UI.error(e)
def _fetch_asset(name, asset_hash, algorithm, locations, cache_dirs, expire, queue): asset_manager = Asset(name, asset_hash, algorithm, locations, cache_dirs, expire) result = 'pass' stdout = '' stderr = '' try: asset_file = asset_manager.fetch() stdout = 'File fetched at %s' % asset_file except OSError as exc: result = 'error' stderr = str(exc) output = {'result': result, 'stdout': stdout, 'stderr': stderr} queue.put(output)
def _fetch_asset(name, asset_hash, algorithm, locations, cache_dirs, expire, queue): asset_manager = Asset(name, asset_hash, algorithm, locations, cache_dirs, expire) result = "pass" stdout = "" stderr = "" try: asset_file = asset_manager.fetch() stdout = f"File fetched at {asset_file}" except OSError as exc: result = "error" stderr = str(exc) output = {"result": result, "stdout": stdout, "stderr": stderr} queue.put(output)
def _fetch_asset(self, url): cachedirs = self.config.get('datadir.paths.cache_dirs') asset = Asset(url, cache_dirs=cachedirs) return asset.fetch()