diff options
| author | Jeff Carr <[email protected]> | 2025-10-14 01:51:55 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-14 01:52:57 -0500 |
| commit | 8ccd6d70a5f6ad873b9cf32f929935b455015092 (patch) | |
| tree | 80fc38078421571202dc4e6cad53a04c229e32e4 | |
| parent | f530e845f43b797247a750a60d6680475e2713f8 (diff) | |
standard .deb var formatting func()
| -rw-r--r-- | getKeyFromPackaagePB.go | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/getKeyFromPackaagePB.go b/getKeyFromPackaagePB.go new file mode 100644 index 0000000..3fa947c --- /dev/null +++ b/getKeyFromPackaagePB.go @@ -0,0 +1,112 @@ +package debian + +import ( + "strings" + + "go.wit.com/lib/cobol" + "go.wit.com/lib/config" + "go.wit.com/lib/protobuf/zoopb" + "go.wit.com/log" +) + +// returns the standard .deb string from a package PB +func GetKeyFromPackagePB(p *zoopb.Package, varname string) (string, string) { + switch varname { + case "Package": + return "Package", p.Package + case "Filename": + return "Filename", p.Filename + case "Version": + return "Version", p.Version + case "Architecture": + return "Architecture", p.Architecture + case "Maintainer": + return "Maintainer", p.DebInfo.Maintainer + // return "Maintainer", p.Author + case "Source": + if config.Verbose() { + log.Info("skipping from controlfile", varname) + // return "Source", p.DebInfo.Source + } + return "Source", "" + case "Conflicts": + return "Conflicts", p.DebInfo.Conflicts + case "Packager": + return "Packager", p.DebInfo.Packager + // return "Packager", p.Packager + case "Depends": + return "Depends", p.DebInfo.Depends + case "Namespace": + return "Namespace", p.Namespace + case "GitHash": + return "Last-Git-Hash", p.DebInfo.GitHash + case "GitDate": + if p.DebInfo.GitDate == "" { + return "Git-Hash-Date", "" + } + return "Git-Hash-Date", cobol.Time(p.DebInfo.GitDate) + case "BuildDepends": + return "Build-Depends", p.DebInfo.BuildDepends + case "InstalledSize": + return "Installed-Size", p.DebInfo.InstalledSize + case "Homepage": + return "Homepage", p.DebInfo.Homepage + case "PreDepends": + return "Pre-Depends", p.DebInfo.PreDepends + case "Suggests": + return "Suggests", p.DebInfo.Suggests + case "MultiArch": + return "Multi-Arch", p.DebInfo.MultiArch + case "Tag": + return "Tag", p.DebInfo.Tag + case "Size": + return "Size", p.DebInfo.Size + case "Section": + return "Section", p.DebInfo.Section + case "URL": + return "URL", p.DebInfo.URL + //case "Size": + // return "Size", p.DebInfo.Size + case "BuildDate": + if p.BuildDate == nil { + return "Build-Date", "" + } + return "Build-Date", cobol.Time(p.BuildDate) + case "DebCtime": + return "Deb-File-Date", cobol.Time(p.Ctime) + case "SHA1": + return "SHA1", "" // deprecated + // return "SHA1", p.DebInfo.SHA1 + case "MD5SUM": + return "MD5Sum", p.DebInfo.MD5SUM + case "SHA256": + return "SHA256", p.DebInfo.SHA256 + case "SHA512": + return "SHA512", "" // totally rediculously overkill + case "Description": + var out string + lines := strings.Split(p.DebInfo.Description, "\n") + if len(lines) == 0 { + return "Description", out + } + out = "Description: " + strings.TrimSpace(lines[0]) + if len(lines) == 1 { + return "Description", out + } + for _, line := range lines[1:] { + out += " " + strings.TrimSpace(line) + } + return "Description", out + default: + dieTrying(varname) + } + return "", "" +} + +// in here because this code is new and must catch every missing varname +func dieTrying(varname string) { + log.Info("DebInfo sent a field we didn't have. fix the code above", varname) + log.Printf("UNHANDLED ABOVE DEBINFO VAR: varname:%s\n", varname) + // This forces me(it could be you!) to fix this parser + panic("fix mirrors makeDebianControlFile()") +} |
