From cbe605e71a2a2f8be42b038bdc998a068f70df7d Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Thu, 18 Aug 2016 12:47:44 +0200 Subject: [PATCH 1/2] Make it possible for users to download a specific version of a tool --- README.md | 11 +++++++++-- hub.go | 51 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b260a0fd1..651bdd2b2 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ $ launchctl unload ~/Library/LaunchAgents/ArduinoCreateAgent.plist 2. Select the .config dir in your home ![Select the .config dir in your home](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/02.png) -3. Select the autostart dir +3. Select the autostart dir ![Select the autostart dir](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/03.png) 4. Move the file to the trash @@ -248,7 +248,7 @@ You can receive output from the serial port by listening to messages like this: ### Download a tool You can download a tool on the computer with a command like - download avrdude + downloadtool avrdude 6.0.1-arduino5 replace receiving a reply like @@ -259,6 +259,13 @@ receiving a reply like } ``` +The syntax of the command is: + + downloadtool {{name}} {{version}} {{behaviour}} + +where `version` can be a version number of the string "latest", and `behaviour` can be +"keep" (which skip the download if the tool already exists) and "replace" (which will download it again). + ### Upload You can upload a binary sketch to a board connected to a port with a POST request to be made at the http endpoint. diff --git a/hub.go b/hub.go index 9fcc94430..070c35ed5 100755 --- a/hub.go +++ b/hub.go @@ -190,26 +190,37 @@ func checkCmd(m []byte) { go spList(false) go spList(true) } else if strings.HasPrefix(sl, "downloadtool") { - args := strings.Split(s, " ") - if len(args) > 1 { - go func() { - var err error - if args[1] == "avrdude" { - err = Tools.Download(args[1], "6.0.1-arduino5", "keep") - } else { - err = Tools.Download(args[1], "latest", "keep") - } - if err != nil { - mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()} - mapB, _ := json.Marshal(mapD) - h.broadcastSys <- mapB - } else { - mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"} - mapB, _ := json.Marshal(mapD) - h.broadcastSys <- mapB - } - }() - } + go func() { + args := strings.Split(s, " ") + var tool, toolVersion, behaviour string + toolVersion = "latest" + behaviour = "keep" + if len(args) < 1 { + mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"} + mapB, _ := json.Marshal(mapD) + h.broadcastSys <- mapB + } + if len(args) > 1 { + tool = args[1] + } + if len(args) > 2 { + toolVersion = args[2] + } + if len(args) > 3 { + behaviour = args[3] + } + + err := Tools.Download(tool, toolVersion, behaviour) + if err != nil { + mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()} + mapB, _ := json.Marshal(mapD) + h.broadcastSys <- mapB + } else { + mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"} + mapB, _ := json.Marshal(mapD) + h.broadcastSys <- mapB + } + }() } else if strings.HasPrefix(sl, "bufferalgorithm") { go spBufferAlgorithms() } else if strings.HasPrefix(sl, "log") { From 3a27d637c47c233e161b4cd988c4f59e982a629b Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Thu, 18 Aug 2016 12:50:41 +0200 Subject: [PATCH 2/2] Fix error management for downloadtool --- hub.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hub.go b/hub.go index 070c35ed5..17363e48f 100755 --- a/hub.go +++ b/hub.go @@ -195,10 +195,11 @@ func checkCmd(m []byte) { var tool, toolVersion, behaviour string toolVersion = "latest" behaviour = "keep" - if len(args) < 1 { + if len(args) <= 1 { mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"} mapB, _ := json.Marshal(mapD) h.broadcastSys <- mapB + return } if len(args) > 1 { tool = args[1]