Browse Source

finish command: install, support github.com only

pull/103/head
Unknown 12 years ago
parent
commit
90cd6f655d
  1. 2
      conf/gpm.toml
  2. 10
      doc/github.go
  3. 3
      doc/walker.go
  4. 42
      install.go

2
conf/gpm.toml

@ -1,5 +1,5 @@
# This is a configuration file for gpm with toml format. # This is a configuration file for gpm with toml format.
title = "gpm(Go Package Manager)" title = "gpm(Go Package Manager)"
version = "v0.0.2 Build 0519" version = "v0.0.3 Build 0519"
user_language = "en-US" user_language = "en-US"

10
doc/github.go

@ -98,6 +98,7 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
// Create destination directory. // Create destination directory.
os.Mkdir(installPath, os.ModePerm) os.Mkdir(installPath, os.ModePerm)
//dirMap := make(map[string][]*source)
dirs := make([]string, 0, 5) dirs := make([]string, 0, 5)
for _, f := range r.File { for _, f := range r.File {
absPath := strings.Replace(f.FileInfo().Name(), shaName, installPath, 1) absPath := strings.Replace(f.FileInfo().Name(), shaName, installPath, 1)
@ -124,6 +125,8 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
} }
_, err = io.Copy(fw, rc) _, err = io.Copy(fw, rc)
rc.Close()
fw.Close()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -156,20 +159,21 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
for _, fi := range fis { for _, fi := range fis {
// Only handle files. // Only handle files.
if strings.HasSuffix(fi.Name(), ".go") { if strings.HasSuffix(fi.Name(), ".go") {
f, err := os.Open(d + "/" + fi.Name()) f, err := os.Open(d + fi.Name())
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer f.Close()
fbytes := make([]byte, fi.Size()) fbytes := make([]byte, fi.Size())
_, err = f.Read(fbytes) _, err = f.Read(fbytes)
f.Close()
//fmt.Println(d+fi.Name(), fi.Size(), n)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
files = append(files, &source{ files = append(files, &source{
name: importPath + "/" + fi.Name(), name: fi.Name(),
data: fbytes, data: fbytes,
}) })
} }

3
doc/walker.go

@ -136,9 +136,10 @@ func (w *walker) build(srcs []*source) ([]string, error) {
var imports []string var imports []string
for _, v := range bpkg.Imports { for _, v := range bpkg.Imports {
// Skip strandard library. // Skip strandard library.
if !utils.IsGoRepoPath(v) { if !utils.IsGoRepoPath(v) && v != w.ImportPath {
imports = append(imports, v) imports = append(imports, v)
} }
} }
return imports, err return imports, err
} }

42
install.go

@ -105,7 +105,7 @@ func runInstall(cmd *Command, args []string) {
commits := make([]string, len(args)) commits := make([]string, len(args))
downloadPackages(args, commits) downloadPackages(args, commits)
if !cmdInstall.Flags["d"] { if !cmdInstall.Flags["d"] && cmdInstall.Flags["-p"] {
// Install packages all together. // Install packages all together.
fmt.Printf("Installing package: %s.\n") fmt.Printf("Installing package: %s.\n")
} }
@ -125,20 +125,24 @@ func downloadPackages(pkgs, commits []string) {
// TODO: api.GetBundleInfo() // TODO: api.GetBundleInfo()
case p[0] == 'S': case p[0] == 'S':
// TODO: api.GetSnapshotInfo() // TODO: api.GetSnapshotInfo()
case utils.IsValidRemotePath(p) && !downloadCache[p]: case utils.IsValidRemotePath(p):
// Download package. if !downloadCache[p] {
pkg, imports := downloadPackage(p, commits[i]) // Download package.
if len(imports) > 0 { pkg, imports := downloadPackage(p, commits[i])
// Need to download dependencies. if len(imports) > 0 {
tags := make([]string, len(imports)) // Need to download dependencies.
downloadPackages(imports, tags) tags := make([]string, len(imports))
continue downloadPackages(imports, tags)
} continue
}
// Only save package information with specific commit.
if pkg != nil { // Only save package information with specific commit.
// Save record in local database. if pkg != nil {
fmt.Printf("Saved information: %s:%s.\n", pkg.ImportPath, pkg.Commit) // Save record in local database.
//fmt.Printf("Saved information: %s:%s.\n", pkg.ImportPath, pkg.Commit)
}
} else {
fmt.Printf("Skipped downloaded package: %s.\n", p)
} }
default: default:
// Invalid import path. // Invalid import path.
@ -173,11 +177,11 @@ func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) {
if err != nil { if err != nil {
fmt.Printf("Fail to download package(%s) with error: %s.\n", path, err) fmt.Printf("Fail to download package(%s) with error: %s.\n", path, err)
return nil, nil return nil, nil
} else {
fmt.Println(pkg)
fmt.Printf("Downloaded package: %s.\n", path)
return pkg, imports
} }
//fmt.Println(pkg)
//fmt.Printf("Downloaded package: %s.\n", path)
return pkg, imports
} }
} }

Loading…
Cancel
Save