def badge_version_for_repo(repo: str, name: str) -> Any: if repo not in repometadata.all_names(): flask.abort(404) args = flask.request.args.to_dict() best_package = packageset_to_best(get_db().get_metapackage_packages( name, repo=repo, fields=['repo', 'version', 'versionclass']), allow_ignored=args.get( 'allow_ignored', False)) left_cell = BadgeCell(flask.request.args.to_dict().get( 'header', repometadata[repo]['singular']), collapsible=True) if best_package is None: # Note: it would be more correct to return 404 with content here, # but some browsers (e.g. Firefox) won't display the image in that case right_cell = BadgeCell('-') else: minversion = flask.request.args.to_dict().get('minversion') unsatisfying = minversion and version_compare(best_package.version, minversion) < 0 right_cell = BadgeCell(best_package.version, badge_color(best_package.versionclass, unsatisfying), truncate=20) return render_generic_badge([[left_cell, right_cell]])
def badge_vertical_allrepos(name: str) -> Any: args = flask.request.args.to_dict() packages = get_db().get_metapackage_packages( name, fields=['repo', 'version', 'versionclass']) best_pkg_by_repo = packageset_to_best_by_repo(packages, allow_ignored=args.get( 'allow_ignored', False)) header = args.get('header') minversion = args.get('minversion') cells = [] for reponame in repometadata.active_names(): if reponame in best_pkg_by_repo: version = best_pkg_by_repo[reponame].version versionclass = best_pkg_by_repo[reponame].versionclass unsatisfying = minversion and version_compare(version, minversion) < 0 color = badge_color(versionclass, unsatisfying) cells.append([ BadgeCell(repometadata[reponame]['desc'], align='r'), BadgeCell(version, color=color, truncate=13, minwidth=60) ]) if header is None: header = 'Packaging status' if cells else 'No known packages' return render_generic_badge(cells, header=header)
def badge_latest_versions(name: str) -> Any: versions = sorted(set( (package.version for package in get_db().get_metapackage_packages( name, fields=['version', 'versionclass']) if package.versionclass in (PackageStatus.NEWEST, PackageStatus.DEVEL, PackageStatus.UNIQUE))), key=cmp_to_key(version_compare), reverse=True) default_caption = 'latest packaged version' if len(versions) > 1: default_caption += 's' text = ', '.join(versions) elif versions: text = versions[0] else: text = '-' caption = flask.request.args.to_dict().get('header', default_caption) return render_generic_badge([[ BadgeCell(caption, collapsible=True), BadgeCell(text, '#007ec6'), ]])
def badge_tiny_repos(name: str) -> Any: return render_generic_badge([[ BadgeCell(flask.request.args.to_dict().get('header', 'in repositories'), collapsible=True), BadgeCell(str(get_db().get_metapackage_families_count(name)), '#007ec6'), ]])
def badge_vertical_allrepos(name: str) -> Response: args = flask.request.args.to_dict() best_pkg_by_repo = packageset_to_best_by_repo( (PackageDataMinimal(**item) for item in get_db().get_metapackage_packages(name, minimal=True)), allow_ignored=args.get('allow_ignored', False)) header = args.get('header') minversion = args.get('minversion') repo_filter = RepositoryFilter(args) cells = [] for reponame in repometadata.active_names(): if not repo_filter.check(reponame): continue if reponame in best_pkg_by_repo: version = best_pkg_by_repo[reponame].version versionclass = best_pkg_by_repo[reponame].versionclass unsatisfying = minversion and version_compare(version, minversion) < 0 color = badge_color(versionclass, unsatisfying) cells.append([ BadgeCell(repometadata[reponame]['desc'], align='r'), BadgeCell(version, color=color, truncate=13, minwidth=60) ]) try: columns = min(int(args.get('columns', '1')), len(cells)) except: columns = 1 if columns > 1: chunks = [] columnsize = (len(cells) + columns - 1) // columns for column in range(columns): chunks.append(cells[column * columnsize:column * columnsize + columnsize]) empty_filler = [BadgeCell(''), BadgeCell('')] cells = [ sum(cells, []) for cells in zip_longest(*chunks, fillvalue=empty_filler) ] if header is None: header = 'Packaging status' if cells else 'No known packages' return render_generic_badge(cells, header=header)
def badge_versions_matrix() -> Any: args = flask.request.args.to_dict() header = args.get('header') # parse requirements required_projects: Dict[str, Optional[Tuple[str, str]]] = {} for project in args.get('projects', '').split(','): match = re.fullmatch('(.*?)(>=?|<=?)(.*?)', project) if match is not None: required_projects[match.group(1)] = (match.group(2), match.group(3)) else: required_projects[project] = None required_repos = set( args.get('repos').split(',')) if 'repos' in args else None require_all = args.get('require_all', False) # get and process packages packages = get_db().get_metapackages_packages( list(required_projects.keys()), fields=['effname', 'repo', 'version', 'versionclass']) packages_by_project: Dict[str, List[Package]] = defaultdict(list) repos = set() for package in packages: packages_by_project[package.effname].append(package) repos.add(package.repo) best_packages_by_project = { effname: packageset_to_best_by_repo(packages) for effname, packages in packages_by_project.items() } if required_repos is not None: repos = repos & required_repos # construct table cells = [[BadgeCell()]] for name in required_projects.keys(): cells[0].append(BadgeCell(name)) for repo in repometadata.sorted_active_names(repos): row = [BadgeCell(repometadata[repo]['desc'], align='r')] for effname, restriction in required_projects.items(): if effname not in best_packages_by_project or repo not in best_packages_by_project[ effname]: # project not found in repo row.append(BadgeCell('-')) if require_all: break else: continue package = best_packages_by_project[effname][repo] unsatisfying = False if restriction is not None: if restriction[0] == '>': unsatisfying = version_compare(package.version, restriction[1]) <= 0 elif restriction[0] == '>=': unsatisfying = version_compare(package.version, restriction[1]) < 0 elif restriction[0] == '<': unsatisfying = version_compare(package.version, restriction[1]) >= 0 elif restriction[0] == '<=': unsatisfying = version_compare(package.version, restriction[1]) > 0 color = badge_color(package.versionclass, unsatisfying) row.append( BadgeCell(package.version, color=color, truncate=13, minwidth=60)) else: cells.append(row) return render_generic_badge(cells, header=header)