summaryrefslogtreecommitdiff
path: root/cmd/confgraph
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-10-08 12:52:33 +0100
committerNick White <git@njw.name>2019-10-08 12:52:33 +0100
commit7482157a03ed3e9d7f45e54a126b391001f34948 (patch)
tree52f87b9ca159fe4c04a0349de95ea9de82692b3c /cmd/confgraph
parentd43c11bf653bfe3c1ad1ed277f1ec08bf155cf98 (diff)
Separate out bookpipeline from catch-all go.git repo, and rename to rescribe.xyz/bookpipeline
The dependencies from the go.git repo will follow in due course.
Diffstat (limited to 'cmd/confgraph')
-rw-r--r--cmd/confgraph/main.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/cmd/confgraph/main.go b/cmd/confgraph/main.go
new file mode 100644
index 0000000..474c0a2
--- /dev/null
+++ b/cmd/confgraph/main.go
@@ -0,0 +1,71 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "rescribe.xyz/bookpipeline"
+ "rescribe.xyz/go.git/lib/hocr"
+)
+
+func walker(confs *[]*bookpipeline.Conf) filepath.WalkFunc {
+ return func(path string, info os.FileInfo, err error) error {
+ if info.IsDir() {
+ return nil
+ }
+ if !strings.HasSuffix(path, ".hocr") {
+ return nil
+ }
+ avg, err := hocr.GetAvgConf(path)
+ if err != nil {
+ return err
+ }
+ c := bookpipeline.Conf{
+ Conf: avg,
+ Path: path,
+ }
+ *confs = append(*confs, &c)
+ return nil
+ }
+}
+
+func main() {
+ flag.Usage = func() {
+ fmt.Fprintln(flag.CommandLine.Output(), "Usage: bookpipeline hocrdir graph.png")
+ flag.PrintDefaults()
+ }
+ flag.Parse()
+
+ if flag.NArg() != 2 {
+ flag.Usage()
+ return
+ }
+
+ var confs []*bookpipeline.Conf
+ err := filepath.Walk(flag.Arg(0), walker(&confs))
+ if err != nil {
+ log.Fatalln("Failed to walk", flag.Arg(0), err)
+ }
+
+ // Structure to fit what bookpipeline.Graph needs
+ // TODO: probably reorganise bookpipeline to just need []*Conf
+ cconfs := make(map[string]*bookpipeline.Conf)
+ for _, c := range confs {
+ cconfs[c.Path] = c
+ }
+
+ fn := flag.Arg(1)
+ f, err := os.Create(fn)
+ if err != nil {
+ log.Fatalln("Error creating file", fn, err)
+ }
+ defer f.Close()
+ err = bookpipeline.Graph(cconfs, filepath.Base(flag.Arg(0)), f)
+ if err != nil {
+ log.Fatalln("Error creating graph", err)
+ }
+}