Browse Source

add search command

pull/103/head
Lunny Xiao 12 years ago
parent
commit
e341795655
  1. 2
      cmd/get.go
  2. 25
      cmd/serve.go
  3. 18
      doc/utils.go
  4. 15
      doc/utils_windows.go
  5. 11
      docs/features_CN.md
  6. 4
      gopm.go

2
cmd/get.go

@ -201,7 +201,7 @@ func downloadPackages(nodes []*doc.Node) {
doc.ColorLog("[SUCC] Downloaded package( %s => %s:%s )\n", doc.ColorLog("[SUCC] Downloaded package( %s => %s:%s )\n",
n.ImportPath, n.Type, n.Value) n.ImportPath, n.Type, n.Value)
downloadCount++ downloadCount++
//saveNode(nod) saveNode(nod)
} }
} else { } else {
doc.ColorLog("[WARN] Skipped downloaded package( %s => %s:%s )\n", doc.ColorLog("[WARN] Skipped downloaded package( %s => %s:%s )\n",

25
cmd/serve.go

@ -15,18 +15,17 @@
package cmd package cmd
import ( import (
serrors "errors"
"fmt" "fmt"
"github.com/gpmgo/gopm/doc"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors" "github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"os/user"
"strconv" "strconv"
"strings" "strings"
"github.com/gpmgo/gopm/doc"
) )
var ( var (
@ -144,6 +143,21 @@ func batchPut(batch *leveldb.Batch, key string, value string) error {
return nil return nil
} }
func saveNode(nod *doc.Node) error {
url := fmt.Sprintf("http://%v:%v/add?%v", "localhost", "8991", nod.ImportPath)
resp, err := http.Get(url)
if err != nil {
doc.ColorLog(err.Error())
return err
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
return nil
}
return serrors.New("save node failed with " + resp.Status)
}
func addNode(nod *doc.Node) error { func addNode(nod *doc.Node) error {
batch := new(leveldb.Batch) batch := new(leveldb.Batch)
strLastId, err := dbGet("lastId") strLastId, err := dbGet("lastId")
@ -316,14 +330,13 @@ func runningStatus() (int, int, int) {
} }
func startService(listen string) { func startService(listen string) {
// check the pre serve's type homeDir, err := doc.HomeDir()
curUser, err := user.Current()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
dbDir = strings.Replace(dbDir, "~", curUser.HomeDir, -1) dbDir = strings.Replace(dbDir, "~", homeDir, -1)
db, err = leveldb.OpenFile(dbDir, &opt.Options{Flag: opt.OFCreateIfMissing}) db, err = leveldb.OpenFile(dbDir, &opt.Options{Flag: opt.OFCreateIfMissing})
if err != nil { if err != nil {

18
doc/utils.go

@ -17,11 +17,12 @@ package doc
import ( import (
"fmt" "fmt"
"os" "os"
"os/user"
"path" "path"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
"syscall" //"syscall"
) )
// IsExist returns if a file or directory exists // IsExist returns if a file or directory exists
@ -144,14 +145,14 @@ func printColorLevel(level string) {
default: default:
cc = WWhite cc = WWhite
} }
fmt.Println(cc)
kernel32 := syscall.NewLazyDLL("kernel32.dll") /*kernel32 := syscall.NewLazyDLL("kernel32.dll")
proc := kernel32.NewProc("SetConsoleTextAttribute") proc := kernel32.NewProc("SetConsoleTextAttribute")
handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(cc)) handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(cc))
fmt.Print(level) fmt.Print(level)
handle, _, _ = proc.Call(uintptr(syscall.Stdout), uintptr(WSilver)) handle, _, _ = proc.Call(uintptr(syscall.Stdout), uintptr(WSilver))
CloseHandle := kernel32.NewProc("CloseHandle") CloseHandle := kernel32.NewProc("CloseHandle")
CloseHandle.Call(handle) CloseHandle.Call(handle)*/
} }
// GetGOPATH returns all paths in GOPATH variable. // GetGOPATH returns all paths in GOPATH variable.
@ -761,3 +762,12 @@ var standardPath = map[string]bool{
func IsGoRepoPath(importPath string) bool { func IsGoRepoPath(importPath string) bool {
return standardPath[importPath] return standardPath[importPath]
} }
func HomeDir() (string, error) {
curUser, err := user.Current()
if err != nil {
return "", err
}
return curUser.HomeDir, nil
}

15
doc/utils_windows.go

@ -0,0 +1,15 @@
package doc
import (
"errors"
"os"
)
func HomeDir() (string, error) {
dir := os.Getenv("userprofile")
if dir == "" {
return "", errors.New()
}
return dir, nil
}

11
docs/features_CN.md

@ -2,6 +2,7 @@ gopm
==== ====
* [总体设计目标](#10) * [总体设计目标](#10)
* [程序结构](#11)
* [Go包版本说明](#20) * [Go包版本说明](#20)
* [各命令的目标和作用](#30) * [各命令的目标和作用](#30)
* [gopm help](#31) * [gopm help](#31)
@ -30,6 +31,16 @@ gopm
5. 支持依赖管理 5. 支持依赖管理
6. 支持从github, code.google.com, gitLab, 等常见的源码托管服务下载 6. 支持从github, code.google.com, gitLab, 等常见的源码托管服务下载
<a id="11" name="11"></a>
#最终程序只有一个,但是通过配置,可以有三种模式:
1 独立服务器
2 子服务器
3 客户端(默认)
##独立服务器
独立服务器就是本身的包都是直接从源服务器中获取的。
<a id="20" name="20"></a> <a id="20" name="20"></a>
#Go包版本说明 #Go包版本说明

4
gopm.go

@ -85,9 +85,9 @@ func initialize() bool {
func main() { func main() {
// Initialization. // Initialization.
if !initialize() { /*if !initialize() {
return return
} }*/
// Check length of arguments. // Check length of arguments.
args := os.Args[1:] args := os.Args[1:]

Loading…
Cancel
Save