summaryrefslogtreecommitdiff
path: root/readControlFile.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-11 02:16:51 -0600
committerJeff Carr <[email protected]>2024-02-11 02:16:51 -0600
commiteed897eefde13caff77cd3c62c2a62f77165a129 (patch)
treea476861fba9da04d5f283ee976d7686e41fffa76 /readControlFile.go
parentb29d6caf34e72af362f791a5cba7dbd06e7fd1a2 (diff)
preliminary file scan and buildv0.0.1
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'readControlFile.go')
-rw-r--r--readControlFile.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/readControlFile.go b/readControlFile.go
new file mode 100644
index 0000000..7431f2a
--- /dev/null
+++ b/readControlFile.go
@@ -0,0 +1,81 @@
+package main
+
+import (
+ "bufio"
+ "os"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+// readGitConfig reads and parses the control file
+func (c *controlFile) readControlFile() error {
+ file, err := os.Open("control")
+ if err != nil {
+ log.Warn("readControlFile() could not find the file")
+ }
+ defer file.Close()
+
+ pairs := make(map[string]string)
+ var key string
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ line := scanner.Text()
+
+ // Skip empty lines and comments
+ if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
+ continue
+ }
+
+ // if line starts with a space, it's part of the last key
+ if strings.HasPrefix(line, " ") {
+ pairs[key] = pairs[key] + "\n" + strings.TrimSpace(line)
+ continue
+ }
+
+ partsNew := strings.SplitN(line, ":", 2)
+ if len(partsNew) < 2 {
+ log.Warn("error on line:", line)
+ continue
+ }
+
+ key = strings.TrimSpace(partsNew[0])
+ value := strings.TrimSpace(partsNew[1])
+ pairs[key] = value
+ }
+ for key, value := range pairs {
+ switch key {
+ case "Source":
+ // log.Info("FOUND Source!", value)
+ c.Source.SetText(value)
+ case "Build-Depends":
+ c.BuildDepends.SetText(value)
+ case "Description":
+ c.Description.SetText(value)
+ case "Maintainer":
+ c.Maintainer.SetText(value)
+ case "Depends":
+ c.Depends.SetText(value)
+ case "Recommends":
+ c.Recommends.SetText(value)
+ case "Package":
+ c.Package.SetText(value)
+ // if c.Package.String() != value {
+ // log.Warn("not sure what to do with Package", c.Package.String(), value)
+ // }
+ case "Architecture":
+ if c.Architecture.String() != value {
+ log.Warn("not sure what to do with Architecture", c.Architecture.String(), value)
+ }
+ default:
+ log.Warn("error unknown key", key, "value:", value)
+ }
+ }
+
+ if err := scanner.Err(); err != nil {
+ return err
+ }
+
+ return nil
+}