summaryrefslogtreecommitdiff
path: root/keyGetFromPackaagePB.go
blob: a97e080afefbeec0f1668a71e77cb5587d410264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main

import (
	"strings"

	"go.wit.com/lib/debian"
	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

// make a list of the newest .deb files
func doMakePackagesFile(all *zoopb.Packages) string {
	var pfile string
	for p := range all.IterAll() {
		var controlfile string
		parts, err := zoopb.GetDebInfoFields(p)
		if err != nil {
			log.Info(err)
		}
		for _, varname := range parts {
			varname, varval := debian.GetKeyFromPackagePB(p, varname)
			varval = strings.TrimSpace(varval)
			if varval == "" {
				continue
			}
			controlfile += log.Sprintf("%s: %s\n", varname, varval)
		}
		controlfile += log.Sprintf("\n")
		pfile += controlfile
	}
	return pfile
}

/*
func keyGetFromPackagePB(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 argv.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:
		dieMaking(varname)
	}
	return "", ""
}

func dieMaking(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()")
}
*/