From 025ccb8054087c664acc6f78d9cf51f563326a80 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 28 Jan 2017 01:29:29 +0100 Subject: loading of file hasher config and writing log files works now diff --git a/.gitignore b/.gitignore index ff7ecdf..16ef3f2 100644 --- a/.gitignore +++ b/.gitignore @@ -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) } -- cgit v0.10.2