diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-01-03 18:04:08 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-01-03 20:24:29 +0200 |
commit | 23a7f3baa33265519840609dc54e950615ec39b1 (patch) | |
tree | ff2737f76b63a2acf5f8a9fffd5c15e3eb4c46c8 /tools/src | |
parent | WebProfile refactoring (diff) | |
download | smolbote-23a7f3baa33265519840609dc54e950615ec39b1.tar.xz |
Merge some QoL improvements from staging branch
- Build executable in top-level buildroot
- Use meson sourceset
- Pull in poi-crash and poi-update from staging
- Remove extraneous scripts in tools/
- Pull in configure scripts in scripts/
Diffstat (limited to 'tools/src')
-rw-r--r-- | tools/src/crashhandler/defaults.go.in | 4 | ||||
-rw-r--r-- | tools/src/crashhandler/main.go | 79 | ||||
-rw-r--r-- | tools/src/updater/main.go | 47 | ||||
-rw-r--r-- | tools/src/updater/manifest.go | 16 |
4 files changed, 146 insertions, 0 deletions
diff --git a/tools/src/crashhandler/defaults.go.in b/tools/src/crashhandler/defaults.go.in new file mode 100644 index 0000000..2ea5827 --- /dev/null +++ b/tools/src/crashhandler/defaults.go.in @@ -0,0 +1,4 @@ +package main + +var dumpPath = "@PATH_CRASHDUMP@" + diff --git a/tools/src/crashhandler/main.go b/tools/src/crashhandler/main.go new file mode 100644 index 0000000..00ce0cd --- /dev/null +++ b/tools/src/crashhandler/main.go @@ -0,0 +1,79 @@ +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "os" + "strings" +) + +type CrashDump struct { + Name string + DumpPath string + MetadataPath string +} + +func expandHomeDir(path string) (string, error) { + home, err := os.UserHomeDir() + if err != nil { + return path, err + } + + return strings.Replace(path, "~/", home, -1), nil +} + +func dumps(path string) ([]CrashDump, error) { + files, err := ioutil.ReadDir(path) + if err != nil { + return nil, err + } + + var crashes []CrashDump + + for i, file := range files { + if strings.HasSuffix(file.Name(), ".dmp") { + if i+1 < len(files) && files[i+1].Name() == file.Name()+".txt" { + crashes = append(crashes, CrashDump{Name: strings.TrimSuffix(file.Name(), ".dmp"), + DumpPath: file.Name(), MetadataPath: files[i+1].Name()}) + } else { + crashes = append(crashes, CrashDump{Name: strings.TrimSuffix(file.Name(), ".dmp"), DumpPath: file.Name()}) + } + } + } + + return crashes, nil +} + +func main() { + helpFlag := flag.Bool("help", false, "Show help information.") + flag.StringVar(&dumpPath, "crashd", dumpPath, "Crash dump path") + + // create crash report flags + crashedFlag := flag.String("c", "", "Create crash report at specified location and write any specified data into it") + + flag.Parse() + dumpPath, _ = expandHomeDir(dumpPath) + + if *helpFlag { + flag.PrintDefaults() + return + } + + if *crashedFlag != "" { + fmt.Println("Creating crash dump report", *crashedFlag) + contents := []byte("Additional information: " + strings.Join(flag.Args(), "")) + ioutil.WriteFile(*crashedFlag+".txt", contents, 0644) + return + } + + fmt.Printf("[%s]\n", dumpPath) + c, err := dumps(dumpPath) + if err != nil { + panic(err) + } + for _, d := range c { + fmt.Printf("\t- %s\n", d.Name) + } + +} diff --git a/tools/src/updater/main.go b/tools/src/updater/main.go new file mode 100644 index 0000000..e6e1560 --- /dev/null +++ b/tools/src/updater/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "encoding/json" + "io/ioutil" +) + +func main() { + helpFlag := flag.Bool("help", false, "Show help information") + //verboseFlag := flag.Bool("verbose", false, "Print more information") + //repoFlag := flag.String("repo", "https://neueland.iserlohn-fortress.net/smolbote/downloads", "Repository path") + //dryRunFlag := flag.Bool("dry-run", false, "Dry run: only check files, do not download") + + flag.Parse() + + branchesRequest := "https://neueland.iserlohn-fortress.net/gitea/api/v1/repos/aqua/smolbote/branches" + + // help flag --> show usage and exit + if *helpFlag { + flag.PrintDefaults() + return + } + + response, err := http.Get(branchesRequest) + if err != nil { + panic(err) + } else if response.StatusCode != 200 { + fmt.Printf("Could not get manifest: %s\n", response.Status) + return + } + defer response.Body.Close() + + body, _ := ioutil.ReadAll(response.Body) + + var branches []BranchResponse + json.Unmarshal(body, &branches) + + + for _,v := range(branches) { + fmt.Printf("%s\t%s %s\n", v.Name, v.Commit.ID, v.Commit.Timestamp) + } + fmt.Println("done") + +} diff --git a/tools/src/updater/manifest.go b/tools/src/updater/manifest.go new file mode 100644 index 0000000..f9d3d86 --- /dev/null +++ b/tools/src/updater/manifest.go @@ -0,0 +1,16 @@ +package main + +import ( + "time" +) + +type CommitResponse struct { + ID string `json:"id"` + Timestamp time.Time `json:"timestamp"` +} + +type BranchResponse struct { + Name string `json:"name"` + Commit CommitResponse `json:"commit"` +} + |