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
This commit is contained in:
parent
e3008a6d43
commit
37bbc4658d
49
cmd/ui/ui.go
49
cmd/ui/ui.go
|
@ -6,7 +6,9 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -18,10 +20,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CMD_SYSTEMCTL = "/usr/bin/systemctl"
|
CMD_SYSTEMCTL = "/usr/bin/systemctl"
|
||||||
CMD_FINDMNT = "/usr/bin/findmnt"
|
CMD_FINDMNT = "/usr/bin/findmnt"
|
||||||
CMD_VCGENCMD = "/opt/vc/bin/vcgencmd"
|
CMD_VCGENCMD = "/opt/vc/bin/vcgencmd"
|
||||||
FILE_CPU_TEMP = "/sys/class/thermal/thermal_zone0/temp"
|
FILE_CPU_TEMP = "/sys/class/thermal/thermal_zone0/temp"
|
||||||
|
ALBUM_ROOT_DIR = "/tank/pictures"
|
||||||
|
SYNCTHING_FOLDER_SKIP = ".stfolder"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -42,29 +46,56 @@ func main() {
|
||||||
// Network interfaces for status panel
|
// Network interfaces for status panel
|
||||||
ifaces, err := net.Interfaces()
|
ifaces, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error getting netork interfaces : %s", err)
|
log.Fatalf("Error getting netork interfaces : %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disk use
|
// Disk use
|
||||||
findmntOut, _ := exec.Command(CMD_FINDMNT, "-n", "-l",
|
findmntOut, err := exec.Command(CMD_FINDMNT, "-n", "-l",
|
||||||
"-o", "TARGET,USE%",
|
"-o", "TARGET,USE%",
|
||||||
"-t", "ext4,exfat,vfat,btrfs,zfs,xfs").Output()
|
"-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")
|
filesystems := strings.Split(strings.Trim(string(findmntOut), "\n"), "\n")
|
||||||
|
|
||||||
// GPU Temp
|
// 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]
|
gpuTemp := strings.Split(strings.Trim(string(vcgencmdOut), "\n"), "=")[1]
|
||||||
|
|
||||||
// CPU Temp
|
// CPU Temp
|
||||||
cpuTempFileContents, err := ioutil.ReadFile(FILE_CPU_TEMP)
|
cpuTempFileContents, err := ioutil.ReadFile(FILE_CPU_TEMP)
|
||||||
if err != nil {
|
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")
|
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)
|
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
|
// Run config UI when slideshow stops
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue