diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/pool-import/file-hasher.go | 30 | ||||
-rw-r--r-- | src/pool-import/main.go | 22 |
3 files changed, 37 insertions, 16 deletions
@@ -3,3 +3,4 @@ pkg/ src/github.com src/code.helsinki.at src/golang.org +P_test/ diff --git a/src/pool-import/file-hasher.go b/src/pool-import/file-hasher.go index 43dc6d9..df58a8e 100644 --- a/src/pool-import/file-hasher.go +++ b/src/pool-import/file-hasher.go @@ -26,22 +26,42 @@ import ( "encoding/json" "os" "os/exec" + "path/filepath" + "time" ) type FileMap map[string]string -// TODO: actually call this via ssh -func callFileHasher() (files FileMap, err error) { +func openGroupConfig(group string) (*os.File, error) { + cwd, err := filepath.Abs(".") + if err != nil { + return nil, err + } + fileName := filepath.Join(cwd, filepath.Clean("/"+group+"/config.json")) + return os.Open(fileName) +} + +func createLogFile(group string) (log *os.File, err error) { + cwd, err := filepath.Abs(".") + if err != nil { + return nil, err + } + fileName := filepath.Join(cwd, filepath.Clean("/"+group), "logs", time.Now().Format(time.RFC3339)+".json") + return os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640) +} + +func callFileHasher(group string) (files FileMap, err error) { var stdin, log *os.File - if stdin, err = os.Open("sample/file-hasher-requst.json"); err != nil { + if stdin, err = openGroupConfig(group); err != nil { return } - if log, err = os.OpenFile("file-hasher.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640); err != nil { + if log, err = createLogFile(group); err != nil { return } + var stdout bytes.Buffer + // TODO: actually call this via ssh cmd := exec.Command("bin/file-hasher") - var stdout bytes.Buffer cmd.Stdin = stdin cmd.Stdout = &stdout cmd.Stderr = log diff --git a/src/pool-import/main.go b/src/pool-import/main.go index 8e68d15..cd52c2f 100644 --- a/src/pool-import/main.go +++ b/src/pool-import/main.go @@ -80,22 +80,22 @@ func main() { stdlog.Printf("*** will import into group '%s'", group) stdlog.Println("***************************************************************") - carts, err := db.GetInterface().GetPoolCartList(rddb.PoolListEntry{Group: group}) - if err != nil { - stdlog.Fatal("Error fetching Pool Carts:", err) - } - - stdlog.Printf("got %d carts from pool:", len(carts)) - for _, cart := range carts { - stdlog.Printf(" %d: '%s' | %s / %s / %s)", cart.Number, cart.UserDefined, cart.Artist, cart.Album, cart.Title) - } - go func() { defer func() { C <- syscall.SIGTERM }() - files, err := callFileHasher() + carts, err := db.GetInterface().GetPoolCartList(rddb.PoolListEntry{Group: group}) + if err != nil { + stdlog.Fatal("Error fetching Pool Carts:", err) + } + + stdlog.Printf("got %d carts from pool:", len(carts)) + for _, cart := range carts { + stdlog.Printf(" %d: '%s' | %s / %s / %s)", cart.Number, cart.UserDefined, cart.Artist, cart.Album, cart.Title) + } + + files, err := callFileHasher(group) if err != nil { stdlog.Fatal("Calling file hasher failed:", err) } |