github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/deploy/jobs/writers.go (about) 1 package jobs 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 "path/filepath" 8 ) 9 10 // [zr] this should go (currently used by the nameReg writer) 11 // WriteJobResultCSV takes two strings and writes those to the delineated log 12 // file, which is currently deploy.log in the same directory as the deploy.yaml 13 func WriteJobResultCSV(name, result string) error { 14 15 pwd, _ := os.Getwd() 16 logFile := filepath.Join(pwd, "jobs_output.csv") 17 18 var file *os.File 19 var err error 20 21 if _, err := os.Stat(logFile); os.IsNotExist(err) { 22 file, err = os.Create(logFile) 23 if err != nil { 24 return err 25 } 26 } else { 27 file, err = os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY, 0600) 28 if err != nil { 29 return err 30 } 31 } 32 33 if err != nil { 34 return err 35 } 36 37 defer file.Close() 38 39 text := fmt.Sprintf("%s,%s\n", name, result) 40 _, err = file.WriteString(text) 41 42 return err 43 } 44 45 func WriteJobResultJSON(results map[string]interface{}, logFile string) error { 46 if logFile == "" { 47 return nil 48 } 49 file, err := os.Create(logFile) 50 if err != nil { 51 return err 52 } 53 defer file.Close() 54 55 res, err := json.MarshalIndent(results, "", " ") 56 if err != nil { 57 return err 58 } 59 if _, err = file.Write(res); err != nil { 60 return err 61 } 62 63 return nil 64 }