From 37bbc4658d4933f1ce2db56bf3bde653118fb5e2 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Wed, 2 Sep 2020 01:30:27 -0400 Subject: [PATCH] Add a TON of error handling that was previously skipped (intentionally but really needs to be there) ; added basic filesystem walk of albums dir to facilitate config of which albums are used for the slideshow --- cmd/ui/ui.go | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/cmd/ui/ui.go b/cmd/ui/ui.go index 81cd4cc..433dd4e 100644 --- a/cmd/ui/ui.go +++ b/cmd/ui/ui.go @@ -6,7 +6,9 @@ import ( "log" "math" "net" + "os" "os/exec" + "path/filepath" "strconv" "strings" @@ -18,10 +20,12 @@ import ( ) const ( - CMD_SYSTEMCTL = "/usr/bin/systemctl" - CMD_FINDMNT = "/usr/bin/findmnt" - CMD_VCGENCMD = "/opt/vc/bin/vcgencmd" - FILE_CPU_TEMP = "/sys/class/thermal/thermal_zone0/temp" + CMD_SYSTEMCTL = "/usr/bin/systemctl" + CMD_FINDMNT = "/usr/bin/findmnt" + CMD_VCGENCMD = "/opt/vc/bin/vcgencmd" + FILE_CPU_TEMP = "/sys/class/thermal/thermal_zone0/temp" + ALBUM_ROOT_DIR = "/tank/pictures" + SYNCTHING_FOLDER_SKIP = ".stfolder" ) const ( @@ -42,29 +46,56 @@ func main() { // Network interfaces for status panel ifaces, err := net.Interfaces() if err != nil { - log.Printf("Error getting netork interfaces : %s", err) + log.Fatalf("Error getting netork interfaces : %s", err) return } // Disk use - findmntOut, _ := exec.Command(CMD_FINDMNT, "-n", "-l", + findmntOut, err := exec.Command(CMD_FINDMNT, "-n", "-l", "-o", "TARGET,USE%", "-t", "ext4,exfat,vfat,btrfs,zfs,xfs").Output() + if err != nil { + log.Fatalf("Error getting disk use : %s", err) + } filesystems := strings.Split(strings.Trim(string(findmntOut), "\n"), "\n") // GPU Temp - vcgencmdOut, _ := exec.Command(CMD_VCGENCMD, "measure_temp").Output() + vcgencmdOut, err := exec.Command(CMD_VCGENCMD, "measure_temp").Output() + if err != nil { + log.Fatalf("Error getting GPU temp : %s", err) + } gpuTemp := strings.Split(strings.Trim(string(vcgencmdOut), "\n"), "=")[1] // CPU Temp cpuTempFileContents, err := ioutil.ReadFile(FILE_CPU_TEMP) if err != nil { - log.Fatalf("Error reading file %s : %s", FILE_CPU_TEMP, err) + log.Fatalf("Error getting CPU temp : %s", err) } cpuTempStr := strings.Trim(string(cpuTempFileContents), "\n") - cpuTempInt, _ := strconv.Atoi(cpuTempStr) + cpuTempInt, err := strconv.Atoi(cpuTempStr) + if err != nil { + log.Fatalf("Error processing CPU temp : %S", err) + } cpuTemp := fmt.Sprintf("%.2f'C", float64(cpuTempInt)/1000.0) + // Get list of all folders that can be used as albums + var albums []string + err = filepath.Walk(ALBUM_ROOT_DIR, func(path string, fi os.FileInfo, err error) error { + if err != nil { + return err + } + if fi.IsDir() { + if strings.Contains(path, SYNCTHING_FOLDER_SKIP) { + return nil + } + albums = append(albums, path) + } + return nil + }) + if err != nil { + log.Fatalf("Error getting list of albums : %s", err) + } + // Run config UI when slideshow stops app := tview.NewApplication()