diff options
| author | Jeff Carr <[email protected]> | 2025-10-14 02:09:45 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-14 02:24:53 -0500 |
| commit | c6fb67ad577915016fdf06506506847c62ba58aa (patch) | |
| tree | 183db070d7bac688dbf5b46ce74a242ada36c95f | |
| parent | 8ccd6d70a5f6ad873b9cf32f929935b455015092 (diff) | |
move to lib/debian
| -rw-r--r-- | parseDpkgOutputIntoPB.go | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/parseDpkgOutputIntoPB.go b/parseDpkgOutputIntoPB.go new file mode 100644 index 0000000..d9b1c4d --- /dev/null +++ b/parseDpkgOutputIntoPB.go @@ -0,0 +1,134 @@ +package debian + +import ( + "bufio" + "strings" + + "go.wit.com/lib/cobol" + "go.wit.com/lib/config" + "go.wit.com/lib/protobuf/zoopb" + "go.wit.com/log" + "google.golang.org/protobuf/types/known/timestamppb" +) + +// PARSES "dpkg -I <p.Filename>" +// panic() on anything missing or unknown +func ParseDpkgOutputIntoPB(pb *zoopb.Package, all string) { + starting := true + scanner := bufio.NewScanner(strings.NewReader(all)) + for scanner.Scan() { + line := scanner.Text() + parts := strings.Fields(line) + if starting { + if parts[0] == "new" { + if config.Verbose() { + log.Printf("new: %v\n", parts) + } + // skip the first dpkg -I line + continue + } + if parts[0] == "size" { + if config.Verbose() { + log.Printf("size: %v\n", parts) + } + // todo: make this correct + pb.DebInfo.Size = parts[1] + pb.DebInfo.InstalledSize = parts[1] + // scan all the entries from size + for scanner.Scan() { + line = scanner.Text() + parts = strings.Fields(line) + if strings.HasPrefix(line, " ") { + if config.Verbose() { + log.Printf("sizeline: %v\n", parts) + } + continue + } + starting = false + break + } + } + if starting { + if config.Verbose() { + log.Printf("parts: %v\n", parts) + } + continue + } + } + varname := strings.TrimSuffix(parts[0], ":") + varval := strings.Join(parts[1:], " ") + // log.Printf("varname:%s varval:%s\n", varname, varval) + switch varname { + case "Package": + pb.Package = varval + case "Filename": + log.Printf("Filename: varname:%s varval:%s\n", varname, varval) + // pb.Package = varval + case "Version": + pb.Version = varval + case "Architecture": + pb.Architecture = varval + case "GoPath": + pb.Namespace = varval + case "Maintainer": + pb.DebInfo.Maintainer = varval + case "Packager": + pb.DebInfo.Packager = varval + case "Depends": + pb.DebInfo.Depends = varval + case "Source": + pb.DebInfo.Source = varval + case "URL": + pb.DebInfo.URL = varval + case "Build-Depends": + pb.DebInfo.BuildDepends = varval + case "Installed-Size:": + case "Installed-Size": + pb.DebInfo.InstalledSize = varval + case "Homepage": + pb.DebInfo.URL = varval + case "Conflicts": + pb.DebInfo.Conflicts = varval + case "Source-Date": + t, err := cobol.GetTime(varval) + if err == nil { + pb.GitDate = timestamppb.New(t) + } else { + if config.Verbose() { + log.Info("FIXME: Package-Build-Date", varval, err) + } + } + case "Build-Date": + case "Package-Build-Date": + t, err := cobol.GetTime(varval) + if err == nil { + pb.BuildDate = timestamppb.New(t) + } else { + if config.Verbose() { + log.Info("FIXME: Package-Build-Date", varval, err) + } + } + case "Git-Tag-Date": + if config.Verbose() { + log.Info("FIXME: Git-Tag-Date", varval) + } + case "Description": + description := varval + for scanner.Scan() { + line := scanner.Text() + if strings.HasPrefix(line, " ") { + line = strings.TrimSpace(line) + description += line + "\n" + continue + } + break + } + pb.DebInfo.Description = description + default: + // This forces me(it could be you!) to fix this parser + varname2 := strings.TrimSuffix(varname, ":") + log.Printf("UNKNOWN: varname:%s varval:%s varname2=%s\n", varname, varval, varname2) + panic("fix mirrors populateDebInfo()") + } + } +} |
