summaryrefslogtreecommitdiff
path: root/cmd/rescribe/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-12-20 15:13:53 +0000
committerNick White <git@njw.name>2021-12-20 15:13:53 +0000
commit4bfc22f97fc081275568af20d5cfd84c71d516cd (patch)
treeb767bd91000492c68a424778ec0f0c69cdabd47d /cmd/rescribe/main.go
parent6ea3243f252bc4944c566a457da227a65639ecc7 (diff)
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
Diffstat (limited to 'cmd/rescribe/main.go')
-rw-r--r--cmd/rescribe/main.go20
1 files changed, 10 insertions, 10 deletions
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)