Skip to content

Make it possible for users to download a specific version of a tool #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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.

Expand Down
52 changes: 32 additions & 20 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,38 @@ 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
return
}
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") {
Expand Down