summaryrefslogtreecommitdiff
path: root/internal/pipeline/get.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-11-10 10:41:15 +0000
committerNick White <git@njw.name>2020-11-10 10:41:15 +0000
commit198f8215f8dd0460608abcd03fa49451462c9d11 (patch)
treefc762e9d45154c6277591743f046d6f0dd0fc88c /internal/pipeline/get.go
parentc48630f590fe2c877e899948f1bf88458d3fd813 (diff)
[getpipelinebook] Rewrite to use internal package functions
Diffstat (limited to 'internal/pipeline/get.go')
-rw-r--r--internal/pipeline/get.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/internal/pipeline/get.go b/internal/pipeline/get.go
index 8492d99..6949062 100644
--- a/internal/pipeline/get.go
+++ b/internal/pipeline/get.go
@@ -9,9 +9,10 @@ import (
"fmt"
"os"
"path/filepath"
+ "strings"
)
-func DownloadBestPages(name string, conn Pipeliner) error {
+func DownloadBestPages(name string, conn Pipeliner, pluspngs bool) error {
fn := filepath.Join(name, "best")
err := conn.Download(conn.WIPStorageId(), fn, fn)
if err != nil {
@@ -26,12 +27,27 @@ func DownloadBestPages(name string, conn Pipeliner) error {
s := bufio.NewScanner(f)
for s.Scan() {
fn = filepath.Join(name, s.Text())
+ conn.Log("Downloading file", fn)
err = conn.Download(conn.WIPStorageId(), fn, fn)
if err != nil {
return fmt.Errorf("Failed to download file %s: %v", fn, err)
}
}
+ if !pluspngs {
+ return nil
+ }
+
+ s = bufio.NewScanner(f)
+ for s.Scan() {
+ txtfn := filepath.Join(name, s.Text())
+ fn = strings.Replace(txtfn, ".hocr", ".png", 1)
+ conn.Log("Downloading file", fn)
+ err = conn.Download(conn.WIPStorageId(), fn, fn)
+ if err != nil {
+ return fmt.Errorf("Failed to download file", fn, err)
+ }
+ }
return nil
}
@@ -56,3 +72,18 @@ func DownloadAnalyses(name string, conn Pipeliner) error {
}
return nil
}
+
+func DownloadAll(name string, conn Pipeliner) error {
+ objs, err := conn.ListObjects(conn.WIPStorageId(), name)
+ if err != nil {
+ return fmt.Errorf("Failed to get list of files for book", name, err)
+ }
+ for _, i := range objs {
+ conn.Log("Downloading", i)
+ err = conn.Download(conn.WIPStorageId(), i, i)
+ if err != nil {
+ return fmt.Errorf("Failed to download file", i, err)
+ }
+ }
+ return nil
+}