2024-02-11 02:16:51 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// readGitConfig reads and parses the control file
|
2024-02-11 06:32:48 -06:00
|
|
|
func (c *controlBox) readControlFile() error {
|
2024-11-07 07:03:13 -06:00
|
|
|
pairs := make(map[string]string)
|
|
|
|
var key string
|
|
|
|
|
2024-02-11 02:16:51 -06:00
|
|
|
file, err := os.Open("control")
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("readControlFile() could not find the file")
|
2024-11-07 07:03:13 -06:00
|
|
|
// return errors.New("'control': file not found")
|
|
|
|
// if this happens, make up a fake control file
|
|
|
|
pairs["Maintainer"] = "go-deb build"
|
|
|
|
pairs["Architecture"] = "x86"
|
|
|
|
pairs["Recommends"] = ""
|
|
|
|
pairs["Source"] = "notsure"
|
|
|
|
pairs["Description"] = "put something here"
|
2024-02-11 02:16:51 -06:00
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
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":
|
2024-02-11 03:11:41 -06:00
|
|
|
// log.Info("FOUND Source!", value) c.Source.SetText(value)
|
2024-02-11 02:16:51 -06:00
|
|
|
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)
|
2024-11-16 09:49:49 -06:00
|
|
|
case "Version":
|
|
|
|
c.Version.SetText(value)
|
2024-02-11 02:16:51 -06:00
|
|
|
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":
|
2024-11-16 11:00:46 -06:00
|
|
|
// todo: add logic to find OS arch
|
2024-02-11 02:16:51 -06:00
|
|
|
if c.Architecture.String() != value {
|
2024-11-16 11:00:46 -06:00
|
|
|
log.Warn("attempting to set arch to", value)
|
|
|
|
c.Architecture.SetText(value)
|
2024-11-16 10:30:30 -06:00
|
|
|
|
2024-02-11 02:16:51 -06:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Warn("error unknown key", key, "value:", value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|