From f7ee57d1ddca1c8462483def03fb51b44b4f8213 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 20 Aug 2013 15:25:43 +0800 Subject: [PATCH] Update customized domain support --- cmd/get.go | 1 + doc/bitbucket.go | 18 +++++++++------ doc/github.go | 18 +++++++++------ doc/google.go | 18 +++++++++------ doc/oschina.go | 18 +++++++++------ doc/utils.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 28 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index ef4cd7da0..d9ac9d66e 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -212,6 +212,7 @@ func downloadPackages(nodes []*doc.Node) { // Invalid import path. doc.ColorLog("[WARN] Skipped invalid package path( %s => %s:%s )\n", n.ImportPath, n.Type, n.Value) + failConut++ } } } diff --git a/doc/bitbucket.go b/doc/bitbucket.go index 078ebf017..752613c93 100644 --- a/doc/bitbucket.go +++ b/doc/bitbucket.go @@ -99,15 +99,19 @@ func getBitbucketDoc(client *http.Client, match map[string]string, installRepoPa return nil, err } - suf := "." + nod.Value - if len(suf) == 1 { - suf = "" + var installPath string + if nod.ImportPath == nod.DownloadURL { + suf := "." + nod.Value + if len(suf) == 1 { + suf = "" + } + projectPath := expand("bitbucket.org/{owner}/{repo}", match) + installPath = installRepoPath + "/" + projectPath + suf + nod.ImportPath = projectPath + } else { + installPath = installRepoPath + "/" + nod.ImportPath } - projectPath := expand("bitbucket.org/{owner}/{repo}", match) - installPath := installRepoPath + "/" + projectPath + suf - nod.ImportPath = projectPath - // Remove old files. os.RemoveAll(installPath + "/") os.MkdirAll(installPath+"/", os.ModePerm) diff --git a/doc/github.go b/doc/github.go index 42f59e55a..fe968335f 100644 --- a/doc/github.go +++ b/doc/github.go @@ -75,15 +75,19 @@ func getGithubDoc(client *http.Client, match map[string]string, installRepoPath shaName = strings.Replace(shaName, "-v", "-", 1) } - suf := "." + nod.Value - if len(suf) == 1 { - suf = "" + var installPath string + if nod.ImportPath == nod.DownloadURL { + suf := "." + nod.Value + if len(suf) == 1 { + suf = "" + } + projectPath := expand("github.com/{owner}/{repo}", match) + installPath = installRepoPath + "/" + projectPath + suf + nod.ImportPath = projectPath + } else { + installPath = installRepoPath + "/" + nod.ImportPath } - projectPath := expand("github.com/{owner}/{repo}", match) - installPath := installRepoPath + "/" + projectPath + suf - nod.ImportPath = projectPath - // Remove old files. os.RemoveAll(installPath + "/") os.MkdirAll(installPath+"/", os.ModePerm) diff --git a/doc/google.go b/doc/google.go index 713c5fd9a..97877aa41 100644 --- a/doc/google.go +++ b/doc/google.go @@ -74,15 +74,19 @@ func getGoogleDoc(client *http.Client, match map[string]string, installRepoPath return nil, err } - suf := "." + nod.Value - if len(suf) == 1 { - suf = "" + var installPath string + if nod.ImportPath == nod.DownloadURL { + suf := "." + nod.Value + if len(suf) == 1 { + suf = "" + } + projectPath := expand("code.google.com/p/{repo}{dot}{subrepo}{dir}", match) + installPath = installRepoPath + "/" + projectPath + suf + nod.ImportPath = projectPath + } else { + installPath = installRepoPath + "/" + nod.ImportPath } - projectPath := expand("code.google.com/p/{repo}{dot}{subrepo}{dir}", match) - installPath := installRepoPath + "/" + projectPath + suf - nod.ImportPath = projectPath - // Remove old files. os.RemoveAll(installPath + "/") os.MkdirAll(installPath+"/", os.ModePerm) diff --git a/doc/oschina.go b/doc/oschina.go index 1a874958c..47c075ef3 100644 --- a/doc/oschina.go +++ b/doc/oschina.go @@ -54,15 +54,19 @@ func getOSCDoc(client *http.Client, match map[string]string, installRepoPath str return nil, errors.New("Fail to donwload OSChina repo -> " + err.Error()) } - suf := "." + nod.Value - if len(suf) == 1 { - suf = "" + var installPath string + if nod.ImportPath == nod.DownloadURL { + suf := "." + nod.Value + if len(suf) == 1 { + suf = "" + } + projectPath := expand("git.oschina.net/{owner}/{repo}", match) + installPath = installRepoPath + "/" + projectPath + suf + nod.ImportPath = projectPath + } else { + installPath = installRepoPath + "/" + nod.ImportPath } - projectPath := expand("git.oschina.net/{owner}/{repo}", match) - installPath := installRepoPath + "/" + projectPath + suf - nod.ImportPath = projectPath - // Remove old files. os.RemoveAll(installPath + "/") os.MkdirAll(installPath+"/", os.ModePerm) diff --git a/doc/utils.go b/doc/utils.go index b08fa4f99..271625bba 100644 --- a/doc/utils.go +++ b/doc/utils.go @@ -21,6 +21,7 @@ import ( "regexp" "runtime" "strings" + "syscall" ) // IsExist returns if a file or directory exists @@ -29,6 +30,7 @@ func IsExist(path string) bool { return err == nil || os.IsExist(err) } +// Non-Windows. const ( Gray = uint8(iota + 90) Red @@ -40,6 +42,26 @@ const ( EndColor = "\033[0m" ) +// Windows. +const ( + WDefault = uintptr(iota) + WBlue + WGreen + WCyan + WRed + WPurple + WYellow + WGray + WSilver + WLightBlue + WLime + WLightCyan + WLightRed + WLightPurple + WLightYellow + WWhite +) + // ColorLog colors log and print to stdout. // Log format: [ error ]. // Level: TRAC -> blue; ERRO -> red; WARN -> Magenta; SUCC -> green; others -> default. @@ -74,6 +96,16 @@ func ColorLog(format string, a ...interface{}) { log = strings.Replace(log, " #", EndColor, -1) log = clog + log + } else { + // Level. + i := strings.Index(log, "]") + if log[0] == '[' && i > -1 { + fmt.Print("[") + printColorLevel(log[1:i]) + fmt.Print("]") + } + + log = log[i+1:] } fmt.Print(log) @@ -96,6 +128,32 @@ func getColorLevel(level string) string { } } +// printColorLevel prints color level prompt, this is only for Windows. +func printColorLevel(level string) { + cc := WDefault + level = strings.ToUpper(level) + switch level { + case "TRAC": + cc = WBlue + case "ERRO": + cc = WRed + case "WARN": + cc = WPurple + case "SUCC": + cc = WGreen + default: + cc = WWhite + } + + kernel32 := syscall.NewLazyDLL("kernel32.dll") + proc := kernel32.NewProc("SetConsoleTextAttribute") + handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(cc)) + fmt.Print(level) + handle, _, _ = proc.Call(uintptr(syscall.Stdout), uintptr(WSilver)) + CloseHandle := kernel32.NewProc("CloseHandle") + CloseHandle.Call(handle) +} + // GetGOPATH returns all paths in GOPATH variable. func GetGOPATH() []string { gopath := os.Getenv("GOPATH")