Browse Source

v0.1.0 build 0521

pull/103/head
Unknown 12 years ago
parent
commit
c3093cb6a8
  1. 2
      .gitignore
  2. 1
      README.md
  3. 2
      conf/gpm.toml
  4. 9
      doc/bitbucket.go
  5. 9
      doc/github.go
  6. 9
      doc/google.go
  7. 9
      doc/launchpad.go
  8. 14
      doc/struct.go
  9. 34
      gpm.go
  10. 44
      install.go

2
.gitignore vendored

@ -20,5 +20,7 @@ _cgo_export.*
_testmain.go
*.exe
gpm
data/
repo/

1
README.md

@ -12,7 +12,6 @@ gpm(Go Package Manager) is a Go package manage tool for search, install, update
## Todo
- Save node information after downloaded, and check for next time, reduce download times.
- All errors should have specific title for exactly where were created.
- Add i18n support for all strings.
- Add gpm working principle design.

2
conf/gpm.toml

@ -1,7 +1,7 @@
# This is a configuration file for gpm with toml format.
title = "gpm(Go Package Manager)"
version = "v0.0.6 Build 0521"
version = "v0.1.0 Build 0521"
username = ""
password = ""
user_language = "en-US"

9
doc/bitbucket.go

@ -22,7 +22,7 @@ var (
)
// GetBitbucketDoc downloads tarball from bitbucket.org.
func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Package, []string, error) {
func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Node, []string, error) {
// Check version control.
if m := bitbucketEtagRe.FindStringSubmatch(commit); m != nil {
match["vcs"] = m[1]
@ -141,9 +141,8 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
}
}
pkg := &Package{
ImportPath: match["importPath"],
AbsPath: installPath,
node := &Node{
ImportPath: projectPath,
Commit: commit,
}
@ -160,7 +159,7 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
}
}
return pkg, imports, err
return node, imports, err
}
// checkDir checks if current directory has been saved.

9
doc/github.go

@ -26,7 +26,7 @@ func SetGithubCredentials(id, secret string) {
}
// GetGithubDoc downloads tarball from github.com.
func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Package, []string, error) {
func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Node, []string, error) {
SetGithubCredentials("1862bcb265171f37f36c", "308d71ab53ccd858416cfceaed52d5d5b7d53c5f")
match["cred"] = githubCred
@ -134,9 +134,8 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, c
}
}
pkg := &Package{
ImportPath: match["importPath"],
AbsPath: installPath,
node := &Node{
ImportPath: projectPath,
Commit: commit,
}
@ -153,5 +152,5 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, c
}
}
return pkg, imports, err
return node, imports, err
}

9
doc/google.go

@ -48,7 +48,7 @@ func getGoogleVCS(client *http.Client, match map[string]string) error {
}
// GetGoogleDoc downloads raw files from code.google.com.
func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Package, []string, error) {
func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Node, []string, error) {
setupGoogleMatch(match)
// Check version control.
if m := googleEtagRe.FindStringSubmatch(commit); m != nil {
@ -132,9 +132,8 @@ func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH, c
return nil, nil, err
}
pkg := &Package{
ImportPath: match["importPath"],
AbsPath: installPath,
node := &Node{
ImportPath: projectPath,
Commit: commit,
}
var imports []string
@ -164,7 +163,7 @@ func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH, c
}
}
return pkg, imports, err
return node, imports, err
}
func downloadFiles(client *http.Client, match map[string]string, rootPath, installPath, commit string, dirs []string) error {

9
doc/launchpad.go

@ -19,7 +19,7 @@ import (
var LaunchpadPattern = regexp.MustCompile(`^launchpad\.net/(?P<repo>(?P<project>[a-z0-9A-Z_.\-]+)(?P<series>/[a-z0-9A-Z_.\-]+)?|~[a-z0-9A-Z_.\-]+/(\+junk|[a-z0-9A-Z_.\-]+)/[a-z0-9A-Z_.\-]+)(?P<dir>/[a-z0-9A-Z_.\-/]+)*$`)
// GetLaunchpadDoc downloads tarball from launchpad.net.
func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Package, []string, error) {
func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH, commit string, cmdFlags map[string]bool) (*Node, []string, error) {
if match["project"] != "" && match["series"] != "" {
rc, err := httpGet(client, expand("https://code.launchpad.net/{project}{series}/.bzr/branch-format", match), nil)
@ -120,9 +120,8 @@ func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH
}
}
pkg := &Package{
ImportPath: match["importPath"],
AbsPath: installPath,
node := &Node{
ImportPath: projectPath,
Commit: commit,
}
@ -139,5 +138,5 @@ func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH
}
}
return pkg, imports, err
return node, imports, err
}

14
doc/struct.go

