def test_relpath(self, url, path, expected): test_url = URL("http://example.com" + url) relpath = test_url.relpath(path) assert relpath == expected test_url = URL("http://example.com" + url + "foo=bar") relpath = test_url.relpath(path) assert relpath == expected
def _simple_list_project(self, stage, project, result, embed_form, blocked_index): response = self.request.response response.content_type = "text/html ; charset=utf-8" title = "%s: links for %s" % (stage.name, project) yield ("<html><head><title>%s</title></head><body><h1>%s</h1>\n" % (title, title)).encode("utf-8") if embed_form: yield self._index_refresh_form(stage, project).encode("utf-8") if blocked_index: yield ("<p><strong>INFO:</strong> Because this project isn't in " "the <code>mirror_whitelist</code>, no releases from " "<strong>%s</strong> are included.</p>" % blocked_index).encode('utf-8') url = URL(self.request.path_info) for key, href in result: yield ('%s <a href="%s">%s</a><br/>\n' % ("/".join(href.split("/", 2)[:2]), url.relpath("/" + href), key)).encode("utf-8") yield "</body></html>".encode("utf-8")
def test_relpath(self, url, path, expected): url = URL("http://example.com" + url) relpath = url.relpath(path) assert relpath == expected
def indexroot(self, user, index): stage = self.getstage(user, index) if json_preferred(): projectlist = stage.getprojectnames_perstage() projectlist = sorted(projectlist) apireturn(200, type="list:projectconfig", result=projectlist) if stage.name == "root/pypi": return simple_html_body("%s index" % stage.name, [ html.ul( html.li(html.a("simple index", href="+simple/")), ), ]).unicode() # XXX this should go to a template if hasattr(stage, "ixconfig"): bases = html.ul() for base in stage.ixconfig["bases"]: bases.append(html.li( html.a("%s" % base, href="/%s/" % base), " (", html.a("simple", href="/%s/+simple/" % base), " )", )) if bases: bases = [html.h2("inherited bases"), bases] else: bases = [] latest_packages = html.table( html.tr(html.td("info"), html.td("file"), html.td("docs"))) for projectname in stage.getprojectnames_perstage(): metadata = stage.get_metadata_latest(projectname) try: name, ver = metadata["name"], metadata["version"] except KeyError: log.error("metadata for project %r empty: %s, skipping", projectname, metadata) continue dockey = stage._doc_key(name, ver) if dockey.exists(): docs = [html.a("%s-%s docs" %(name, ver), href="%s/%s/+doc/index.html" %(name, ver))] else: docs = [] files = metadata.get("+files", {}) if not files: log.warn("project %r version %r has no files", projectname, metadata.get("version")) baseurl = URL(request.path) for basename, relpath in files.items(): latest_packages.append(html.tr( html.td(html.a("%s-%s info page" % (name, ver), href="%s/%s/" % (name, ver))), html.td(html.a(basename, href=baseurl.relpath("/" + relpath))), html.td(*docs), )) break # could present more releasefiles latest_packages = [ html.h2("in-stage latest packages, at least as recent as bases"), latest_packages] return simple_html_body("%s index" % stage.name, [ html.ul( html.li(html.a("simple index", href="+simple/")), ), latest_packages, bases, ]).unicode()
def indexroot(self, user, index): stage = self.getstage(user, index) if json_preferred(): projectlist = stage.getprojectnames_perstage() projectlist = sorted(projectlist) apireturn(200, type="list:projectconfig", result=projectlist) if stage.name == "root/pypi": return simple_html_body("%s index" % stage.name, [ html.ul(html.li(html.a("simple index", href="+simple/")), ), ]).unicode() # XXX this should go to a template if hasattr(stage, "ixconfig"): bases = html.ul() for base in stage.ixconfig["bases"]: bases.append( html.li( html.a("%s" % base, href="/%s/" % base), " (", html.a("simple", href="/%s/+simple/" % base), " )", )) if bases: bases = [html.h2("inherited bases"), bases] else: bases = [] latest_packages = html.table( html.tr(html.td("info"), html.td("file"), html.td("docs"))) for projectname in stage.getprojectnames_perstage(): metadata = stage.get_metadata_latest(projectname) try: name, ver = metadata["name"], metadata["version"] except KeyError: log.error("metadata for project %r empty: %s, skipping", projectname, metadata) continue dockey = stage._doc_key(name, ver) if dockey.exists(): docs = [ html.a("%s-%s docs" % (name, ver), href="%s/%s/+doc/index.html" % (name, ver)) ] else: docs = [] files = metadata.get("+files", {}) if not files: log.warn("project %r version %r has no files", projectname, metadata.get("version")) baseurl = URL(request.path) for basename, relpath in files.items(): latest_packages.append( html.tr( html.td( html.a("%s-%s info page" % (name, ver), href="%s/%s/" % (name, ver))), html.td( html.a(basename, href=baseurl.relpath("/" + relpath))), html.td(*docs), )) break # could present more releasefiles latest_packages = [ html.h2("in-stage latest packages, at least as recent as bases"), latest_packages ] return simple_html_body("%s index" % stage.name, [ html.ul(html.li(html.a("simple index", href="+simple/")), ), latest_packages, bases, ]).unicode()