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. 18
      install.go

2
conf/gpm.toml

@ -1,5 +1,5 @@
# This is a configuration file for gpm with toml format.
title = "gpm(Go Package Manager)"
version = "v0.0.2 Build 0519"
version = "v0.0.3 Build 0519"
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.
os.Mkdir(installPath, os.ModePerm)
//dirMap := make(map[string][]*source)
dirs := make([]string, 0, 5)
for _, f := range r.File {
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)
rc.Close()
fw.Close()
if err != nil {
return nil, nil, err
}
@ -156,20 +159,21 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
for _, fi := range fis {
// Only handle files.
if strings.HasSuffix(fi.Name(), ".go") {
f, err := os.Open(d + "/" + fi.Name())
f, err := os.Open(d + fi.Name())
if err != nil {
return nil, nil, err
}
defer f.Close()
fbytes := make([]byte, fi.Size())
_, err = f.Read(fbytes)
f.Close()
//fmt.Println(d+fi.Name(), fi.Size(), n)
if err != nil {
return nil, nil, err
}
files = append(files, &source{
name: importPath + "/" + fi.Name(),
name: fi.Name(),
data: fbytes,
})
}

3
doc/walker.go

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

18
install.go

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