refactor to store info

This commit is contained in:
Jeff Carr 2025-09-11 15:03:44 -05:00
parent b05b706d8b
commit 127f36ca1f
8 changed files with 114 additions and 116 deletions

View File

@ -4,6 +4,8 @@ VERSION = $(shell git describe --tags)
DATE = $(shell date +%Y.%m.%d) DATE = $(shell date +%Y.%m.%d)
run: clean goimports vet install run: clean goimports vet install
junk:
#go-deb --release go.wit.com/apps/go-mod-clean --dir /tmp/ #go-deb --release go.wit.com/apps/go-mod-clean --dir /tmp/
#go-deb go.wit.com/apps/autotypist #go-deb go.wit.com/apps/autotypist
#ls -lth /tmp/*deb #ls -lth /tmp/*deb

View File

@ -95,7 +95,7 @@ func (c *controlBox) addRepo() {
c.lastTag.SetText(lasttag) c.lastTag.SetText(lasttag)
c.currentL.SetText(cbname + " " + cbversion) c.currentL.SetText(cbname + " " + cbversion)
tagDate := c.getDateStamp(lasttag) tagDate := getDateStamp(lasttag)
c.tagDate.SetText(tagDate) c.tagDate.SetText(tagDate)
return return
} }

View File

@ -49,10 +49,12 @@ func (a args) DoAutoComplete(argv []string) {
fmt.Println("riscv64") fmt.Println("riscv64")
case "build": case "build":
fmt.Println("user devel release") fmt.Println("user devel release")
case "--gui":
fmt.Println("nocui andlabs")
default: default:
if argv[0] == ARGNAME { if argv[0] == ARGNAME {
// list the subcommands here // list the subcommands here
fmt.Println("arch build gui show") fmt.Println("arch build gui show --gui")
} }
} }
os.Exit(0) os.Exit(0)

View File

