2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 HRRootTmpl = template.Must(template.New("hr-root").Parse(`<!DOCTYPE html>
35 <title>{{.Version}}: packages</title>
38 <ul>{{range .Packages}}
39 <li><a href="/hr/{{.}}/">{{.}}</a></li>
45 HRPkgTmpl = template.Must(template.New("hr-pkg").Parse(`<!DOCTYPE html>
48 <title>{{.Version}}: package {{.PkgName}}</title>
52 {{with .Info.Name}}<dt>Name</dt><dd>{{.}}</dd>{{end}}
53 {{with .Info.Version}}<dt>Version</dt><dd>{{.}}</dd>{{end}}
55 {{with .Info.Platform}}<dt>Platform</dt><dd><ul>
56 {{range .}}<li>{{.}}</li>
57 {{end}}</ul></dd>{{end}}
59 {{with .Info.SupportedPlatform}}<dt>SupportedPlatform</dt><dd><ul>
60 {{range .}}<li>{{.}}</li>
61 {{end}}</ul></dd>{{end}}
63 <dt>Summary</dt><dd>{{.Info.Summary}}</dd>
64 <dt>Description</dt><dd><pre>
68 {{with .Info.DescriptionContentType}}<dt>DescriptionContentType</dt><dd>{{.}}</dd>{{end}}
69 {{with .Info.Keywords}}<dt>Keywords</dt><dd>{{.}}</dd>{{end}}
70 {{with .Info.HomePage}}<dt>HomePage</dt><dd>{{.}}</dd>{{end}}
71 {{with .Info.Author}}<dt>Author</dt><dd>{{.}}</dd>{{end}}
72 {{with .Info.AuthorEmail}}<dt>AuthorEmail</dt><dd>{{.}}</dd>{{end}}
73 {{with .Info.Maintainer}}<dt>Maintainer</dt><dd>{{.}}</dd>{{end}}
74 {{with .Info.MaintainerEmail}}<dt>MaintainerEmail</dt><dd>{{.}}</dd>{{end}}
75 {{with .Info.License}}<dt>License</dt><dd>{{.}}</dd>{{end}}
77 {{with .Info.Classifier}}<dt>Classifier</dt><dd><ul>
78 {{range .}}<li>{{.}}</li>
79 {{end}}</ul></dd>{{end}}
81 {{with .Info.RequiresDist}}<dt>RequiresDist</dt><dd><ul>
82 {{range .}}<li>{{.}}</li>
83 {{end}}</ul></dd>{{end}}
85 {{with .Info.RequiresPython}}<dt>RequiresPython</dt><dd>{{.}}</dd>{{end}}
87 {{with .Info.RequiresExternal}}<dt>RequiresExternal</dt><dd><ul>
88 {{range .}}<li>{{.}}</li>
89 {{end}}</ul></dd>{{end}}
91 {{with .Info.ProjectURL}}<dt>ProjectURL</dt><dd><ul>
92 {{range .}}<li>{{.}}</li>
93 {{end}}</ul></dd>{{end}}
95 {{with .Info.ProvidesExtra}}<dt>ProvidesExtra</dt><dd><ul>
96 {{range .}}<li>{{.}}</li>
97 {{end}}</ul></dd>{{end}}
109 {{range .Releases}}{{if .Size}}
111 <td>{{.Filename}}</th>
112 <td>{{.Version}}</th>
113 <td>{{.UploadTimeISO8601}}</th>
115 <td><ul>{{range $a, $d := .Digests}}
116 <li>{{$a}}: <tt>{{$d}}</tt></li>
125 func serveHRRoot(w http.ResponseWriter, r *http.Request) {
126 files, err := ioutil.ReadDir(Root)
128 log.Println("error", r.RemoteAddr, "hr-root", err)
129 http.Error(w, err.Error(), http.StatusInternalServerError)
132 packages := make([]string, 0, len(files))
133 for _, f := range files {
134 packages = append(packages, f.Name())
136 sort.Strings(packages)
138 err = HRRootTmpl.Execute(&buf, struct {
146 log.Println("error", r.RemoteAddr, "hr-root", err)
147 http.Error(w, err.Error(), http.StatusInternalServerError)
153 func serveHRPkg(w http.ResponseWriter, r *http.Request) {
154 cols := strings.Split(strings.TrimRight(r.URL.Path, "/"), "/")
155 pkgName := cols[len(cols)-1]
156 meta, releases, err := getMetadata(pkgName, "")
158 if os.IsNotExist(err) {
161 log.Println("error", r.RemoteAddr, "json", pkgName, err)
162 http.Error(w, err.Error(), http.StatusInternalServerError)
167 err = HRPkgTmpl.Execute(&buf, struct {
171 Releases []*PkgReleaseInfo
179 log.Println("error", r.RemoteAddr, "root", err)
180 http.Error(w, err.Error(), http.StatusInternalServerError)