Pushing a bunch of hosuekeeper updates

This commit is contained in:
Matt Burchett
2018-11-14 03:51:03 +00:00
parent 254933c2f0
commit e9280412a7
7 changed files with 204 additions and 39 deletions

View File

@ -2,58 +2,58 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"time"
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/config"
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/locator"
)
func isOlder(t time.Time, days int) bool {
return time.Now().Sub(t) > 1*time.Hour
}
// func getFiles(location string, days int) ([]string, error) {
// var files []string
// err := filepath.Walk(location, func(path string, info os.FileInfo, err error) error {
// files = append(files, path)
// return nil
// })
// if err != nil {
// log.Fatal(err)
// }
func getFiles(location string, days int) ([]string, error) {
var files []string
err := filepath.Walk(location, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
log.Fatal(err)
}
// test := make([]string, 0)
test := make([]string, 0)
// for _, file := range files {
// at, err := os.Stat(file)
// if err != nil {
// log.Fatal(err)
// }
// if isOlder(at.ModTime(), days) {
// test = append(test, file)
// }
for _, file := range files {
at, err := os.Stat(file)
if err != nil {
log.Fatal(err)
}
if isOlder(at.ModTime(), days) {
test = append(test, file)
}
// }
}
// return test, err
return test, err
}
// }
func main() {
var location string
var c string
var days int
flag.StringVar(&location, "location", "", "location to scan")
flag.IntVar(&days, "days", 0, "days to poll")
flag.Parse()
var sectionID int
files, err := getFiles(location, days)
flag.StringVar(&c, "c", "", "Configuration to load")
flag.IntVar(&days, "days", 0, "days to poll")
flag.IntVar(&sectionID, "sectionid", 0, "pick a section ID")
flag.Parse()
if c == "" {
log.Fatal("You need to specify a configuration file.")
}
if sectionID == 0 {
log.Fatal("You need to specify a section ID for Plex.")
}
cfg, err := config.GetConfig(c)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
fmt.Println(file)
}
locator.GetCount(cfg, sectionID)
}