]> Cypherpunks.ru repositories - gocheese.git/blob - metadata.go
More convenient trusted-host
[gocheese.git] / metadata.go
1 // GoCheese -- Python private package repository and caching proxy
2 // Copyright (C) 2019-2024 Sergey Matveev <stargrave@stargrave.org>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package main
17
18 const (
19         MDFile = ".metadata.rec"
20
21         // https://packaging.python.org/specifications/core-metadata/
22         MDVersion                     = "2.1"
23         MDFieldMetadataVersion        = "Metadata-Version"
24         MDFieldName                   = "Name"
25         MDFieldVersion                = "Version"
26         MDFieldDescription            = "Description"
27         MDFieldPlatform               = "Platform"
28         MDFieldSupportedPlatform      = "Supported-Platform"
29         MDFieldSummary                = "Summary"
30         MDFieldDescriptionContentType = "Description-Content-Type"
31         MDFieldKeywords               = "Keywords"
32         MDFieldHomePage               = "Home-page"
33         MDFieldAuthor                 = "Author"
34         MDFieldAuthorEmail            = "Author-email"
35         MDFieldMaintainer             = "Maintainer"
36         MDFieldMaintainerEmail        = "Maintainer-email"
37         MDFieldLicense                = "License"
38         MDFieldRequiresDist           = "Requires-Dist"
39         MDFieldRequiresPython         = "Requires-Python"
40         MDFieldRequiresExternal       = "Requires-External"
41         MDFieldProjectURL             = "Project-URL"
42         MDFieldProvidesExtra          = "Provides-Extra"
43         MDFieldClassifier             = "Classifier"
44 )
45
46 var (
47         MDFieldToRecField = map[string]string{
48                 MDFieldMetadataVersion:        "MetadataVersion",
49                 MDFieldName:                   "Name",
50                 MDFieldVersion:                "Version",
51                 MDFieldDescription:            "Description",
52                 MDFieldPlatform:               "Platform",
53                 MDFieldSupportedPlatform:      "SupportedPlatform",
54                 MDFieldSummary:                "Summary",
55                 MDFieldDescriptionContentType: "DescriptionContentType",
56                 MDFieldKeywords:               "Keywords",
57                 MDFieldHomePage:               "HomePage",
58                 MDFieldAuthor:                 "Author",
59                 MDFieldAuthorEmail:            "AuthorEmail",
60                 MDFieldMaintainer:             "Maintainer",
61                 MDFieldMaintainerEmail:        "MaintainerEmail",
62                 MDFieldLicense:                "License",
63                 MDFieldRequiresDist:           "RequiresDist",
64                 MDFieldRequiresPython:         "RequiresPython",
65                 MDFieldRequiresExternal:       "RequiresExternal",
66                 MDFieldProjectURL:             "ProjectURL",
67                 MDFieldProvidesExtra:          "ProvidesExtra",
68                 MDFieldClassifier:             "Classifier",
69         }
70         MDFormToRecField = [][2]string{
71                 {"name", MDFieldToRecField[MDFieldName]},
72                 {"version", MDFieldToRecField[MDFieldVersion]},
73                 {"platform", MDFieldToRecField[MDFieldPlatform]},
74                 {"supported_platform", MDFieldToRecField[MDFieldSupportedPlatform]},
75                 {"summary", MDFieldToRecField[MDFieldSummary]},
76                 {"description", MDFieldToRecField[MDFieldDescription]},
77                 {"description_content_type", MDFieldToRecField[MDFieldDescriptionContentType]},
78                 {"keywords", MDFieldToRecField[MDFieldKeywords]},
79                 {"home_page", MDFieldToRecField[MDFieldHomePage]},
80                 {"author", MDFieldToRecField[MDFieldAuthor]},
81                 {"author_email", MDFieldToRecField[MDFieldAuthorEmail]},
82                 {"maintainer", MDFieldToRecField[MDFieldMaintainer]},
83                 {"maintainer_email", MDFieldToRecField[MDFieldMaintainerEmail]},
84                 {"license", MDFieldToRecField[MDFieldLicense]},
85                 {"classifiers", MDFieldToRecField[MDFieldClassifier]},
86                 {"requires_dist", MDFieldToRecField[MDFieldRequiresDist]},
87                 {"requires_python", MDFieldToRecField[MDFieldRequiresPython]},
88                 {"requires_external", MDFieldToRecField[MDFieldRequiresExternal]},
89                 {"project_url", MDFieldToRecField[MDFieldProjectURL]},
90                 {"provides_extra", MDFieldToRecField[MDFieldProvidesExtra]},
91         }
92 )
93
94 // It should follow https://www.python.org/dev/peps/pep-0566/
95 type PkgInfo struct {
96         Name                   string   `json:"name"`
97         Version                string   `json:"version"`
98         Platform               []string `json:"platform,omitempty"`
99         SupportedPlatform      []string `json:"supported_platform,omitempty"`
100         Summary                string   `json:"summary,omitempty"`
101         Description            string   `json:"description,omitempty"`
102         DescriptionContentType string   `json:"description_content_type,omitempty"`
103         Keywords               string   `json:"keywords,omitempty"`
104         HomePage               string   `json:"home_page,omitempty"`
105         Author                 string   `json:"author,omitempty"`
106         AuthorEmail            string   `json:"author_email,omitempty"`
107         Maintainer             string   `json:"maintainer,omitempty"`
108         MaintainerEmail        string   `json:"maintainer_email,omitempty"`
109         License                string   `json:"license,omitempty"`
110         Classifier             []string `json:"classifier,omitempty"`
111         RequiresDist           []string `json:"requires_dist,omitempty"`
112         RequiresPython         string   `json:"requires_python,omitempty"`
113         RequiresExternal       []string `json:"requires_external,omitempty"`
114         ProjectURL             []string `json:"project_url,omitempty"`
115         ProvidesExtra          []string `json:"provides_extra,omitempty"`
116 }
117
118 // But current PyPI does not follow PEP-0566, so just ignore some fields
119 type PkgInfoStripped struct {
120         Name                   string   `json:"name"`
121         Version                string   `json:"version"`
122         Summary                string   `json:"summary,omitempty"`
123         Description            string   `json:"description,omitempty"`
124         DescriptionContentType string   `json:"description_content_type,omitempty"`
125         Keywords               string   `json:"keywords,omitempty"`
126         HomePage               string   `json:"home_page,omitempty"`
127         Author                 string   `json:"author,omitempty"`
128         AuthorEmail            string   `json:"author_email,omitempty"`
129         Maintainer             string   `json:"maintainer,omitempty"`
130         MaintainerEmail        string   `json:"maintainer_email,omitempty"`
131         License                string   `json:"license,omitempty"`
132         Classifier             []string `json:"classifiers,omitempty"`
133         RequiresPython         string   `json:"requires_python,omitempty"`
134         RequiresDist           []string `json:"requires_dist,omitempty"`
135 }
136
137 // Unknown format: no detailed specification available
138 // https://github.com/cooperlees/peps/blob/warehouse_json_api/pep-9999.rst
139 type PkgReleaseInfo struct {
140         Filename          string `json:"filename"`
141         Version           string `json:"version"`
142         UploadTimeISO8601 string `json:"upload_time_iso_8601"`
143         Size              int64  `json:"size"`
144         HasSig            bool   `json:"has_sig"`
145
146         Digests map[string]string `json:"digests"`
147 }
148
149 type PkgMeta struct {
150         Info       PkgInfo                      `json:"info"`
151         LastSerial int64                        `json:"last_serial"`
152         Releases   map[string][]*PkgReleaseInfo `json:"releases"`
153         URLs       []*PkgReleaseInfo            `json:"urls"`
154 }
155
156 type PkgMetaStripped struct {
157         Info     PkgInfoStripped              `json:"info"`
158         Releases map[string][]*PkgReleaseInfo `json:"releases"`
159 }