@ -10,17 +10,11 @@ import (
"time"
)
// Package represents a package.
type Package struct {
// Package import path.
ImportPath string
AbsPath string
// Revision tag and project tags.
// Node represents a node structure.
type Node struct {
ImportPath string `json:"import_path"`
Commit string
// Imports.
Imports []string
Date string
}
// source is source code file.

34
gpm.go

@ -7,6 +7,7 @@
package main
import (
"encoding/json"
"fmt"
"io"
"os"
@ -20,11 +21,14 @@ import (
"unicode/utf8"
"github.com/BurntSushi/toml"
"github.com/GPMGo/gpm/doc"
"github.com/GPMGo/gpm/utils"
)
var (
config tomlConfig
appPath string // Application path.
localNodes []*doc.Node
)
type tomlConfig struct {
@ -100,7 +104,7 @@ func getAppPath() bool {
}
// loadUsage loads usage according to user language.
func loadUsage(lang, appPath string) bool {
func loadUsage(lang string) bool {
// Load main usage.
f, err := os.Open(appPath + "i18n/" + lang + "/usage.tpl")
if err != nil {
@ -139,6 +143,27 @@ func loadUsage(lang, appPath string) bool {
return true
}
// loadLocalNodes loads nodes information from local file system.
func loadLocalNodes() bool {
if !utils.IsExist(appPath + "data/nodes.json") {
os.MkdirAll(appPath+"data/", os.ModePerm)
} else {
fr, err := os.Open(appPath + "data/nodes.json")
if err != nil {
fmt.Println(err)
return false
}
defer fr.Close()
err = json.NewDecoder(fr).Decode(&localNodes)
if err != nil && err != io.EOF {
fmt.Println(err)
return false
}
}
return true
}
// We don't use init() to initialize
// bacause we need to get execute path in runtime.
func initialize() bool {
@ -154,7 +179,7 @@ func initialize() bool {
}
// Load usages by language.
if !loadUsage(config.Lang, appPath) {
if !loadUsage(config.Lang) {
return false
}
@ -162,6 +187,11 @@ func initialize() bool {
os.MkdirAll(appPath+"repo/bundles/", os.ModePerm)
os.MkdirAll(appPath+"repo/snapshots/", os.ModePerm)
// Initialize local nodes.
if !loadLocalNodes() {
return false
}
return true
}

44
install.go

@ -5,8 +5,10 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"os/exec"
"regexp"
"strings"
@ -126,6 +128,16 @@ func runInstall(cmd *Command, args []string) {
cmdArgs[1] = k
executeGoCommand(cmdArgs)
}
// Save local nodes to file.
fw, err := os.Create(appPath + "data/nodes.json")
if err != nil {
fmt.Println(err)
return
}
defer fw.Close()
fbytes, _ := json.MarshalIndent(&localNodes, "", "\t")
fw.Write(fbytes)
}
fmt.Println("Well done.")
@ -146,17 +158,17 @@ func downloadPackages(pkgs, commits []string) {
case utils.IsValidRemotePath(p):
if !downloadCache[p] {
// Download package.
pkg, imports := downloadPackage(p, commits[i])
node, imports := downloadPackage(p, commits[i])
if len(imports) > 0 {
// Need to download dependencies.
tags := make([]string, len(imports))
downloadPackages(imports, tags)
continue
}
// Only save package information with specific commit.
if pkg != nil {
// Save record in local database.
if node != nil {
// Save record in local nodes.
saveNode(node)
//fmt.Printf("Saved information: %s:%s.\n", pkg.ImportPath, pkg.Commit)
}
} else {
@ -169,8 +181,22 @@ func downloadPackages(pkgs, commits []string) {
}
}
// saveNode saves node into local nodes.
func saveNode(n *doc.Node) {
// Check if this node exists.
for _, v := range localNodes {
if n.ImportPath == v.ImportPath {
v = n
return
}
}
// Add new node.
localNodes = append(localNodes, n)
}
// downloadPackage download package either use version control tools or not.
func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) {
func downloadPackage(path, commit string) (node *doc.Node, imports []string) {
// Check if use version control tools.
switch {
case !cmdInstall.Flags["-p"] &&
@ -191,13 +217,13 @@ func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) {
downloadCache[path] = true
var err error
pkg, imports, err = pureDownload(path, commit)
node, imports, err = pureDownload(path, commit)
if err != nil {
fmt.Printf("Fail to download package(%s) with error: %s.\n", path, err)
return nil, nil
}
return pkg, imports
return node, imports
}
}
@ -218,7 +244,7 @@ func checkGoGetFlags() (args []string) {
type service struct {
pattern *regexp.Regexp
prefix string
get func(*http.Client, map[string]string, string, string, map[string]bool) (*doc.Package, []string, error)
get func(*http.Client, map[string]string, string, string, map[string]bool) (*doc.Node, []string, error)
}
// services is the list of source code control services handled by gopkgdoc.
@ -230,7 +256,7 @@ var services = []*service{
}
// pureDownload downloads package without version control.
func pureDownload(path, commit string) (pinfo *doc.Package, imports []string, err error) {
func pureDownload(path, commit string) (*doc.Node, []string, error) {
for _, s := range services {
if s.get == nil || !strings.HasPrefix(path, s.prefix) {
continue

Loading…
Cancel
Save