@ -11,10 +11,11 @@ import (
"github.com/go-cmd/cmd" "github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
func buildPackage(c *controlBox) (bool, error) { func buildPackage(repo *gitpb.Repo) (bool, error) {
// TODO: if dirty, set GO111MODULE // TODO: if dirty, set GO111MODULE
// also, if last tag != version // also, if last tag != version
/* /*
@ -26,7 +27,7 @@ func buildPackage(c *controlBox) (bool, error) {
*/ */
// ldflags := "main.GOTAG=" + repo.LastTag() // ldflags := "main.GOTAG=" + repo.LastTag()
filename := c.Package.String() filename := repo.Control["Package"] // c.Package.String()
if filename == "" { if filename == "" {
return false, errors.New("filename is blank") return false, errors.New("filename is blank")
} }
@ -36,8 +37,8 @@ func buildPackage(c *controlBox) (bool, error) {
return false, err return false, err
} }
arch := c.Architecture.String() arch := repo.Control["Architecture"] // c.Architecture.String()
version := c.Version.String() version := repo.Control["Version"]
log.Info("version is:", version) log.Info("version is:", version)
debname := filename + "_" + version + "_" + arch + ".deb" debname := filename + "_" + version + "_" + arch + ".deb"
var fulldebname string var fulldebname string
@ -120,7 +121,7 @@ func buildPackage(c *controlBox) (bool, error) {
log.Warn("go build worked") log.Warn("go build worked")
} }
filebase := filepath.Base(c.pathL.String()) filebase := filepath.Base(repo.Control["pathL"]) // c.pathL.String())
if fullfilename != filebase { if fullfilename != filebase {
// this exception is for when you want to override a package name // this exception is for when you want to override a package name
// sometimes that's the best option. This way you can keep your // sometimes that's the best option. This way you can keep your
@ -189,7 +190,7 @@ func buildPackage(c *controlBox) (bool, error) {
} }
} }
if !c.writeDebianControlFile() { if !writeDebianControlFile(repo) {
return false, errors.New("write control file") return false, errors.New("write control file")
} }
if shell.Exists("postinst") { if shell.Exists("postinst") {
@ -229,85 +230,78 @@ func buildPackage(c *controlBox) (bool, error) {
return true, nil return true, nil
} }
func (c *controlBox) writeDebianControlFile() bool { func writeDebianControlFile(repo *gitpb.Repo) bool {
cf, err := os.OpenFile("files/DEBIAN/control", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) cf, err := os.OpenFile("files/DEBIAN/control", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil { if err != nil {
log.Info("open control file failed", err) log.Info("open control file failed", err)
return false return false
} }
fmt.Fprintln(cf, "Package:", c.Package.String()) fmt.Fprintln(cf, "Package:", repo.Control["Package"]) // c.Package.String())
fmt.Fprintln(cf, "Source:", c.Source.String()) fmt.Fprintln(cf, "Source:", repo.Control["Source"]) // c.Source.String())
fmt.Fprintln(cf, "Version:", c.Version.String()) fmt.Fprintln(cf, "Version:", repo.Control["Version"]) // c.Version.String())
fmt.Fprintln(cf, "Architecture:", c.Architecture.String()) fmt.Fprintln(cf, "Architecture:", repo.Control["Architecture"]) // c.Architecture.String())
if c.Depends.String() != "" {
fmt.Fprintln(cf, "Depends:", c.Depends.String()) writeControlVar(cf, repo, "Depends")
} writeControlVar(cf, repo, "Build-Depends")
if c.BuildDepends.String() != "" {
fmt.Fprintln(cf, "Build-Depends:", c.BuildDepends.String())
}
stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC") stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
// update to now now despite what the GUI is showing // update to now now despite what the GUI is showing
fmt.Fprintln(cf, "Package-Build-Date:", stamp) fmt.Fprintln(cf, "Package-Build-Date:", stamp)
if c.tagDate.String() == "" {
// todo: allow this to be set somehow
} else {
fmt.Fprintln(cf, "Git-Tag-Date:", c.tagDate.String())
}
fmt.Fprintln(cf, "Maintainer:", c.Maintainer.String()) fmt.Fprintln(cf, "Git-Tag-Date:", "todo: get from repo")
fmt.Fprintln(cf, "Packager:", c.Packager.String())
if c.GoPath.String() != "" {
fmt.Fprintln(cf, "GoPath:", c.URL.String())
}
if c.URL.String() != "" {
fmt.Fprintln(cf, "URL:", c.URL.String())
}
if c.Conflicts.String() != "" {
fmt.Fprintln(cf, "Conflicts:", c.Conflicts.String())
}
desc := c.Description.String() writeControlVar(cf, repo, "Maintainer")
writeControlVar(cf, repo, "Packager")
writeControlVar(cf, repo, "GoPath")
writeControlVar(cf, repo, "URL")
writeControlVar(cf, repo, "Conflicts")
desc, _ := repo.Control["Description"] // c.Description.String()
parts := strings.Split(desc, "\n") parts := strings.Split(desc, "\n")
fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n ")) fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n "))
return true return true
} }
func writeControlVar(f *os.File, repo *gitpb.Repo, varname string) {
val, _ := repo.Control[varname]
if val == "" {
return
}
fmt.Fprintln(f, val+":", val)
}
// try to guess or figure out the config file values // try to guess or figure out the config file values
// if there is not a control file // if there is not a control file
func (c *controlBox) computeControlValues() bool { func computeControlValues(repo *gitpb.Repo) bool {
if c.Package.String() == "" { if repo.Control["Package"] == "" {
// get the package name from the repo name // get the package name from the repo name
path := c.pathL.String() path := repo.Control["pathL"] // c.pathL.String()
parts := strings.Split(path, "/") parts := strings.Split(path, "/")
name := parts[len(parts)-1] name := parts[len(parts)-1]
c.Package.SetText(name) repo.Control["Package"] = name
} }
if c.Source.String() == "" { if repo.Control["Source"] == "" {
c.Source.SetText(c.Package.String()) repo.Control["Source"] = repo.Control["Package"]
} }
if c.BuildDepends.String() == "" { if repo.Control["Build-Depends"] == "" {
c.BuildDepends.SetText("golang") repo.Control["Build-Depends"] = repo.Control["golang"]
} }
if c.Recommends.String() == "" { if repo.Control["Recommends"] == "" {
c.Recommends.SetText("go-gui-toolkits") repo.Control["Recommends"] = repo.Control["go-gui-toolkits"]
} }
// TODO: get this from the git log if repo.Control["Maintainer"] == "" {
if c.Maintainer.String() == "" { repo.Control["Maintainer"] = "todo: get from ENV"
c.Maintainer.SetText("made by go-deb")
} }
// TODO: get this from gitea (or gitlab or github, etc) if repo.Control["Description"] == "" {
// or from the README.md ? repo.Control["Description"] = "todo: put URL here"
if c.Description.String() == "" {
path := c.pathL.String()
c.Description.SetText("GO binary of " + path)
} }
return true return true
} }
// stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC") // stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
func (c *controlBox) getDateStamp(tag string) string { func getDateStamp(tag string) string {
var r cmd.Status var r cmd.Status
if me.repo == nil { if me.repo == nil {
r = shell.Run([]string{"git", "log", "-1", "--format=%at", tag}) r = shell.Run([]string{"git", "log", "-1", "--format=%at", tag})

17
main.go
View File

@ -43,10 +43,7 @@ func main() {
log.Info("todo: show", me.repo.GetGoPath()) log.Info("todo: show", me.repo.GetGoPath())
okExit("") okExit("")
} }
log.Info("todo: show", me.repo.GetNamespace(), me.repo.GetFullPath()) log.Info("Namespace:", me.repo.GetNamespace(), "Fullpath:", me.repo.GetFullPath())
okExit("")
me.basicWindow = makebasicWindow()
// figure out where we are working from // figure out where we are working from
// os.Chdir to that directory // os.Chdir to that directory
@ -61,27 +58,25 @@ func main() {
me.goPath = basename me.goPath = basename
os.Chdir(debpath) os.Chdir(debpath)
// scan the repo
me.cBox.addRepo()
// look for a 'config' file in the repo // look for a 'config' file in the repo
if me.cBox.readControlFile() == nil { if readControlFile(me.repo) == nil {
log.Warn("scan worked") log.Warn("scan worked")
} else { } else {
log.Warn("scan failed") log.Warn("scan failed")
} }
me.cBox.computeControlValues() computeControlValues(me.repo)
if argv.Gui != nil { if argv.Gui != nil {
// only load teh toolkit if you get this far // only load teh toolkit if you get this far
me.myGui.Start() // loads the GUI toolkit me.myGui.Start() // loads the GUI toolkit
doGui() doGui()
me.basicWindow.Show() win := makebasicWindow()
win.Show()
debug() debug()
} }
log.Info("go-deb: attempting to build package") log.Info("go-deb: attempting to build package")
if ok, err := buildPackage(me.cBox); ok { if ok, err := buildPackage(me.repo); ok {
log.Info("build worked") log.Info("build worked")
} else { } else {
log.Warn("build failed:", err) log.Warn("build failed:", err)

View File

@ -5,11 +5,12 @@ import (
"os" "os"
"strings" "strings"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
// readGitConfig reads and parses the control file // readGitConfig reads and parses the control file
func (c *controlBox) readControlFile() error { func readControlFile(repo *gitpb.Repo) error {
pairs := make(map[string]string) pairs := make(map[string]string)
var key string var key string
@ -55,46 +56,52 @@ func (c *controlBox) readControlFile() error {
value := strings.TrimSpace(partsNew[1]) value := strings.TrimSpace(partsNew[1])
pairs[key] = value pairs[key] = value
} }
if repo.Control == nil {
repo.Control = make(map[string]string)
}
for key, value := range pairs { for key, value := range pairs {
switch key { repo.Control[key] = value
case "Source": /*
c.Source.SetText(value) switch key {
case "Build-Depends": case "Source":
c.BuildDepends.SetText(value) c.Source.SetText(value)
case "Description": case "Build-Depends":
c.Description.SetText(value) c.BuildDepends.SetText(value)
case "Maintainer": case "Description":
c.Maintainer.SetText(value) c.Description.SetText(value)
case "Packager": case "Maintainer":
c.Packager.SetText(value) c.Maintainer.SetText(value)
case "GoPath": case "Packager":
c.GoPath.SetText(value) c.Packager.SetText(value)
case "URL": case "GoPath":
c.URL.SetText(value) c.GoPath.SetText(value)
case "Depends": case "URL":
c.Depends.SetText(value) c.URL.SetText(value)
case "Recommends": case "Depends":
c.Recommends.SetText(value) c.Depends.SetText(value)
case "Conflicts": case "Recommends":
c.Conflicts.SetText(value) c.Recommends.SetText(value)
case "Version": case "Conflicts":
c.Version.SetText(value) c.Conflicts.SetText(value)
case "Package": case "Version":
c.Package.SetText(value) c.Version.SetText(value)
// if c.Package.String() != value { case "Package":
// log.Warn("not sure what to do with Package", c.Package.String(), value) c.Package.SetText(value)
// } // if c.Package.String() != value {
case "Architecture": // log.Warn("not sure what to do with Package", c.Package.String(), value)
// todo: add logic to find OS arch // }
if c.Architecture.String() != value { case "Architecture":
log.Warn("attempting to set arch to", value) // todo: add logic to find OS arch
c.Architecture.SetText(value) if c.Architecture.String() != value {
log.Warn("attempting to set arch to", value)
c.Architecture.SetText(value)
}
default:
log.Warn("the 'control' file has a value I don't know about")
log.Warn("error unknown key", key, "value:", value)
} }
default: */
log.Warn("the 'control' file has a value I don't know about")
log.Warn("error unknown key", key, "value:", value)
}
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {

View File

@ -20,7 +20,8 @@ func makebasicWindow() *gadgets.BasicWindow {
} }
box1 := win.Box() box1 := win.Box()
me.cBox = newControl(box1) // me.cBox = newControl(box1)
newControl(box1)
vbox := box1.Box().Horizontal() vbox := box1.Box().Horizontal()
group1 := vbox.NewGroup("controls").Horizontal() // Vertical() group1 := vbox.NewGroup("controls").Horizontal() // Vertical()
@ -30,12 +31,12 @@ func makebasicWindow() *gadgets.BasicWindow {
}) })
group1.NewButton("read control file", func() { group1.NewButton("read control file", func() {
me.cBox.readControlFile() readControlFile(me.repo)
}) })
group1.NewButton("Make .deb", func() { group1.NewButton("Make .deb", func() {
win.Disable() win.Disable()
if ok, err := buildPackage(me.cBox); ok { if ok, err := buildPackage(me.repo); ok {
log.Info("build worked") log.Info("build worked")
os.Exit(0) os.Exit(0)
} else { } else {

View File

@ -2,7 +2,6 @@ package main
import ( import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/prep" "go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/gitpb"
) )
@ -11,12 +10,10 @@ var me *mainType
// this app's variables // this app's variables
type mainType struct { type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint! pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
goSrc string // path to ~/go/src or go.work file goSrc string // path to ~/go/src or go.work file
goPath string // the goPath to use for the package goPath string // the goPath to use for the package
hasWork bool // true if using go.work file hasWork bool // true if using go.work file
repo *gitpb.Repo // this is the repo we are in repo *gitpb.Repo // this is the repo we are in
myGui *prep.GuiPrep // the gui toolkit handle myGui *prep.GuiPrep // the gui toolkit handle
cBox *controlBox // the GUI box in the main window
basicWindow *gadgets.BasicWindow // this is a basic window. the user can open and close it
} }