Skip to content

[WIP] Download tools refactoring #95

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 24 commits into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
54b274f
Move utilities to a package to keep things clean
matteosuppo Mar 1, 2016
b6c0cbc
Move initialization of tools in package tools
matteosuppo Mar 1, 2016
3785777
Move the function to download tools in a package
matteosuppo Mar 1, 2016
92da217
Make the indexurl configurable
matteosuppo Mar 3, 2016
57fdc3e
Fix a typo for darwin
matteosuppo Mar 3, 2016
a3991cf
Fix stupid typo again
matteosuppo Mar 3, 2016
d083191
Foxed conflicts in main
matteosuppo Apr 21, 2016
22c5028
[WIP] Working download toold from json
facchinm May 5, 2016
d603c93
Add "github.com/blang/semver" to govendor
facchinm May 11, 2016
62fa42b
adding github.com/blang/semver sources
facchinm May 11, 2016
700a888
move TellCommandNotToSpawnShell to tools package
facchinm May 11, 2016
cbe8007
address filepath issue
facchinm May 11, 2016
33c4356
execute post_install.bat if contained in downloaded tool
facchinm May 11, 2016
fcb34fd
modify reference package_json and call post_install
facchinm May 11, 2016
95a9232
rework "latest" behaviour
facchinm May 11, 2016
1acfc46
remove useless log on windows
facchinm May 11, 2016
1d2a4b7
[WIN] solve some path-replated bugs
facchinm May 11, 2016
2ea2c2a
handle Verbose parameters
facchinm May 12, 2016
e2b5a2a
add exclude list for extended header "files"
facchinm May 12, 2016
2a8dfff
[STUB] add GPG check on package_index
facchinm May 12, 2016
453530a
add time handling in tools
facchinm May 13, 2016
bfd2fb4
GPG check and avoid redownloading the json every time
facchinm May 13, 2016
30a2a69
use https to download package_index.json
facchinm May 13, 2016
b663ce9
add golang.org/x/crypto/openpgp/armor to govendor
facchinm May 13, 2016
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
Prev Previous commit
Next Next commit
Move initialization of tools in package tools
  • Loading branch information
matteosuppo authored and facchinm committed May 5, 2016
commit b6c0cbc678a00429679671d796b99fed3e69b39b
4 changes: 3 additions & 1 deletion hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/arduino/arduino-create-agent/tools"
"github.com/kardianos/osext"
//"os"
"os/exec"
Expand Down Expand Up @@ -191,7 +193,7 @@ func checkCmd(m []byte) {
} else if strings.HasPrefix(sl, "downloadtool") {
args := strings.Split(s, " ")
if len(args) > 2 {
go spDownloadTool(args[1], args[2])
go tools.Download(args[1], args[2])
}
} else if strings.HasPrefix(sl, "bufferalgorithm") {
go spBufferAlgorithms()
Expand Down
15 changes: 6 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ package main
import (
"flag"
"os"
"os/user"
"path/filepath"
"runtime/debug"
"strconv"
"text/template"
"time"

log "github.com/Sirupsen/logrus"
<<<<<<< e73846650fde9b0955aa35e237100ec552af47fb
=======
"github.com/arduino/arduino-create-agent/tools"
"github.com/carlescere/scheduler"
>>>>>>> Move initialization of tools in package tools
"github.com/gin-gonic/gin"
"github.com/itsjamie/gin-cors"
"github.com/kardianos/osext"
Expand All @@ -39,7 +43,6 @@ var (
appName = flag.String("appName", "", "")
genCert = flag.Bool("generateCert", false, "")
globalToolsMap = make(map[string]string)
tempToolsPath = createToolsDir()
port string
portSSL string
origins = flag.String("origins", "", "Allowed origin list for CORS")
Expand All @@ -60,11 +63,6 @@ func (u *logWriter) Write(p []byte) (n int, err error) {

var logger_ws logWriter

func createToolsDir() string {
usr, _ := user.Current()
return usr.HomeDir + "/.arduino-create"
}

func homeHandler(c *gin.Context) {
homeTemplate.Execute(c.Writer, c.Request.Host)
}
Expand Down Expand Up @@ -92,8 +90,7 @@ func main() {
src, _ := osext.Executable()
dest := filepath.Dir(src)

os.Mkdir(tempToolsPath, 0777)
hideFile(tempToolsPath)
tools.CreateDir()

if embedded_autoextract {
// save the config.ini (if it exists)
Expand Down
3 changes: 0 additions & 3 deletions seriallist_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,5 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
return ports
}

func hideFile(path string) {
}

func tellCommandNotToSpawnShell(_ *exec.Cmd) {
}
3 changes: 0 additions & 3 deletions seriallist_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
return ports
}

func hideFile(path string) {
}

func tellCommandNotToSpawnShell(_ *exec.Cmd) {
}
14 changes: 4 additions & 10 deletions seriallist_windows.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package main

import (
log "github.com/Sirupsen/logrus"
"github.com/mattn/go-ole"
"github.com/mattn/go-ole/oleutil"
"os"
"os/exec"
"regexp"
"strings"
"sync"
"syscall"

log "github.com/Sirupsen/logrus"
"github.com/mattn/go-ole"
"github.com/mattn/go-ole/oleutil"
)

var (
Expand Down Expand Up @@ -62,13 +63,6 @@ func getListSynchronously() {

}

func hideFile(path string) {
cpath, cpathErr := syscall.UTF16PtrFromString(path)
if cpathErr != nil {
}
syscall.SetFileAttributes(cpath, syscall.FILE_ATTRIBUTE_HIDDEN)
}

func getListViaWmiPnpEntity() ([]OsSerialPort, os.SyscallError) {

//log.Println("Doing getListViaWmiPnpEntity()")
Expand Down
5 changes: 5 additions & 0 deletions tools/hidefile_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tools

func hideFile(path string) {

}
5 changes: 5 additions & 0 deletions tools/hidefile_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tools

func hideFile(path string) {

}
10 changes: 10 additions & 0 deletions tools/hidefile_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tools

import "syscall"

func hideFile(path string) {
cpath, cpathErr := syscall.UTF16PtrFromString(path)
if cpathErr != nil {
}
syscall.SetFileAttributes(cpath, syscall.FILE_ATTRIBUTE_HIDDEN)
}
24 changes: 24 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tools

import (
"os"
"os/user"
)

func dir() string {
usr, _ := user.Current()
return usr.HomeDir + "/.arduino-create"
}

// CreateDir creates the directory where the tools will be stored
func CreateDir() {
directory := dir()
os.Mkdir(directory, 0777)
hideFile(directory)
}

// Download will parse the index at the indexURL for the tool to download
func Download(name, indexURL string) {
if _, err := os.Stat(dir() + "/" + name); err != nil {
}
}