Commit 8092b735 authored by Joan Piles's avatar Joan Piles

Prettified and minor cosmetic changes

parent 685a0c83
......@@ -17,9 +17,9 @@ import (
)
const (
myName = "snaprd"
defaultSchedFileName = "/etc/"+myName+".schedules"
DATA_SUBDIR = ".data"
myName = "snaprd"
defaultSchedFileName = "/etc/" + myName + ".schedules"
DATA_SUBDIR = ".data"
)
type Opts []string
......@@ -81,8 +81,8 @@ func (c *Config) ReadCache() error {
c.RsyncPath = t.RsyncPath
c.RsyncOpts = t.RsyncOpts
if t.SchedFile != "" {
c.SchedFile = t.SchedFile
schedules.AddFromFile(c.SchedFile)
c.SchedFile = t.SchedFile
schedules.AddFromFile(c.SchedFile)
}
c.Origin = t.Origin
if _, ok := schedules[t.Schedule]; ok == false {
......@@ -152,11 +152,11 @@ func LoadConfig() *Config {
flags.StringVar(&(config.SchedFile),
"schedFile", defaultSchedFileName,
"path to external schedules")
flags.Parse(os.Args[2:])
flags.Parse(os.Args[2:])
if config.SchedFile != "" {
schedules.AddFromFile(config.SchedFile)
schedules.AddFromFile(config.SchedFile)
}
if _, ok := schedules[config.Schedule]; ok == false {
if _, ok := schedules[config.Schedule]; ok == false {
log.Fatalln("no such schedule:", config.Schedule)
}
path := filepath.Join(config.repository, DATA_SUBDIR)
......@@ -189,11 +189,11 @@ func LoadConfig() *Config {
flags.StringVar(&(config.SchedFile),
"schedFile", defaultSchedFileName,
"path to external schedules")
flags.Parse(os.Args[2:])
flags.Parse(os.Args[2:])
if config.SchedFile != "" {
schedules.AddFromFile(config.SchedFile)
schedules.AddFromFile(config.SchedFile)
}
err := config.ReadCache()
err := config.ReadCache()
if err != nil {
log.Println("error reading cached settings (using defaults):", err)
}
......@@ -213,7 +213,7 @@ func LoadConfig() *Config {
"path to external schedules")
flags.Parse(os.Args[2:])
if config.SchedFile != "" {
schedules.AddFromFile(config.SchedFile)
schedules.AddFromFile(config.SchedFile)
}
return config
}
......
......@@ -5,12 +5,12 @@
package main
import (
"strings"
"time"
"encoding/json"
"io/ioutil"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
)
const (
......@@ -72,30 +72,30 @@ func (schl scheduleList) AddFromFile(file string) {
if _, err := os.Stat(file); os.IsNotExist(err) && file == defaultSchedFileName {
return
}
schedFile, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("Error opening schedule file: %v\n", err)
return
}
var readData map[string]jsonInterval
err = json.Unmarshal(schedFile,&readData)
err = json.Unmarshal(schedFile, &readData)
if err != nil {
fmt.Printf("Error parsing data: %v\n", err)
return
}
for k,v := range readData {
for k, v := range readData {
schl[k] = v.IntervalList()
}
}
}
// Prints the stored schedules in the list
func (schl scheduleList) List() {
for name,sched := range schl {
fmt.Println(name,": ", sched);
for name, sched := range schl {
fmt.Println(name, ": ", sched)
}
}
......@@ -110,27 +110,27 @@ func (schl scheduleList) List() {
// { 1*day + 12*hour, 2*week, 1*month + 2*week, long }
func (json jsonInterval) IntervalList() intervalList {
il := make(intervalList,len(json))
for i,interval := range json {
il := make(intervalList, len(json))
for i, interval := range json {
var duration time.Duration = 0
Loop:
for k,v := range interval {
Loop:
for k, v := range interval {
switch k {
case "s","second":
case "s", "second":
duration += v * second
case "m","minute":
case "m", "minute":
duration += v * minute
case "h","hour":
case "h", "hour":
duration += v * hour
case "d","day":
case "d", "day":
duration += v * day
case "w","week":
case "w", "week":
duration += v * week
case "M","month":
case "M", "month":
duration += v * month
case "y","year":
case "y", "year":
duration += v * year
case "l","long":
case "l", "long":
duration = long
break Loop
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment