def resolve_resource(self, resource): # pylint: disable=too-many-branches assets = self.index.get(resource.owner.name, {}) if not assets: return {} if resource.name in ["apk", "jar"]: paths = [a["path"] for a in assets] version = getattr(resource, "version", None) found = get_from_list_by_extension(resource, paths, resource.name, version) if found: for a in assets: if a["path"] == found: return a elif resource.name == "revent": device_model = resource.owner.device.get_device_model() wa_device_name = resource.owner.device.name for name in [device_model, wa_device_name]: if not name: continue filename = ".".join([name, resource.stage, "revent"]).lower() for asset in assets: pathname = os.path.basename(asset["path"]).lower() if pathname == filename: try: ReventParser.check_revent_file(asset["path"]) return asset except ValueError as e: self.logger.warning(e.message) else: # file for asset in assets: if asset["path"].lower() == resource.path.lower(): return asset
def get(self, resource, **kwargs): device_model = resource.owner.device.get_device_model() wa_device_name = resource.owner.device.name for name in [device_model, wa_device_name]: if not name: continue filename = ".".join([name, resource.stage, "revent"]).lower() location = _d(os.path.join(self.get_base_location(resource), "revent_files")) for candidate in os.listdir(location): if candidate.lower() == filename.lower(): path = os.path.join(location, candidate) try: ReventParser.check_revent_file(path) return path except ValueError as e: self.logger.warning(e.message)
def get_from(self, resource, version, location): # pylint: disable=no-self-use # pylint: disable=too-many-branches if resource.name in ["apk", "jar"]: return get_from_location_by_extension(resource, location, resource.name, version) elif resource.name == "file": filepath = os.path.join(location, resource.path) if os.path.exists(filepath): return filepath elif resource.name == "revent": device_model = resource.owner.device.get_device_model() wa_device_name = resource.owner.device.name for name in [device_model, wa_device_name]: if not name: continue filename = ".".join([name, resource.stage, "revent"]).lower() alternate_location = os.path.join(location, "revent_files") # There tends to be some confusion as to where revent files should # be placed. This looks both in the extension's directory, and in # 'revent_files' subdirectory under it, if it exists. path = None if os.path.isdir(alternate_location): for candidate in os.listdir(alternate_location): if candidate.lower() == filename.lower(): path = os.path.join(alternate_location, candidate) if os.path.isdir(location): for candidate in os.listdir(location): if candidate.lower() == filename.lower(): path = os.path.join(location, candidate) if path: try: ReventParser.check_revent_file(path) return path except ValueError as e: self.logger.warning(e.message) else: raise ValueError("Unexpected resource type: {}".format(resource.name))