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. 17
      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
- 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 gpm working principle design.
- Add support for downloading tarballs from user sources.

17
doc/bitbucket.go

@ -8,6 +8,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"io"
"net/http"
"os"
@ -40,8 +41,9 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
// but does not need to download dependencies.
isCheckImport := len(node.Value) == 0
// Check if download with specific revision.
if isCheckImport || len(node.Value) == 1 {
switch {
case isCheckImport || len(node.Value) == 1:
// Get up-to-date version.
tags := make(map[string]string)
for _, nodeType := range []string{"branches", "tags"} {
var nodes map[string]struct {
@ -61,10 +63,17 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
if err != nil {
return nil, err
}
node.Type = "commit"
node.Value = match["commit"]
} else {
match["commit"] = node.Value
case !isCheckImport: // Bundle or snapshot.
// Check downlaod type.
switch node.Type {
case "tag", "commit", "branch":
match["commit"] = node.Value
default:
return nil, errors.New("Unknown node type: " + node.Type)
}
}
// 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.Value = match["sha"]
case !isCheckImport: // Bundle or snapshot.
// Check downlaod type.
switch node.Type {
@ -96,11 +97,6 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
return nil, err
}
r, err := zip.NewReader(bytes.NewReader(p), int64(len(p)))
if err != nil {
return nil, err
}
shaName := expand("{repo}-{sha}", match)
if node.Type == "tag" {
shaName = strings.Replace(shaName, "-v", "-", 1)
@ -115,6 +111,11 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
// Create destination directory.
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)
// Need to add root path because we cannot get from tarball.
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
// Check if need to check imports.

2
install.go

@ -194,7 +194,7 @@ func downloadPackages(nodes []*doc.Node) {
for _, bn := range bnodes {
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
fmt.Fscan(os.Stdin, &option)
if strings.ToLower(option) != "y" {

4
repo/bundles/test_bundle.json

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

Loading…
Cancel
Save