Beispiel #1
0
def fetch_generate_page(dir, package):
    finder = PackageFinder([], []) # these args are not really used
    req = InstallRequirement(package, None)
    page_versions = []
    out_html = []

    for p in finder._get_pages([Link("%s/%s" % (PYPI_URL, package))], req):
        page_versions.extend(finder._package_versions(p.links, req.name.lower()))

    if not page_versions:
        # nothing found - maybe no such package
        return ''

    seen_archive_names = set()
    for _parsed_version, link, version in page_versions:
        archive_name, real_url, fragment = parse_link_url(link.url)
        archive_name = alt_filename(archive_name, seen_archive_names)
        with open("%s/%s.url" % (dir, archive_name), "w") as f:
            f.write(real_url)

        if fragment:
            fragment = "#%s" % fragment
        out_html.append('<a href="%s%s">%s</a>' % (archive_name, fragment, version))

    return "<html><head><title>Links for %s</title></head><body><h1>Links for %s</h1>%s</body></html>" % (
        package,
        package,
        '\n'.join(out_html))
def get_versions(package):
    host = "https://pypi.python.org/simple/"
    url = urlparse.urljoin(host, package)
    url = url + '/'
    session = PipSession()
    session.timeout = 15
    session.auth.prmpting = True
    pf = PackageFinder(find_links=[], index_urls=host, use_wheel=True, allow_external=[], allow_unverified=[], allow_all_external=False, allow_all_prereleases=False, process_dependency_links=False, session=session,)

    location = [Link(url, trusted=True)]
    req = InstallRequirement.from_line(package, None)
    versions = []
    for page in pf._get_pages(location, req):
        versions = versions + [version for _, _, version in pf._package_versions(page.links, package)]
    return versions