From 4bfc22f97fc081275568af20d5cfd84c71d516cd Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 20 Dec 2021 15:13:53 +0000 Subject: rescribe: Ensure temporary tesseract data is only removed when the program ends, so multiple books can be processed by the gui one after the other --- cmd/rescribe/main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'cmd/rescribe/main.go') diff --git a/cmd/rescribe/main.go b/cmd/rescribe/main.go index 229bf49..72a03d3 100644 --- a/cmd/rescribe/main.go +++ b/cmd/rescribe/main.go @@ -237,7 +237,7 @@ These training files are included in rescribe, and are always available: } if flag.NArg() < 1 || *usegui { - err := startGui(*verboselog, tessCommand, trainingName, *systess, tessdir) + err := startGui(*verboselog, tessCommand, trainingName, tessdir) err = os.RemoveAll(tessdir) if err != nil { log.Printf("Error removing tesseract directory %s: %v", tessdir, err) @@ -279,11 +279,18 @@ These training files are included in rescribe, and are always available: ispdf = true } - err = startProcess(*verboselog, tessCommand, bookdir, bookname, trainingName, *systess, savedir, tessdir) + err = startProcess(*verboselog, tessCommand, bookdir, bookname, trainingName, savedir, tessdir) if err != nil { log.Fatalln(err) } + if !*systess { + err = os.RemoveAll(tessdir) + if err != nil { + log.Printf("Error removing tesseract directory %s: %v", tessdir, err) + } + } + if ispdf { os.RemoveAll(filepath.Clean(filepath.Join(bookdir, ".."))) } @@ -392,7 +399,7 @@ func rmIfNotImage(f string) error { return nil } -func startProcess(logger log.Logger, tessCommand string, bookdir string, bookname string, trainingName string, systess bool, savedir string, tessdir string) error { +func startProcess(logger log.Logger, tessCommand string, bookdir string, bookname string, trainingName string, savedir string, tessdir string) error { _, err := exec.Command(tessCommand, "--help").Output() if err != nil { errmsg := "Error, Can't run Tesseract\n" @@ -449,13 +456,6 @@ func startProcess(logger log.Logger, tessCommand string, bookdir string, booknam return fmt.Errorf("Error removing temporary directory %s: %v", tempdir, err) } - if !systess { - err = os.RemoveAll(tessdir) - if err != nil { - return fmt.Errorf("Error removing tesseract directory %s: %v", tessdir, err) - } - } - hocrs, err := filepath.Glob(fmt.Sprintf("%s%s*.hocr", savedir, string(filepath.Separator))) if err != nil { return fmt.Errorf("Error looking for .hocr files: %v", err) -- cgit v1.2.1-24-ge1ad