def resolve_package(self, context): if not self.owner.package_names and not self.package_name: msg = 'Cannot Resolve package; No package name(s) specified' raise WorkloadError(msg) self.error_msg = None with lock_file(os.path.join(self.owner.dependencies_directory, self.owner.name)): if self.prefer_host_package: self.resolve_package_from_host(context) if not self.apk_file: self.resolve_package_from_target() else: self.resolve_package_from_target() if not self.apk_file: self.resolve_package_from_host(context) if self.apk_file: with lock_file(self.apk_file): self.apk_info = ApkInfo(self.apk_file) else: if self.error_msg: raise WorkloadError(self.error_msg) else: if self.package_name: message = 'Package "{package}" not found for workload {name} '\ 'on host or target.' elif self.version: message = 'No matching package found for workload {name} '\ '(version {version}) on host or target.' else: message = 'No matching package found for workload {name} on host or target' raise WorkloadError(message.format(name=self.owner.name, version=self.version, package=self.package_name))
def read_target_info_cache(): if not os.path.exists(settings.cache_directory): os.makedirs(settings.cache_directory) if not os.path.isfile(settings.target_info_cache_file): return {} with lock_file(settings.target_info_cache_file): return read_pod(settings.target_info_cache_file)
def apk_version_matches(path, version): version = list_or_string(version) with lock_file(path): info = ApkInfo(path) for v in version: if info.version_name == v or info.version_code == v: return True if loose_version_matching(v, info.version_name): return True return False
def pull_apk(self, package): if not self.target.package_is_installed(package): message = 'Cannot retrieve "{}" as not installed on Target' raise WorkloadError(message.format(package)) package_info = self.target.get_package_info(package) apk_name = self._get_package_name(package_info.apk_path) host_path = os.path.join(self.owner.dependencies_directory, apk_name) with lock_file(host_path, timeout=self.install_timeout): self.target.pull(package_info.apk_path, host_path, timeout=self.install_timeout) return host_path
def apk_abi_matches(path, supported_abi, exact_abi=False): supported_abi = list_or_string(supported_abi) with lock_file(path): info = ApkInfo(path) # If no native code present, suitable for all devices. if not info.native_code: return True if exact_abi: # Only check primary return supported_abi[0] in info.native_code else: for abi in supported_abi: if abi in info.native_code: return True return False
def download_asset(self, asset, owner_name): url = urljoin(self.url, owner_name, asset['path']) local_path = _f( os.path.join(settings.dependencies_directory, '__remote', owner_name, asset['path'].replace('/', os.sep))) with lock_file(local_path, timeout=5 * 60): if os.path.exists(local_path) and not self.always_fetch: local_sha = sha256(local_path) if local_sha == asset['sha256']: self.logger.debug( 'Local SHA256 matches; not re-downloading') return local_path self.logger.debug('Downloading {}'.format(url)) response = self.geturl(url, stream=True) if response.status_code != http.client.OK: message = 'Could not download asset "{}"; recieved "{} {}"' self.logger.warning( message.format(url, response.status_code, response.reason)) return with open(local_path, 'wb') as wfh: for chunk in response.iter_content(chunk_size=self.chunk_size): wfh.write(chunk) return local_path
def setup(self, context): if hasattr(context.workload, 'apk_file'): with lock_file(context.workload.apk_file): self.apk_info = ApkInfo(context.workload.apk_file) else: self.apk_info = None
def package_name_matches(path, package): with lock_file(path): info = ApkInfo(path) return info.package == package
def uiauto_test_matches(path, uiauto): with lock_file(path): info = ApkInfo(path) return uiauto == ('com.arm.wa.uiauto' in info.package)
def apk_version_matches_range(path, min_version=None, max_version=None): with lock_file(path): info = ApkInfo(path) return range_version_matching(info.version_name, min_version, max_version)
def write_target_info_cache(cache): if not os.path.exists(settings.cache_directory): os.makedirs(settings.cache_directory) with lock_file(settings.target_info_cache_file): write_pod(cache, settings.target_info_cache_file)