Skip to content

Find the tool given the packager #125

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 10, 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
16 changes: 12 additions & 4 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ func checkCmd(m []byte) {
} else if strings.HasPrefix(sl, "downloadtool") {
go func() {
args := strings.Split(s, " ")
var tool, toolVersion, behaviour string
var tool, toolVersion, pack, behaviour string
toolVersion = "latest"
pack = "arduino"
behaviour = "keep"
if len(args) <= 1 {
mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"}
Expand All @@ -205,13 +206,20 @@ func checkCmd(m []byte) {
tool = args[1]
}
if len(args) > 2 {
toolVersion = args[2]
if strings.HasPrefix(args[2], "http") {
//old APIs, ignore this field
} else {
toolVersion = args[2]
}
}
if len(args) > 3 {
behaviour = args[3]
pack = args[3]
}
if len(args) > 4 {
behaviour = args[4]
}

err := Tools.Download(tool, toolVersion, behaviour)
err := Tools.Download(pack, tool, toolVersion, behaviour)
if err != nil {
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
mapB, _ := json.Marshal(mapD)
Expand Down
12 changes: 8 additions & 4 deletions tools/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (t *Tools) DownloadPackageIndex(index_file, signature_file string) error {
// It will extract it in a folder in .arduino-create, and it will update the
// Installed map.
//
// pack contains the packager of the tool
// name contains the name of the tool.
// version contains the version of the tool.
// behaviour contains the strategy to use when there is already a tool installed
Expand All @@ -140,7 +141,7 @@ func (t *Tools) DownloadPackageIndex(index_file, signature_file string) error {
// If version is not "latest" and behaviour is "replace", it will download the
// version again. If instead behaviour is "keep" it will not download the version
// if it already exists.
func (t *Tools) Download(name, version, behaviour string) error {
func (t *Tools) Download(pack, name, version, behaviour string) error {

index_file := path.Join(t.Directory, "package_index.json")
signature_file := path.Join(t.Directory, "package_index.json.sig")
Expand Down Expand Up @@ -169,10 +170,10 @@ func (t *Tools) Download(name, version, behaviour string) error {
t.Logger.Println(string(body))

// Find the tool by name
correctTool, correctSystem := findTool(name, version, data)
correctTool, correctSystem := findTool(pack, name, version, data)

if correctTool.Name == "" || correctSystem.URL == "" {
t.Logger.Println("We couldn't find a tool with the name " + name + " and version " + version)
t.Logger.Println("We couldn't find a tool with the name " + name + " and version " + version + " packaged by " + pack)
return nil
}

Expand Down Expand Up @@ -255,11 +256,14 @@ func (t *Tools) Download(name, version, behaviour string) error {
return t.writeMap()
}

func findTool(name, version string, data index) (tool, system) {
func findTool(pack, name, version string, data index) (tool, system) {
var correctTool tool
correctTool.Version = "0.0"

for _, p := range data.Packages {
if p.Name != pack {
continue
}
for _, t := range p.Tools {
if version != "latest" {
if t.Name == name && t.Version == version {
Expand Down