Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
unreal committed Jan 25, 2023
1 parent e5f879a commit 86dc507
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
31 changes: 16 additions & 15 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ var filters map[string][]string
var robotNamelistFlag project.RobotNamelist

func init() {
filters = make(map[string][]string)
filters["all"] = []string{"*.*"}
filters["tp"] = []string{"*.tp"}
filters["ls"] = []string{"*.ls"}
filters["vr"] = []string{"*.vr"}
filters["va"] = []string{"*.va"}
filters["sv"] = []string{"*.sv"}
filters["vision"] = []string{"*.vd", "*.vda", "*.zip"}
filters["app"] = []string{"*.tp", "numreg.vr", "posreg.vr"}
filters["ascii"] = []string{"*.ls", "*.va", "*.dat", "*.dg", "*.xml"}
filters["bin"] = []string{"*.zip", "*.sv", "*.tp", "*.vr"}

flag.Var(&robotNamelistFlag, "r", "comma-separated list of robot names")
filters = make(map[string][]string)
filters["all"] = []string{"*.*"}
filters["tp"] = []string{"*.tp"}
filters["ls"] = []string{"*.ls"}
filters["vr"] = []string{"*.vr"}
filters["va"] = []string{"*.va"}
filters["sv"] = []string{"*.sv"}
filters["vision"] = []string{"*.vd", "*.vda", "*.zip"}
filters["app"] = []string{"*.tp", "numreg.vr", "posreg.vr"}
filters["ascii"] = []string{"*.ls", "*.va", "*.dat", "*.dg", "*.xml"}
filters["bin"] = []string{"*.zip", "*.sv", "*.tp", "*.vr"}

flag.Var(&robotNamelistFlag, "r", "comma-separated list of robot names")
}

func usage() {
Expand Down Expand Up @@ -59,7 +59,7 @@ to the current project.`)
}

func backupUsage() {
fmt.Println(`
fmt.Printf(`
usage: backuptool backup [flags] filter
The filters are:
Expand All @@ -77,6 +77,7 @@ The filters are:
The flags are:
-r comma-separated list of robot names
Used to backup a subset of the project's robots
`)
}

Expand Down Expand Up @@ -118,7 +119,7 @@ func main() {
os.Exit(1)
}

filter, ok := filters[args[1]];
filter, ok := filters[args[1]]
if !ok {
fmt.Printf("Invalid filter: %s\n", args[1])
backupUsage()
Expand Down
2 changes: 1 addition & 1 deletion ftp/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Connection) debugResponse(code int, msg string) {
}

func (c *Connection) Connect() error {
c.debugf("Connecting to", c.addr+":"+c.port)
c.debugf("Connecting to %s", c.addr+":"+c.port)
conn, err := net.Dial("tcp", c.addr+":"+c.port)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/onerobotics/backup

go 1.17
9 changes: 3 additions & 6 deletions project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (r *RobotNamelist) Set(value string) error {
return nil
}


type Project struct {
Destination string
Version string
Expand All @@ -58,15 +57,15 @@ func (p *Project) fromJSON() error {
func (p *Project) fromWizard() error {
r := bufio.NewReader(os.Stdin)

questions:
questions:
fmt.Println("Where should backups be stored?")
dest, err := r.ReadString('\n')
if err != nil {
return err
}
dest = strings.TrimSpace(dest)

confirm:
confirm:
fmt.Printf("Destination: %s\n", dest)
fmt.Println("Is this correct? (Y/N)")

Expand All @@ -91,7 +90,6 @@ func (p *Project) fromWizard() error {
return p.Save()
}


func Init() (*Project, error) {
p := &Project{}

Expand Down Expand Up @@ -140,8 +138,7 @@ func (p *Project) RemoveRobot() error {
return nil
}


list:
list:
for id, robot := range p.Robots {
fmt.Printf("%d. %s %s\n", id+1, robot.Name, robot.Host)
}
Expand Down
6 changes: 4 additions & 2 deletions robot/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (r Robot) Backup(filter func(filename string) bool, destination string, wg
}

c := ftp.NewConnection(r.Host, "21")
c.Connect()
err = c.Connect()
if err != nil {
return err
}
defer c.Quit()

files, err := c.NameList()
Expand Down Expand Up @@ -104,4 +107,3 @@ func (r Robot) Backup(filter func(filename string) bool, destination string, wg

return nil
}

0 comments on commit 86dc507

Please sign in to comment.