]> Cypherpunks.ru repositories - gocheese.git/blobdiff - metadata.go
More convenient trusted-host
[gocheese.git] / metadata.go
index 87ff48a1df93d96e6f75881f6676f5c0bc0ac43c..8959002953565adbf5829df6e5163eca430a1f89 100644 (file)
@@ -1,55 +1,95 @@
-/*
-GoCheese -- Python private package repository and caching proxy
-Copyright (C) 2019-2021 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// GoCheese -- Python private package repository and caching proxy
+// Copyright (C) 2019-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package main
 
-import "strings"
-
 const (
-       MetadataFile = ".metadata.rec"
+       MDFile = ".metadata.rec"
 
        // https://packaging.python.org/specifications/core-metadata/
-       MetadataVersion                     = "2.1"
-       MetadataFieldMetadataVersion        = "Metadata-Version"
-       MetadataFieldName                   = "Name"
-       MetadataFieldVersion                = "Version"
-       MetadataFieldDescription            = "Description"
-       MetadataFieldPlatform               = "Platform"
-       MetadataFieldSupportedPlatform      = "Supported-Platform"
-       MetadataFieldSummary                = "Summary"
-       MetadataFieldDescriptionContentType = "Description-Content-Type"
-       MetadataFieldKeywords               = "Keywords"
-       MetadataFieldHomePage               = "Home-page"
-       MetadataFieldAuthor                 = "Author"
-       MetadataFieldAuthorEmail            = "Author-email"
-       MetadataFieldMaintainer             = "Maintainer"
-       MetadataFieldMaintainerEmail        = "Maintainer-Email"
-       MetadataFieldLicense                = "License"
-       MetadataFieldRequiresDist           = "Requires-Dist"
-       MetadataFieldRequiresPython         = "Requires-Python"
-       MetadataFieldRequiresExternal       = "Requires-External"
-       MetadataFieldProjectURL             = "Project-URL"
-       MetadataFieldProvidesExtra          = "Provides-Extra"
-       MetadataFieldClassifier             = "Classifier"
+       MDVersion                     = "2.1"
+       MDFieldMetadataVersion        = "Metadata-Version"
+       MDFieldName                   = "Name"
+       MDFieldVersion                = "Version"
+       MDFieldDescription            = "Description"
+       MDFieldPlatform               = "Platform"
+       MDFieldSupportedPlatform      = "Supported-Platform"
+       MDFieldSummary                = "Summary"
+       MDFieldDescriptionContentType = "Description-Content-Type"
+       MDFieldKeywords               = "Keywords"
+       MDFieldHomePage               = "Home-page"
+       MDFieldAuthor                 = "Author"
+       MDFieldAuthorEmail            = "Author-email"
+       MDFieldMaintainer             = "Maintainer"
+       MDFieldMaintainerEmail        = "Maintainer-email"
+       MDFieldLicense                = "License"
+       MDFieldRequiresDist           = "Requires-Dist"
+       MDFieldRequiresPython         = "Requires-Python"
+       MDFieldRequiresExternal       = "Requires-External"
+       MDFieldProjectURL             = "Project-URL"
+       MDFieldProvidesExtra          = "Provides-Extra"
+       MDFieldClassifier             = "Classifier"
 )
 
-func metadataFieldToRecField(f string) string {
-       return strings.ReplaceAll(f, "-", "")
-}
+var (
+       MDFieldToRecField = map[string]string{
+               MDFieldMetadataVersion:        "MetadataVersion",
+               MDFieldName:                   "Name",
+               MDFieldVersion:                "Version",
+               MDFieldDescription:            "Description",
+               MDFieldPlatform:               "Platform",
+               MDFieldSupportedPlatform:      "SupportedPlatform",
+               MDFieldSummary:                "Summary",
+               MDFieldDescriptionContentType: "DescriptionContentType",
+               MDFieldKeywords:               "Keywords",
+               MDFieldHomePage:               "HomePage",
+               MDFieldAuthor:                 "Author",
+               MDFieldAuthorEmail:            "AuthorEmail",
+               MDFieldMaintainer:             "Maintainer",
+               MDFieldMaintainerEmail:        "MaintainerEmail",
+               MDFieldLicense:                "License",
+               MDFieldRequiresDist:           "RequiresDist",
+               MDFieldRequiresPython:         "RequiresPython",
+               MDFieldRequiresExternal:       "RequiresExternal",
+               MDFieldProjectURL:             "ProjectURL",
+               MDFieldProvidesExtra:          "ProvidesExtra",
+               MDFieldClassifier:             "Classifier",
+       }
+       MDFormToRecField = [][2]string{
+               {"name", MDFieldToRecField[MDFieldName]},
+               {"version", MDFieldToRecField[MDFieldVersion]},
+               {"platform", MDFieldToRecField[MDFieldPlatform]},
+               {"supported_platform", MDFieldToRecField[MDFieldSupportedPlatform]},
+               {"summary", MDFieldToRecField[MDFieldSummary]},
+               {"description", MDFieldToRecField[MDFieldDescription]},
+               {"description_content_type", MDFieldToRecField[MDFieldDescriptionContentType]},
+               {"keywords", MDFieldToRecField[MDFieldKeywords]},
+               {"home_page", MDFieldToRecField[MDFieldHomePage]},
+               {"author", MDFieldToRecField[MDFieldAuthor]},
+               {"author_email", MDFieldToRecField[MDFieldAuthorEmail]},
+               {"maintainer", MDFieldToRecField[MDFieldMaintainer]},
+               {"maintainer_email", MDFieldToRecField[MDFieldMaintainerEmail]},
+               {"license", MDFieldToRecField[MDFieldLicense]},
+               {"classifiers", MDFieldToRecField[MDFieldClassifier]},
+               {"requires_dist", MDFieldToRecField[MDFieldRequiresDist]},
+               {"requires_python", MDFieldToRecField[MDFieldRequiresPython]},
+               {"requires_external", MDFieldToRecField[MDFieldRequiresExternal]},
+               {"project_url", MDFieldToRecField[MDFieldProjectURL]},
+               {"provides_extra", MDFieldToRecField[MDFieldProvidesExtra]},
+       }
+)
 
 // It should follow https://www.python.org/dev/peps/pep-0566/
 type PkgInfo struct {