From e4e12ae90dd2f9775b1d45c1d083a4e44817a655 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 11 Feb 2024 06:32:48 -0600 Subject: [PATCH] specify repo on command line works Signed-off-by: Jeff Carr --- Makefile | 3 ++ addRepo.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++ control | 10 ++++-- controlBox.go | 17 +++++++--- main.go | 36 +++++++++------------ readControlFile.go | 2 +- stateWindow.go | 33 +++++++++----------- 7 files changed, 130 insertions(+), 49 deletions(-) create mode 100644 addRepo.go diff --git a/Makefile b/Makefile index f55d126..49cf377 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ run: build ./go-deb --open-gui +dns: build + ./go-deb --repo go.wit.com/apps/control-panel-dns + build: -cp ~/go/src/go.wit.com/toolkits/*.so resources/ GO111MODULE="off" go build -v diff --git a/addRepo.go b/addRepo.go new file mode 100644 index 0000000..1a25dc9 --- /dev/null +++ b/addRepo.go @@ -0,0 +1,78 @@ +// This is a simple example +package main + +import ( + "strings" + + "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/repostatus" + "go.wit.com/log" +) + +func RemoveFirstElement(slice []string) (string, []string) { + if len(slice) == 0 { + return "", slice // Return the original slice if it's empty + } + return slice[0], slice[1:] // Return the slice without the first element +} + +// homeDir, _ := os.UserHomeDir() + +func (c *controlBox) addRepo(path string) { + path = strings.Trim(path, "/") // trim any extranous '/' chars put in the config file by the user + if path == "" { + log.Warn("addRepo() got empty path", path) + return + } + + if repostatus.VerifyLocalGoRepo(path) { + log.Verbose("path actually exists", path) + } else { + log.Warn("repostatus.VerifyLocalGoRepo() failed for for", path) + return + } + + c.pathL = gadgets.NewOneLiner(c.grid, "path") + c.pathL.SetText(path) + c.grid.NextRow() + + c.lastTag = gadgets.NewOneLiner(c.grid, "lastTag") + c.lastTag.SetText(path) + c.grid.NextRow() + + c.dirtyL = gadgets.NewOneLiner(c.grid, "dirty") + c.grid.NextRow() + + c.currentL = gadgets.NewOneLiner(c.grid, "current") + c.grid.NextRow() + + c.status = repostatus.NewRepoStatusWindow(path) + c.status.SetMainWorkingName("master") + c.status.SetDevelWorkingName("devel") + c.status.SetUserWorkingName("jcarr") + c.status.Update() + + + cbname := c.status.GetCurrentBranchName() + cbversion := c.status.GetCurrentBranchVersion() + debversion := strings.TrimPrefix(cbversion, "v") + + if c.status.CheckDirty() { + c.dirtyL.SetText("true") + debversion = debversion + "-dirty" + } else { + c.dirtyL.SetText("false") + } + + c.Version.SetText(debversion) + + lasttag := c.status.GetLastTagVersion() + c.lastTag.SetText(lasttag) + c.currentL.SetText(cbname + " " + cbversion) + + if c.status.Changed() { + log.Warn("should scan here") + } + + return +} diff --git a/control b/control index 12f6b3b..6c48021 100644 --- a/control +++ b/control @@ -4,6 +4,10 @@ Package: go-deb Maintainer: Jeff Carr Architecture: amd64 Depends: -Recommends: libgtk-3-0, ddclient, ddupdate -Description: a control panel for DNS and IPv6 settings - Goals: show the settings, validate & update DNS +Recommends: go-gui-toolkits +Description: create distribution packages for golang repositories + Hopefully, this can make compatible and correct source + packages for things like debuild or the incoming queue since + golang applications are more strict then the traditional C + libraries and binaries that require lots of scripting. + A person can dream anyway. diff --git a/controlBox.go b/controlBox.go index b25e91e..fc4fc36 100644 --- a/controlBox.go +++ b/controlBox.go @@ -4,9 +4,10 @@ package main import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/repostatus" ) -type controlFile struct { +type controlBox struct { group *gui.Node // the group grid *gui.Node // the grid @@ -20,12 +21,19 @@ type controlFile struct { BuildDepends *gadgets.OneLiner Recommends *gadgets.OneLiner Description *gadgets.OneLiner + + // repostatus things + pathL *gadgets.OneLiner + lastTag *gadgets.OneLiner + dirtyL *gadgets.OneLiner + currentL *gadgets.OneLiner + status *repostatus.RepoStatus } // This initializes the control box -func newControl(parent *gui.Node) *controlFile { - var c *controlFile - c = new(controlFile) +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) @@ -68,6 +76,7 @@ func newControl(parent *gui.Node) *controlFile { c.grid.NextRow() c.Description = gadgets.NewOneLiner(c.grid, "Description") + c.grid.NextRow() return c } diff --git a/main.go b/main.go index 9a80ad3..55101d4 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,9 @@ package main import ( + "os" + "path/filepath" + "go.wit.com/gui" "go.wit.com/lib/debugger" "go.wit.com/lib/gadgets" @@ -11,8 +14,7 @@ import ( // This is the beginning of the binary tree of GUI widgets var myGui *gui.Node -// this is the primary window. If you close it, the program will exit -// var mainWindow *gui.Node +var cBox *controlBox // this is a basic window. the user can open and close it var basicWindow *gadgets.BasicWindow @@ -29,9 +31,18 @@ func main() { myGui = gui.New() myGui.Default() - // helloworld() basicWindow = makebasicWindow() + if args.Repo != "" { + filepath := filepath.Join("/home/jcarr/go/src", args.Repo) + os.Chdir(filepath) + + cBox.addRepo(args.Repo) + cBox.readControlFile() + basicWindow.Show() + // go will sit here until the window exits + gui.Watchdog() + } if args.OpenGui { basicWindow.Show() // go will sit here until the window exits @@ -46,22 +57,3 @@ func main() { }() } } - -/* -// This initializes the first window and some widgets -func helloworld() { - mainWindow = myGui.NewWindow("Debian Package Creater for GO Language Applicatiosn").SetProgName("BASEWIN") - - box := mainWindow.NewBox("hbox", true) - // section1 = newChoices(box) - - group := box.NewGroup("control file") - group.NewButton("show basic window", func() { - if basicWindow.Hidden() { - basicWindow.Show() - } else { - basicWindow.Hide() - } - }) -} -*/ diff --git a/readControlFile.go b/readControlFile.go index 14c336d..7b07430 100644 --- a/readControlFile.go +++ b/readControlFile.go @@ -9,7 +9,7 @@ import ( ) // readGitConfig reads and parses the control file -func (c *controlFile) readControlFile() error { +func (c *controlBox) readControlFile() error { file, err := os.Open("control") if err != nil { log.Warn("readControlFile() could not find the file") diff --git a/stateWindow.go b/stateWindow.go index 3fda09d..efe9a8a 100644 --- a/stateWindow.go +++ b/stateWindow.go @@ -7,14 +7,11 @@ import ( "os" "strings" - "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) -var apple *gui.Node - // This initializes the first window, a group and a button func makebasicWindow() *gadgets.BasicWindow { log.Warn("init basicWindow state") @@ -26,7 +23,7 @@ func makebasicWindow() *gadgets.BasicWindow { } box1 := basicWindow.Box() - control := newControl(box1) + cBox = newControl(box1) vbox := box1.Box().Horizontal() group1 := vbox.NewGroup("controls").Horizontal() // Vertical() @@ -36,12 +33,12 @@ func makebasicWindow() *gadgets.BasicWindow { }) group1.NewButton("read control file", func() { - control.readControlFile() + cBox.readControlFile() }) group1.NewButton("Make .deb", func() { basicWindow.Disable() - if control.buildPackage() { + if cBox.buildPackage() { log.Info("build worked") } else { log.Warn("build failed") @@ -50,20 +47,14 @@ func makebasicWindow() *gadgets.BasicWindow { }) group1.NewButton("open repo", func() { + cBox.status.Update() + cBox.status.Toggle() }) - /* - group1.NewButton("show apple", func() { - apple.Show() - }) - apple = group1.NewButton("apple", func() { - log.Info("is not a pear") - }) - */ return basicWindow } -func (c *controlFile) buildPackage() bool { +func (c *controlBox) buildPackage() bool { if c.readControlFile() == nil { log.Warn("scan worked") } else { @@ -88,8 +79,10 @@ func (c *controlFile) buildPackage() bool { } arch := c.Architecture.String() - version := "0.0.0" - c.Version.SetText(version) + version := c.Version.String() + if version == "" { + version = "0.0.0" + } debname := filename + "_" + version + "_" + arch + ".deb" @@ -139,10 +132,12 @@ func (c *controlFile) buildPackage() bool { log.Warn("build failed") return false } + shell.Run([]string{"dpkg-deb", "-I", debname}) + shell.Run([]string{"dpkg-deb", "-c", debname}) return true } -func (c *controlFile) writeFiles() bool { +func (c *controlBox) writeFiles() bool { cf, err := os.OpenFile("files/DEBIAN/control", os.O_RDWR|os.O_CREATE, 0644) if err != nil { log.Info("open control file failed", err) @@ -157,7 +152,7 @@ func (c *controlFile) writeFiles() bool { fmt.Fprintln(cf, "Maintainer:", c.Maintainer.String()) desc := c.Description.String() parts := strings.Split(desc, "\n") - fmt.Fprintln(cf, "Description:", strings.Join(parts, " \n")) + fmt.Fprintln(cf, "Description:", strings.Join(parts, "\n ")) return true }