From ec661807da8b201cd51e544aee59e8de21aeb0df Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 11 Sep 2025 15:23:17 -0500 Subject: switch over to using gitpb.Repo directly --- Makefile | 1 + addRepo.go | 12 +-- build.go | 325 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ buildPackage.go | 325 -------------------------------------------------------- controlBox.go | 102 ------------------ doGui.go | 40 ++++--- main.go | 2 - stateWindow.go | 75 +++++++++++++ structs.go | 32 ++++++ 9 files changed, 454 insertions(+), 460 deletions(-) create mode 100644 build.go delete mode 100644 buildPackage.go delete mode 100644 controlBox.go diff --git a/Makefile b/Makefile index 252bd8d..1e8ecd6 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ VERSION = $(shell git describe --tags) DATE = $(shell date +%Y.%m.%d) run: clean goimports vet install + go-deb --gui andlabs gui junk: #go-deb --release go.wit.com/apps/go-mod-clean --dir /tmp/ diff --git a/addRepo.go b/addRepo.go index 800076c..4a954ad 100644 --- a/addRepo.go +++ b/addRepo.go @@ -1,13 +1,6 @@ package main -import ( - "strings" - "time" - - "go.wit.com/lib/gadgets" - "go.wit.com/log" -) - +/* func RemoveFirstElement(slice []string) (string, []string) { if len(slice) == 0 { return "", slice // Return the original slice if it's empty @@ -17,7 +10,7 @@ func RemoveFirstElement(slice []string) (string, []string) { // homeDir, _ := os.UserHomeDir() -func (c *controlBox) addRepo() { +func (c *controlBox) addRepoOld() { path := strings.Trim(me.goPath, "/") // trim any extranous '/' chars put in the config file by the user if path == "" { log.Warn("addRepo() got empty path", path) @@ -99,3 +92,4 @@ func (c *controlBox) addRepo() { c.tagDate.SetText(tagDate) return } +*/ diff --git a/build.go b/build.go new file mode 100644 index 0000000..80ee9dc --- /dev/null +++ b/build.go @@ -0,0 +1,325 @@ +package main + +import ( + "errors" + "fmt" + "os" + "path/filepath" + "strconv" + "strings" + "time" + + "github.com/go-cmd/cmd" + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func buildPackage(repo *gitpb.Repo) (bool, error) { + // TODO: if dirty, set GO111MODULE + // also, if last tag != version + /* + go install -ldflags " \ + -X main.GITCOMMIT=${GITCOMMIT} \ + -X main.GOVERSION='${GOVERSION}' \ + -X main.BUILDTIME='${BUILDTIME}' \ + -X main.VERSION=${VERSION}" + */ + // ldflags := "main.GOTAG=" + repo.LastTag() + + filename := repo.Control["Package"] // c.Package.String() + if filename == "" { + return false, errors.New("filename is blank") + } + + homeDir, err := os.UserHomeDir() + if err != nil { + return false, err + } + + arch := repo.Control["Architecture"] // c.Architecture.String() + version := repo.Control["Version"] + log.Info("version is:", version) + debname := filename + "_" + version + "_" + arch + ".deb" + var fulldebname string + if argv.OutDir == "" { + fulldebname = debname + } else { + fulldebname = filepath.Join(argv.OutDir, debname) + } + if shell.Exists(fulldebname) { + log.Info("debian package already built: " + fulldebname) + return true, errors.New("debian package already built: " + fulldebname) + + } + + var fullfilename string + if argv.Release { + fullfilename = filepath.Join(homeDir, "go/bin", filename) + } else { + fullfilename = filename + } + shell.Run([]string{"rm", "-f", fullfilename}) + + if shell.Exists(fullfilename) { + // something wrong + return false, errors.New("binary existed before build") + } + + if argv.Release { + os.Unsetenv("GO111MODULE") + cmd := []string{"go"} + cmd = append(cmd, "install") + if argv.Verbose { + cmd = append(cmd, "-v") + cmd = append(cmd, "-x") + } + /* + cmd = append(cmd, "some path"+"@v"+version) + if err := shell.PathExecVerbose("", cmd); err != nil { + badExit(err) + return false, fmt.Errorf("go build err %v", err) + } + */ + cmd = []string{"go"} + cmd = append(cmd, "build") + if argv.Verbose { + cmd = append(cmd, "-v") + cmd = append(cmd, "-x") + } + cmd = append(cmd, "this should be the path") + if err := shell.PathExecVerbose("", cmd); err != nil { + badExit(err) + return false, fmt.Errorf("go build err %v", err) + } + log.Warn("build worked") + } else { + // set the GO111 build var to true. pass the versions to the compiler manually + os.Setenv("GO111MODULE", "off") + cmd := []string{"go", "build"} + // set standard ldflag options + now := time.Now() + datestamp := now.UTC().Format("2006/01/02_1504_UTC") + log.Info("datestamp =", datestamp) + // add some standard golang flags + ldflags := "-X main.VERSION=" + version + " " + ldflags += "-X main.BUILDTIME=" + datestamp + " " + ldflags += "-X main.GUIVERSION=" + version + "" // todo: git this from the filesystem + cmd = append(cmd, "-ldflags", ldflags) + + // add any flags from the command line + // this might not actually work + // todo: test this + for _, flag := range argv.Ldflags { + cmd = append(cmd, "-ldflags", "-X "+flag) + } + + _, err := shell.RunVerbose(cmd) + if err != nil { + return false, fmt.Errorf("go build err %v", err) + } + log.Warn("go build worked") + } + + filebase := filepath.Base(repo.Control["pathL"]) // c.pathL.String()) + if fullfilename != filebase { + // this exception is for when you want to override a package name + // sometimes that's the best option. This way you can keep your + // name, but the .deb package name can be different so you can + // still apt-get it. For an example, look at the gozookeeper package + fullfilename = filebase + } + + if !shell.Exists(fullfilename) { + log.Warn("build failed. filename does not exist", fullfilename) + return false, errors.New("missing " + fullfilename) + } + + if shell.Exists("files") { + shell.Run([]string{"rm", "-rf", "files"}) + // log.Info("running sync") + shell.Run([]string{"sync"}) + if shell.Exists("files") { + log.Warn("rm failed for some reason") + return false, errors.New("rm files/") + } + } + shell.Run([]string{"sync"}) // for some reason the next check fails sometimes? + if shell.Exists("files") { + // probably the 'shell' package id being stupid and not waiting for the process to actually exit + log.Warn("rm failed. files/ still exists. is golang doing these in parallel?") + return false, errors.New("rm files/") + } + if err := os.MkdirAll("files/DEBIAN", os.ModePerm); err != nil { + return false, errors.New("mkdir files/DEBIAN") + } + if err := os.MkdirAll("files/usr/bin", os.ModePerm); err != nil { + log.Warn("mkdir failed") + return false, errors.New("mkdir files/usr/bin") + } + if os.Getenv("GO_DEB_CUSTOM") == "true" { + // skip cp & strip on custom 'control' files + } else { + if r := shell.Run([]string{"cp", fullfilename, "files/usr/bin"}); r.Error != nil { + log.Warn("cp failed") + return false, r.Error + } + if r := shell.Run([]string{"strip", "files/usr/bin/" + filename}); r.Error != nil { + log.Warn("strip failed") + return false, r.Error + } + } + + // put the README in there (if missing, generate it?) + var readme string = "" + if shell.Exists("README.md") { + readme = "README.md" + } + + if shell.Exists("README") { + readme = "README" + } + + if readme != "" { + path := filepath.Join("files/usr/lib/" + filename) + if err := os.MkdirAll(path, os.ModePerm); err != nil { + return false, errors.New("no files/usr/lib") + } + if r := shell.Run([]string{"cp", readme, path}); r.Error != nil { + return false, r.Error + } + } + + if !writeDebianControlFile(repo) { + return false, errors.New("write control file") + } + if shell.Exists("postinst") { + shell.Run([]string{"cp", "postinst", "files/DEBIAN/"}) + } + + // experiment for the toolkit package + // if the git repo has a "./build" script run it before packaging + // this way the user can put custom files in the .deb package + if shell.Exists("build") { + shell.Run([]string{"./build"}) + } + + shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname}) + if shell.Exists(fulldebname) { + } else { + log.Warn("build failed", fulldebname) + return false, errors.New("dpkg-deb --build failed") + } + shell.Run([]string{"dpkg-deb", "-I", fulldebname}) + shell.Run([]string{"dpkg-deb", "-c", fulldebname}) + + // cleanup files + if shell.Exists("files") { + if argv.KeepFiles { + log.Info("keeping the build files/") + } else { + shell.Run([]string{"rm", "-rf", "files"}) + // log.Info("running sync") + shell.Run([]string{"sync"}) + if shell.Exists("files") { + log.Warn("rm -rf files/ failed. Run() returned false") + return false, errors.New("rm files/") + } + } + } + return true, nil +} + +func writeDebianControlFile(repo *gitpb.Repo) bool { + filename := "files/DEBIAN/control" + cf, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + log.Info("open control file failed", err) + return false + } + fmt.Fprintln(cf, "Package:", repo.Control["Package"]) // c.Package.String()) + fmt.Fprintln(cf, "Source:", repo.Control["Source"]) // c.Source.String()) + fmt.Fprintln(cf, "Version:", repo.Control["Version"]) // c.Version.String()) + fmt.Fprintln(cf, "Architecture:", repo.Control["Architecture"]) // c.Architecture.String()) + + writeControlVar(cf, repo, "Depends") + writeControlVar(cf, repo, "Build-Depends") + writeControlVar(cf, repo, "Maintainer") + writeControlVar(cf, repo, "Packager") + writeControlVar(cf, repo, "GoPath") + writeControlVar(cf, repo, "URL") + writeControlVar(cf, repo, "Conflicts") + + stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC") + // update to now now despite what the GUI is showing + fmt.Fprintln(cf, "Package-Build-Date:", stamp) + fmt.Fprintln(cf, "Git-Tag-Date:", "todo: get from repo") + + desc, _ := repo.Control["Description"] // c.Description.String() + parts := strings.Split(desc, "\n") + fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n ")) + + log.Info("file written as:", filename) + 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 +// if there is not a control file +func computeControlValues(repo *gitpb.Repo) bool { + if repo.Control["Package"] == "" { + // get the package name from the repo name + path := repo.Control["pathL"] // c.pathL.String() + parts := strings.Split(path, "/") + name := parts[len(parts)-1] + repo.Control["Package"] = name + } + if repo.Control["Source"] == "" { + repo.Control["Source"] = repo.Control["Package"] + } + if repo.Control["Build-Depends"] == "" { + repo.Control["Build-Depends"] = repo.Control["golang"] + } + if repo.Control["Recommends"] == "" { + repo.Control["Recommends"] = repo.Control["go-gui-toolkits"] + } + if repo.Control["Maintainer"] == "" { + repo.Control["Maintainer"] = "todo: get from ENV" + } + if repo.Control["Description"] == "" { + repo.Control["Description"] = "todo: put URL here" + } + return true +} + +// stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC") + +func getDateStamp(tag string) string { + var r cmd.Status + if me.repo == nil { + r = shell.Run([]string{"git", "log", "-1", "--format=%at", tag}) + } else { + r = me.repo.Run([]string{"git", "log", "-1", "--format=%at", tag}) + } + + out := strings.Join(r.Stdout, "\n") + out = strings.TrimSpace(out) + + // Convert the string to an integer + gitTagTimestampInt, err := strconv.ParseInt(out, 10, 64) + if err != nil { + fmt.Println("Error converting timestamp:", err) + return "git tag " + tag + " unknown" + } + + // Parse the Unix timestamp into a time.Time object + gitTagDate := time.Unix(gitTagTimestampInt, 0) + return gitTagDate.UTC().Format("2006-01-02_15:04:05_UTC") // close to RFC3339 +} diff --git a/buildPackage.go b/buildPackage.go deleted file mode 100644 index 5f2f2a7..0000000 --- a/buildPackage.go +++ /dev/null @@ -1,325 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "strconv" - "strings" - "time" - - "github.com/go-cmd/cmd" - "go.wit.com/lib/gui/shell" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func buildPackage(repo *gitpb.Repo) (bool, error) { - // TODO: if dirty, set GO111MODULE - // also, if last tag != version - /* - go install -ldflags " \ - -X main.GITCOMMIT=${GITCOMMIT} \ - -X main.GOVERSION='${GOVERSION}' \ - -X main.BUILDTIME='${BUILDTIME}' \ - -X main.VERSION=${VERSION}" - */ - // ldflags := "main.GOTAG=" + repo.LastTag() - - filename := repo.Control["Package"] // c.Package.String() - if filename == "" { - return false, errors.New("filename is blank") - } - - homeDir, err := os.UserHomeDir() - if err != nil { - return false, err - } - - arch := repo.Control["Architecture"] // c.Architecture.String() - version := repo.Control["Version"] - log.Info("version is:", version) - debname := filename + "_" + version + "_" + arch + ".deb" - var fulldebname string - if argv.OutDir == "" { - fulldebname = debname - } else { - fulldebname = filepath.Join(argv.OutDir, debname) - } - if shell.Exists(fulldebname) { - log.Info("debian package already built: " + fulldebname) - return true, errors.New("debian package already built: " + fulldebname) - - } - - var fullfilename string - if argv.Release { - fullfilename = filepath.Join(homeDir, "go/bin", filename) - } else { - fullfilename = filename - } - shell.Run([]string{"rm", "-f", fullfilename}) - - if shell.Exists(fullfilename) { - // something wrong - return false, errors.New("binary existed before build") - } - - if argv.Release { - os.Unsetenv("GO111MODULE") - cmd := []string{"go"} - cmd = append(cmd, "install") - if argv.Verbose { - cmd = append(cmd, "-v") - cmd = append(cmd, "-x") - } - /* - cmd = append(cmd, "some path"+"@v"+version) - if err := shell.PathExecVerbose("", cmd); err != nil { - badExit(err) - return false, fmt.Errorf("go build err %v", err) - } - */ - cmd = []string{"go"} - cmd = append(cmd, "build") - if argv.Verbose { - cmd = append(cmd, "-v") - cmd = append(cmd, "-x") - } - cmd = append(cmd, "this should be the path") - if err := shell.PathExecVerbose("", cmd); err != nil { - badExit(err) - return false, fmt.Errorf("go build err %v", err) - } - log.Warn("build worked") - } else { - // set the GO111 build var to true. pass the versions to the compiler manually - os.Setenv("GO111MODULE", "off") - cmd := []string{"go", "build"} - // set standard ldflag options - now := time.Now() - datestamp := now.UTC().Format("2006/01/02_1504_UTC") - log.Info("datestamp =", datestamp) - // add some standard golang flags - ldflags := "-X main.VERSION=" + version + " " - ldflags += "-X main.BUILDTIME=" + datestamp + " " - ldflags += "-X main.GUIVERSION=" + version + "" // todo: git this from the filesystem - cmd = append(cmd, "-ldflags", ldflags) - - // add any flags from the command line - // this might not actually work - // todo: test this - for _, flag := range argv.Ldflags { - cmd = append(cmd, "-ldflags", "-X "+flag) - } - - _, err := shell.RunVerbose(cmd) - if err != nil { - return false, fmt.Errorf("go build err %v", err) - } - log.Warn("go build worked") - } - - filebase := filepath.Base(repo.Control["pathL"]) // c.pathL.String()) - if fullfilename != filebase { - // this exception is for when you want to override a package name - // sometimes that's the best option. This way you can keep your - // name, but the .deb package name can be different so you can - // still apt-get it. For an example, look at the gozookeeper package - fullfilename = filebase - } - - if !shell.Exists(fullfilename) { - log.Warn("build failed. filename does not exist", fullfilename) - return false, errors.New("missing " + fullfilename) - } - - if shell.Exists("files") { - shell.Run([]string{"rm", "-rf", "files"}) - // log.Info("running sync") - shell.Run([]string{"sync"}) - if shell.Exists("files") { - log.Warn("rm failed for some reason") - return false, errors.New("rm files/") - } - } - shell.Run([]string{"sync"}) // for some reason the next check fails sometimes? - if shell.Exists("files") { - // probably the 'shell' package id being stupid and not waiting for the process to actually exit - log.Warn("rm failed. files/ still exists. is golang doing these in parallel?") - return false, errors.New("rm files/") - } - if err := os.MkdirAll("files/DEBIAN", os.ModePerm); err != nil { - return false, errors.New("mkdir files/DEBIAN") - } - if err := os.MkdirAll("files/usr/bin", os.ModePerm); err != nil { - log.Warn("mkdir failed") - return false, errors.New("mkdir files/usr/bin") - } - if os.Getenv("GO_DEB_CUSTOM") == "true" { - // skip cp & strip on custom 'control' files - } else { - if r := shell.Run([]string{"cp", fullfilename, "files/usr/bin"}); r.Error != nil { - log.Warn("cp failed") - return false, r.Error - } - if r := shell.Run([]string{"strip", "files/usr/bin/" + filename}); r.Error != nil { - log.Warn("strip failed") - return false, r.Error - } - } - - // put the README in there (if missing, generate it?) - var readme string = "" - if shell.Exists("README.md") { - readme = "README.md" - } - - if shell.Exists("README") { - readme = "README" - } - - if readme != "" { - path := filepath.Join("files/usr/lib/" + filename) - if err := os.MkdirAll(path, os.ModePerm); err != nil { - return false, errors.New("no files/usr/lib") - } - if r := shell.Run([]string{"cp", readme, path}); r.Error != nil { - return false, r.Error - } - } - - if !writeDebianControlFile(repo) { - return false, errors.New("write control file") - } - if shell.Exists("postinst") { - shell.Run([]string{"cp", "postinst", "files/DEBIAN/"}) - } - - // experiment for the toolkit package - // if the git repo has a "./build" script run it before packaging - // this way the user can put custom files in the .deb package - if shell.Exists("build") { - shell.Run([]string{"./build"}) - } - - shell.Run([]string{"dpkg-deb", "--build", "files", fulldebname}) - if shell.Exists(fulldebname) { - } else { - log.Warn("build failed", fulldebname) - return false, errors.New("dpkg-deb --build failed") - } - shell.Run([]string{"dpkg-deb", "-I", fulldebname}) - shell.Run([]string{"dpkg-deb", "-c", fulldebname}) - - // cleanup files - if shell.Exists("files") { - if argv.KeepFiles { - log.Info("keeping the build files/") - } else { - shell.Run([]string{"rm", "-rf", "files"}) - // log.Info("running sync") - shell.Run([]string{"sync"}) - if shell.Exists("files") { - log.Warn("rm -rf files/ failed. Run() returned false") - return false, errors.New("rm files/") - } - } - } - return true, nil -} - -func writeDebianControlFile(repo *gitpb.Repo) bool { - cf, err := os.OpenFile("files/DEBIAN/control", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - if err != nil { - log.Info("open control file failed", err) - return false - } - fmt.Fprintln(cf, "Package:", repo.Control["Package"]) // c.Package.String()) - fmt.Fprintln(cf, "Source:", repo.Control["Source"]) // c.Source.String()) - fmt.Fprintln(cf, "Version:", repo.Control["Version"]) // c.Version.String()) - fmt.Fprintln(cf, "Architecture:", repo.Control["Architecture"]) // c.Architecture.String()) - - writeControlVar(cf, repo, "Depends") - writeControlVar(cf, repo, "Build-Depends") - - stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC") - // update to now now despite what the GUI is showing - fmt.Fprintln(cf, "Package-Build-Date:", stamp) - - fmt.Fprintln(cf, "Git-Tag-Date:", "todo: get from repo") - - 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") - fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n ")) - - 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 -// if there is not a control file -func computeControlValues(repo *gitpb.Repo) bool { - if repo.Control["Package"] == "" { - // get the package name from the repo name - path := repo.Control["pathL"] // c.pathL.String() - parts := strings.Split(path, "/") - name := parts[len(parts)-1] - repo.Control["Package"] = name - } - if repo.Control["Source"] == "" { - repo.Control["Source"] = repo.Control["Package"] - } - if repo.Control["Build-Depends"] == "" { - repo.Control["Build-Depends"] = repo.Control["golang"] - } - if repo.Control["Recommends"] == "" { - repo.Control["Recommends"] = repo.Control["go-gui-toolkits"] - } - if repo.Control["Maintainer"] == "" { - repo.Control["Maintainer"] = "todo: get from ENV" - } - if repo.Control["Description"] == "" { - repo.Control["Description"] = "todo: put URL here" - } - return true -} - -// stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC") - -func getDateStamp(tag string) string { - var r cmd.Status - if me.repo == nil { - r = shell.Run([]string{"git", "log", "-1", "--format=%at", tag}) - } else { - r = me.repo.Run([]string{"git", "log", "-1", "--format=%at", tag}) - } - - out := strings.Join(r.Stdout, "\n") - out = strings.TrimSpace(out) - - // Convert the string to an integer - gitTagTimestampInt, err := strconv.ParseInt(out, 10, 64) - if err != nil { - fmt.Println("Error converting timestamp:", err) - return "git tag " + tag + " unknown" - } - - // Parse the Unix timestamp into a time.Time object - gitTagDate := time.Unix(gitTagTimestampInt, 0) - return gitTagDate.UTC().Format("2006-01-02_15:04:05_UTC") // close to RFC3339 -} diff --git a/controlBox.go b/controlBox.go deleted file mode 100644 index 3edacb7..0000000 --- a/controlBox.go +++ /dev/null @@ -1,102 +0,0 @@ -package main - -import ( - "go.wit.com/gui" - "go.wit.com/lib/gadgets" -) - -type controlBox struct { - group *gui.Node // the group - grid *gui.Node // the grid - - Package *gadgets.OneLiner - Source *gadgets.OneLiner - Version *gadgets.OneLiner - Maintainer *gadgets.OneLiner - Packager *gadgets.BasicEntry - GoPath *gadgets.BasicEntry - URL *gadgets.BasicEntry - Architecture *gadgets.BasicDropdown - InstallPath *gadgets.BasicCombobox - Depends *gadgets.OneLiner - BuildDepends *gadgets.OneLiner - Recommends *gadgets.OneLiner - Conflicts *gadgets.BasicEntry - Test gui.Widget - Description *gadgets.OneLiner - - // repostatus things - pathL *gadgets.OneLiner - lastTag *gadgets.OneLiner - dirtyL *gadgets.OneLiner - currentL *gadgets.OneLiner - buildDate *gadgets.OneLiner - tagDate *gadgets.BasicEntry - // status *repostatus.RepoStatus -} - -// This initializes the control box -func newControl(parent *gui.Node) *controlBox { - var c *controlBox - c = new(controlBox) - c.group = parent.NewGroup("choices") - c.grid = c.group.NewGrid("gridiron", 8, 1) - - c.Package = gadgets.NewOneLiner(c.grid, "Package") - c.grid.NextRow() - - c.Source = gadgets.NewOneLiner(c.grid, "Source") - c.grid.NextRow() - - c.Version = gadgets.NewOneLiner(c.grid, "Version") - c.grid.NextRow() - - c.Architecture = gadgets.NewBasicDropdown(c.grid, "Architecture") - c.Architecture.AddText("all") - c.Architecture.AddText("riscv64") - c.Architecture.AddText("amd64") - c.Architecture.AddText("arm64") - c.Architecture.AddText("ppc64") - c.Architecture.AddText("i386") - c.Architecture.AddText("sparc64") - c.Architecture.AddText("alpha") - c.Architecture.SetText("riscv64") - c.grid.NextRow() - - c.InstallPath = gadgets.NewBasicCombobox(c.grid, "Install Path") - c.InstallPath.AddText("/usr/bin") - c.InstallPath.AddText("/usr/local/bin") - c.InstallPath.AddText("/bin") - c.InstallPath.AddText("/opt//bin") - c.InstallPath.SetText("/usr/bin") - c.grid.NextRow() - - c.Maintainer = gadgets.NewOneLiner(c.grid, "Maintainer") - c.grid.NextRow() - - c.Packager = gadgets.NewBasicEntry(c.grid, "Packager") - c.grid.NextRow() - - c.GoPath = gadgets.NewBasicEntry(c.grid, "GoPath") - c.grid.NextRow() - - c.URL = gadgets.NewBasicEntry(c.grid, "URL") - c.grid.NextRow() - - c.Depends = gadgets.NewOneLiner(c.grid, "Depends") - c.grid.NextRow() - - c.BuildDepends = gadgets.NewOneLiner(c.grid, "Build-Depends") - c.grid.NextRow() - - c.Recommends = gadgets.NewOneLiner(c.grid, "Recommends") - c.grid.NextRow() - - c.Conflicts = gadgets.NewBasicEntry(c.grid, "Conflicts") - c.grid.NextRow() - - c.Description = gadgets.NewOneLiner(c.grid, "Description") - c.grid.NextRow() - - return c -} diff --git a/doGui.go b/doGui.go index 38973a5..cc89f15 100644 --- a/doGui.go +++ b/doGui.go @@ -5,27 +5,23 @@ package main // An app to submit patches for the 30 GO GUI repos -import ( - "os" - - "go.wit.com/gui" - "go.wit.com/lib/gadgets" - "go.wit.com/log" -) - func doGui() { - win := gadgets.NewGenericWindow("testing", "Current Conversations") - win.Custom = func() { - log.Warn("MAIN WINDOW CLOSE") - gui.StandardExit() - os.Exit(0) - } - - grid := win.Group.RawGrid() - - grid.NewLabel("label worked") - grid.NextRow() - - grid.NewButton("more", func() { - }) + win := makebasicWindow() + win.Show() + /* + win := gadgets.NewGenericWindow("testing", "Current Conversations") + win.Custom = func() { + log.Warn("MAIN WINDOW CLOSE") + gui.StandardExit() + os.Exit(0) + } + + grid := win.Group.RawGrid() + + grid.NewLabel("label worked") + grid.NextRow() + + grid.NewButton("more", func() { + }) + */ } diff --git a/main.go b/main.go index 32a46c4..bb574ec 100644 --- a/main.go +++ b/main.go @@ -70,8 +70,6 @@ func main() { // only load teh toolkit if you get this far me.myGui.Start() // loads the GUI toolkit doGui() - win := makebasicWindow() - win.Show() debug() } diff --git a/stateWindow.go b/stateWindow.go index a47c2ec..c5637a2 100644 --- a/stateWindow.go +++ b/stateWindow.go @@ -3,6 +3,7 @@ package main import ( "os" + "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/shell" "go.wit.com/log" @@ -34,6 +35,10 @@ func makebasicWindow() *gadgets.BasicWindow { readControlFile(me.repo) }) + group1.NewButton("write control file", func() { + writeDebianControlFile(me.repo) + }) + group1.NewButton("Make .deb", func() { win.Disable() if ok, err := buildPackage(me.repo); ok { @@ -47,3 +52,73 @@ func makebasicWindow() *gadgets.BasicWindow { return win } + +// This initializes the control box +func newControl(parent *gui.Node) *controlBox { + var c *controlBox + c = new(controlBox) + c.group = parent.NewGroup("choices") + c.grid = c.group.NewGrid("gridiron", 8, 1) + + c.Package = gadgets.NewOneLiner(c.grid, "Package") + c.grid.NextRow() + + c.Source = gadgets.NewOneLiner(c.grid, "Source") + c.grid.NextRow() + + c.Version = gadgets.NewOneLiner(c.grid, "Version") + c.grid.NextRow() + + c.Architecture = gadgets.NewBasicDropdown(c.grid, "Architecture") + c.Architecture.AddText("all") + c.Architecture.AddText("riscv64") + c.Architecture.AddText("amd64") + c.Architecture.AddText("arm64") + c.Architecture.AddText("ppc64") + c.Architecture.AddText("i386") + c.Architecture.AddText("sparc64") + c.Architecture.AddText("alpha") + c.Architecture.SetText("riscv64") + c.grid.NextRow() + + c.InstallPath = gadgets.NewBasicCombobox(c.grid, "Install Path") + c.InstallPath.AddText("/usr/bin") + c.InstallPath.AddText("/usr/local/bin") + c.InstallPath.AddText("/bin") + c.InstallPath.AddText("/opt//bin") + c.InstallPath.SetText("/usr/bin") + c.grid.NextRow() + + c.Maintainer = gadgets.NewOneLiner(c.grid, "Maintainer") + c.grid.NextRow() + + c.Packager = gadgets.NewBasicEntry(c.grid, "Packager") + c.grid.NextRow() + + c.GoPath = gadgets.NewBasicEntry(c.grid, "GoPath") + c.grid.NextRow() + + c.URL = gadgets.NewBasicEntry(c.grid, "URL") + c.grid.NextRow() + + c.Depends = gadgets.NewOneLiner(c.grid, "Depends") + c.grid.NextRow() + + c.BuildDepends = gadgets.NewOneLiner(c.grid, "Build-Depends") + c.grid.NextRow() + + c.Recommends = gadgets.NewOneLiner(c.grid, "Recommends") + c.grid.NextRow() + + c.Conflicts = gadgets.NewBasicEntry(c.grid, "Conflicts") + c.grid.NextRow() + + c.Description = gadgets.NewOneLiner(c.grid, "Description") + c.grid.NextRow() + + return c +} + +func updateControl(c *controlBox) { + c.URL.SetText(me.repo.URL) +} diff --git a/structs.go b/structs.go index 6452f8e..b648572 100644 --- a/structs.go +++ b/structs.go @@ -2,6 +2,8 @@ package main import ( "go.wit.com/dev/alexflint/arg" + "go.wit.com/gui" + "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/gitpb" ) @@ -17,3 +19,33 @@ type mainType struct { repo *gitpb.Repo // this is the repo we are in myGui *prep.GuiPrep // the gui toolkit handle } + +type controlBox struct { + group *gui.Node // the group + grid *gui.Node // the grid + + Package *gadgets.OneLiner + Source *gadgets.OneLiner + Version *gadgets.OneLiner + Maintainer *gadgets.OneLiner + Packager *gadgets.BasicEntry + GoPath *gadgets.BasicEntry + URL *gadgets.BasicEntry + Architecture *gadgets.BasicDropdown + InstallPath *gadgets.BasicCombobox + Depends *gadgets.OneLiner + BuildDepends *gadgets.OneLiner + Recommends *gadgets.OneLiner + Conflicts *gadgets.BasicEntry + Test gui.Widget + Description *gadgets.OneLiner + + // repostatus things + pathL *gadgets.OneLiner + lastTag *gadgets.OneLiner + dirtyL *gadgets.OneLiner + currentL *gadgets.OneLiner + buildDate *gadgets.OneLiner + tagDate *gadgets.BasicEntry + // status *repostatus.RepoStatus +} -- cgit v1.2.3