Browse Source

add support for downloading packages from bitbucket.org through tag and branch

pull/103/head
Unknown 12 years ago
parent
commit
4738d25eb2
  1. 2
      README.md
  2. 15
      doc/bitbucket.go
  3. 15
      doc/github.go
  4. 2
      install.go
  5. 4
      repo/bundles/test_bundle.json

2
README.md

@ -29,7 +29,7 @@ This application still in experiment, any change could happen, but it doesn't af
## Todo ## Todo
- Add support for downloading by tag and branch for packages in bitbucket.org, git.oschina.net, gitcafe.com. - Add support for downloading by tag and branch for packages in git.oschina.net, gitcafe.com.
- Add template projects for testing commands. - Add template projects for testing commands.
- Add gpm working principle design. - Add gpm working principle design.
- Add support for downloading tarballs from user sources. - Add support for downloading tarballs from user sources.

15
doc/bitbucket.go

@ -8,6 +8,7 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"errors"
"io" "io"
"net/http" "net/http"
"os" "os"
@ -40,8 +41,9 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
// but does not need to download dependencies. // but does not need to download dependencies.
isCheckImport := len(node.Value) == 0 isCheckImport := len(node.Value) == 0
// Check if download with specific revision. switch {
if isCheckImport || len(node.Value) == 1 { case isCheckImport || len(node.Value) == 1:
// Get up-to-date version.
tags := make(map[string]string) tags := make(map[string]string)
for _, nodeType := range []string{"branches", "tags"} { for _, nodeType := range []string{"branches", "tags"} {
var nodes map[string]struct { var nodes map[string]struct {
@ -61,10 +63,17 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
if err != nil { if err != nil {
return nil, err return nil, err
} }
node.Type = "commit" node.Type = "commit"
node.Value = match["commit"] node.Value = match["commit"]
} else { case !isCheckImport: // Bundle or snapshot.
// Check downlaod type.
switch node.Type {
case "tag", "commit", "branch":
match["commit"] = node.Value match["commit"] = node.Value
default:
return nil, errors.New("Unknown node type: " + node.Type)
}
} }
// We use .tar.gz here. // We use .tar.gz here.

15
doc/github.go

@ -76,6 +76,7 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
} }
node.Type = "commit" node.Type = "commit"
node.Value = match["sha"]
case !isCheckImport: // Bundle or snapshot. case !isCheckImport: // Bundle or snapshot.
// Check downlaod type. // Check downlaod type.
switch node.Type { switch node.Type {
@ -96,11 +97,6 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
return nil, err return nil, err
} }
r, err := zip.NewReader(bytes.NewReader(p), int64(len(p)))
if err != nil {
return nil, err
}
shaName := expand("{repo}-{sha}", match) shaName := expand("{repo}-{sha}", match)
if node.Type == "tag" { if node.Type == "tag" {
shaName = strings.Replace(shaName, "-v", "-", 1) shaName = strings.Replace(shaName, "-v", "-", 1)
@ -115,6 +111,11 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
// Create destination directory. // Create destination directory.
os.MkdirAll(installPath+"/", os.ModePerm) os.MkdirAll(installPath+"/", os.ModePerm)
r, err := zip.NewReader(bytes.NewReader(p), int64(len(p)))
if err != nil {
return nil, err
}
dirs := make([]string, 0, 5) dirs := make([]string, 0, 5)
// Need to add root path because we cannot get from tarball. // Need to add root path because we cannot get from tarball.
dirs = append(dirs, installPath+"/") dirs = append(dirs, installPath+"/")
@ -154,10 +155,6 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
} }
} }
if node.Type == "commit" {
node.Value = match["sha"]
}
var imports []string var imports []string
// Check if need to check imports. // Check if need to check imports.

2
install.go

@ -194,7 +194,7 @@ func downloadPackages(nodes []*doc.Node) {
for _, bn := range bnodes { for _, bn := range bnodes {
fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value) fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value)
} }
fmt.Printf(fmt.Sprintf("%s", promptMsg["ContinueDownload"])) fmt.Printf(fmt.Sprintf("%s\n", promptMsg["ContinueDownload"]))
var option string var option string
fmt.Fscan(os.Stdin, &option) fmt.Fscan(os.Stdin, &option)
if strings.ToLower(option) != "y" { if strings.ToLower(option) != "y" {

4
repo/bundles/test_bundle.json

@ -44,8 +44,8 @@
}, },
{ {
"import_path": "bitbucket.org/zombiezen/gopdf/pdf", "import_path": "bitbucket.org/zombiezen/gopdf/pdf",
"type": "commit", "type": "branch",
"value": "", "value": "default",
"deps": null "deps": null
}, },
{ {

Loading…
Cancel
Save