async def get_version_impl(info): conf = dict(info) url = conf['url'] header = conf.get('header', 'Location') follow_redirects = conf.get('follow_redirects', False) method = conf.get('method', 'HEAD') try: regex = re.compile(conf['regex']) except sre_constants.error as e: raise GetVersionError('bad regex', exc_info=e) res = await session.request( url, method=method, follow_redirects=follow_redirects, ) header_value = res.headers.get(header) if not header_value: raise GetVersionError('header %s not found or is empty' % header) try: version = regex.findall(header_value) except ValueError: raise GetVersionError('version string not found.') return version
async def get_version(name, conf, *, cache, **kwargs): pkgname = conf.get('alpm', name) dbpath = conf.get('dbpath', '/var/lib/pacman') strip_release = conf.get('strip_release', False) provided = conf.get('provided') repo = conf.get('repo') if repo is None: repos = ['core', 'extra', 'community', 'multilib'] else: repos = [repo] for repo in repos: db = (await cache.get((dbpath, repo), open_db))[1] pkg = db.get_pkg(pkgname) if pkg is not None: break if pkg is None: raise GetVersionError('package not found in the ALPM database') if provided is None: version = pkg.version else: provides = dict(x.split('=', 1) for x in pkg.provides if '=' in x) version = provides.get(provided) if version is None: raise GetVersionError('provides element not found') if strip_release: version = version.split('-', 1)[0] return version
async def get_version_impl(info): conf = dict(info) encoding = conf.get('encoding') parser = html.HTMLParser(encoding=encoding) data = conf.get('post_data') if data is None: res = await session.get(conf['url']) else: res = await session.post(conf['url'], body=data, headers={ 'Content-Type': conf.get( 'post_data_type', 'application/x-www-form-urlencoded') }) doc = html.fromstring(res.body, base_url=conf['url'], parser=parser) try: version = doc.xpath(conf.get('xpath')) except ValueError: if not conf.get('missing_ok', False): raise GetVersionError('version string not found.') except etree.XPathEvalError as e: raise GetVersionError('bad xpath', exc_info=e) return version
async def get_latest_tag(key: Tuple[str, str, str]) -> str: repo, query, token = key owner, reponame = repo.split('/') headers = { 'Authorization': f'bearer {token}', 'Content-Type': 'application/json', } q = QUERY_LATEST_TAG.format( owner=owner, name=reponame, query=query, ) res = await session.post( GITHUB_GRAPHQL_URL, headers=headers, json={'query': q}, ) j = res.json() refs = j['data']['repository']['refs']['edges'] if not refs: raise GetVersionError('no tag found') return refs[0]['node']['name']
async def get_version_impl(info): conf = dict(info) encoding = conf.get('encoding') parser = html.HTMLParser(encoding=encoding) res = await session.get(conf['url']) doc = html.fromstring(res.body, base_url=conf['url'], parser=parser) try: version = doc.xpath(conf.get('xpath')) except ValueError: if not conf.get('missing_ok', False): raise GetVersionError('version string not found.') except etree.XPathEvalError as e: raise GetVersionError('bad xpath', exc_info=e) return version
async def _run_batch_impl( batch: List[Tuple[str, Entry]], aur_results: AurResults, ) -> Dict[str, VersionResult]: aurnames = {conf.get('aur', name) for name, conf in batch} results = await aur_results.get_multiple(aurnames) ret: Dict[str, VersionResult] = {} for name, conf in batch: aurname = conf.get('aur', name) use_last_modified = conf.get('use_last_modified', False) strip_release = conf.get('strip_release', False) result = results.get(aurname) if result is None: ret[name] = GetVersionError('AUR upstream not found') continue version = result['Version'] if use_last_modified: version += '-' + datetime.utcfromtimestamp( result['LastModified']).strftime('%Y%m%d%H%M%S') if strip_release and '-' in version: version = version.rsplit('-', 1)[0] ret[name] = version return ret
async def get_version_impl(info): conf = dict(info) try: regex = re.compile(conf['regex']) except sre_constants.error as e: raise GetVersionError('bad regex', exc_info=e) encoding = conf.get('encoding', 'latin1') res = await session.get(conf['url']) body = res.body.decode(encoding) try: version = regex.findall(body) except ValueError: if not conf.get('missing_ok', False): raise GetVersionError('version string not found.') return version
async def get_version( name: str, conf: Entry, *, cache: AsyncCache, keymanager: KeyManager, **kwargs, ) -> VersionResult: srcpkg = conf.get('srcpkg') pkg = conf.get('pkg') mirror = conf['mirror'] suite = conf['suite'] repo = conf.get('repo', 'main') arch = conf.get('arch', 'amd64') strip_release = conf.get('strip_release', False) if srcpkg and pkg: raise GetVersionError('Setting both srcpkg and pkg is ambigious') elif not srcpkg and not pkg: pkg = name apt_release = await cache.get(APT_RELEASE_URL % (mirror, suite), get_url) # type: ignore for suffix in APT_PACKAGES_SUFFIX_PREFER: packages_path = APT_PACKAGES_PATH % (repo, arch, suffix) if " " + packages_path in apt_release: break else: raise GetVersionError('Packages file not found in APT repository') pkg_map, srcpkg_map = await cache.get( (cache, APT_PACKAGES_URL % (mirror, suite, packages_path)), parse_packages) # type: ignore if pkg and pkg in pkg_map: version = pkg_map[pkg] elif srcpkg and srcpkg in srcpkg_map: version = srcpkg_map[srcpkg] else: raise GetVersionError('package not found in APT repository') if strip_release: version = version.split("-")[0] return version
async def get_version(name, conf, *, cache, **kwargs): package = conf.get('cran', name) desc = await cache.get(package, request) for line in desc.splitlines(): if line.startswith(VERSION_FIELD): version = line[len(VERSION_FIELD):] break else: raise GetVersionError('Invalid DESCRIPTION file') return version
async def run_cmd(cmd: str) -> str: logger.debug('running cmd', cmd=cmd) p = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) output, error = await p.communicate() output_s = output.strip().decode('latin1') error_s = error.strip().decode(errors='replace') if p.returncode != 0: raise GetVersionError('command exited with error', cmd=cmd, error=error_s, returncode=p.returncode) elif not output_s: raise GetVersionError('command exited without output', cmd=cmd, error=error_s, returncode=p.returncode) else: return output_s
async def get_version(name, conf, *, cache, **kwargs): project = conf.get('repology') or name repo = conf.get('repo') subrepo = conf.get('subrepo') if not repo: raise GetVersionError('repo field is required for repology source') url = API_URL.format(project) data = await cache.get_json(url) pkgs = [pkg for pkg in data if pkg['repo'] == repo] if not pkgs: raise GetVersionError('package is not found', repo=repo) if subrepo: pkgs = [pkg for pkg in pkgs if pkg.get('subrepo') == subrepo] if not pkgs: raise GetVersionError('package is not found in subrepo', repo=repo, subrepo=subrepo) versions = [pkg['version'] for pkg in pkgs] return versions
async def get_version_impl(info): conf = dict(info) try: regex = re.compile(conf['regex']) except sre_constants.error as e: raise GetVersionError('bad regex', exc_info=e) if regex.groups > 1: raise GetVersionError('multi-group regex') encoding = conf.get('encoding', 'latin1') data = conf.get('post_data') if data is None: res = await session.get(conf['url']) else: res = await session.post(conf['url'], body = data, headers = { 'Content-Type': conf.get('post_data_type', 'application/x-www-form-urlencoded') }) body = res.body.decode(encoding) versions = regex.findall(body) if not versions and not conf.get('missing_ok', False): raise GetVersionError('version string not found.') return versions
async def get_version(name, conf, *, cache, **kwargs): pkg = conf.get('debianpkg') or name strip_release = conf.get('strip_release', False) suite = conf.get('suite') or "sid" url = URL % {"pkgname": pkg, "suite": suite} data = await cache.get_json(url) if not data.get('versions'): raise GetVersionError('Debian package not found') r = data['versions'][0] if strip_release: version = r['version'].split("-")[0] else: version = r['version'] return version
async def run_cmd(cmd): p = await asyncio.create_subprocess_exec( *cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) output, error = await asyncio.wait_for(p.communicate(), 20) output = output.strip().decode('latin1') error = error.strip().decode('latin1') if p.returncode != 0: raise GetVersionError('command exited with error', output=output, returncode=p.returncode, error=error) else: return output
async def get_version(name, conf, *, cache, **kwargs): pkg = conf.get('archpkg') or name strip_release = conf.get('strip_release', False) provided = conf.get('provided') data = await cache.get(pkg, request) if not data['results']: raise GetVersionError('Arch package not found') r = [r for r in data['results'] if r['repo'] != 'testing'][0] if provided: provides = dict(x.split('=', 1) for x in r['provides'] if '=' in x) version = provides.get(provided, None) if strip_release: version = version.split('-', 1)[0] elif strip_release: version = r['pkgver'] else: version = r['pkgver'] + '-' + r['pkgrel'] return version
async def run(self) -> None: exc = GetVersionError('no source specified') async with self.task_sem: for name, conf in self.tasks: await self.result_q.put( RawResult(name, exc, conf))
async def get_version_real( name: str, conf: Entry, *, cache: AsyncCache, keymanager: KeyManager, **kwargs, ) -> VersionResult: repo = conf['github'] # Load token from config token = conf.get('token') # Load token from keyman if token is None: token = keymanager.get_key('github') use_latest_tag = conf.get('use_latest_tag', False) if use_latest_tag: if not token: raise GetVersionError('token not given but it is required') query = conf.get('query', '') return await cache.get((repo, query, token), get_latest_tag) # type: ignore br = conf.get('branch') path = conf.get('path') use_latest_release = conf.get('use_latest_release', False) use_max_tag = conf.get('use_max_tag', False) if use_latest_release: url = GITHUB_LATEST_RELEASE % repo elif use_max_tag: url = GITHUB_MAX_TAG % repo else: url = GITHUB_URL % repo parameters = {} if br: parameters['sha'] = br if path: parameters['path'] = path url += '?' + urlencode(parameters) headers = { 'Accept': 'application/vnd.github.quicksilver-preview+json', } if token: headers['Authorization'] = f'token {token}' data = await cache.get_json(url, headers=headers) if use_max_tag: tags = [ref['ref'].split('/', 2)[-1] for ref in data] if not tags: raise GetVersionError('No tag found in upstream repository.') return tags if use_latest_release: if 'tag_name' not in data: raise GetVersionError('No release found in upstream repository.') version = data['tag_name'] else: # YYYYMMDD.HHMMSS version = data[0]['commit']['committer']['date'] \ .rstrip('Z').replace('-', '').replace(':', '').replace('T', '.') return version