Browse Source

add flag -e for command install

pull/103/head
Unknown 12 years ago
parent
commit
cb5853dbea
  1. 1
      README.md
  2. 2
      conf/gpm.toml
  3. 7
      doc/github.go
  4. 26
      gpm.go
  5. 2
      i18n/en-US/usage_install.txt
  6. 24
      install.go

1
README.md

@ -8,6 +8,7 @@ gpm(Go Package Manager) is a Go package manage tool for search, install, update
## Todo ## Todo
- Command `install` add support for downloading code from code.google.com, launchpad.net, bitbucket.org; hopefully, support user sources for downloading tarballs. - Command `install` add support for downloading code from code.google.com, launchpad.net, bitbucket.org; hopefully, support user sources for downloading tarballs.
- Command `install` installs all packages after downloaded.
- After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well. - After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well.
- Develop user source API server template application to support user sources in bundles. - Develop user source API server template application to support user sources in bundles.
- Add bundle and snapshot parser code for downloading by bundle or snapshot id. - Add bundle and snapshot parser code for downloading by bundle or snapshot id.

2
conf/gpm.toml

@ -2,4 +2,6 @@
title = "gpm(Go Package Manager)" title = "gpm(Go Package Manager)"
version = "v0.0.3 Build 0519" version = "v0.0.3 Build 0519"
username = ""
password = ""
user_language = "en-US" user_language = "en-US"

7
doc/github.go

@ -28,7 +28,7 @@ func SetGithubCredentials(id, secret string) {
} }
// GetGithubDoc downloads tarball from github.com. // GetGithubDoc downloads tarball from github.com.
func GetGithubDoc(client *http.Client, match map[string]string, commit string) (*Package, []string, error) { func GetGithubDoc(client *http.Client, match map[string]string, commit string, isDownloadEx bool) (*Package, []string, error) {
SetGithubCredentials("1862bcb265171f37f36c", "308d71ab53ccd858416cfceaed52d5d5b7d53c5f") SetGithubCredentials("1862bcb265171f37f36c", "308d71ab53ccd858416cfceaed52d5d5b7d53c5f")
match["cred"] = githubCred match["cred"] = githubCred
@ -143,6 +143,11 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
// Check if need to check imports. // Check if need to check imports.
if isCheckImport { if isCheckImport {
for _, d := range dirs { for _, d := range dirs {
// Check if current directory is example.
if !isDownloadEx && strings.Contains(d, "example") {
continue
}
dir, err := os.Open(d) dir, err := os.Open(d)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

26
gpm.go

@ -28,8 +28,9 @@ var (
) )
type tomlConfig struct { type tomlConfig struct {
Title, Version string Title, Version string
Lang string `toml:"user_language"` Username, Password string
Lang string `toml:"user_language"`
} }
// A Command is an implementation of a go command // A Command is an implementation of a go command
@ -138,20 +139,35 @@ func loadUsage(lang, appPath string) bool {
return true return true
} }
func main() { // We don't use init() to initialize
// bacause we need to get execute path in runtime.
func initialize() bool {
// Get application execute path. // Get application execute path.
if !getAppPath() { if !getAppPath() {
return return false
} }
// Load configuration. // Load configuration.
if _, err := toml.DecodeFile(appPath+"conf/gpm.toml", &config); err != nil { if _, err := toml.DecodeFile(appPath+"conf/gpm.toml", &config); err != nil {
fmt.Println(err) fmt.Println(err)
return return false
} }
// Load usages by language. // Load usages by language.
if !loadUsage(config.Lang, appPath) { if !loadUsage(config.Lang, appPath) {
return false
}
// Create bundle and snapshot directories.
os.MkdirAll(appPath+"bundles", os.ModePerm)
os.MkdirAll(appPath+"snapshots", os.ModePerm)
return true
}
func main() {
// Initialization.
if !initialize() {
return return
} }

2
i18n/en-US/usage_install.txt

@ -13,6 +13,8 @@ The install flags are:
download without installing packages. download without installing packages.
-u -u
force to update pakcages. force to update pakcages.
-e
download dependencies for examples.
The list flags accept a space-separated list of strings. To embed spaces The list flags accept a space-separated list of strings. To embed spaces
in an element in the list, surround it with either single or double quotes. in an element in the list, surround it with either single or double quotes.

24
install.go

@ -30,7 +30,8 @@ func init() {
cmdInstall.Flags = map[string]bool{ cmdInstall.Flags = map[string]bool{
"-p": false, "-p": false,
"-d": false, "-d": false,
"-u": false, "-u": false, // Flag for 'go get'.
"-e": false,
} }
} }
@ -42,6 +43,8 @@ func printPrompt(flag string) {
fmt.Printf("You enabled pure download.\n") fmt.Printf("You enabled pure download.\n")
case "-d": case "-d":
fmt.Printf("You enabled download without installing.\n") fmt.Printf("You enabled download without installing.\n")
case "-e":
fmt.Printf("You enabled download dependencies in exmaple.\n")
} }
} }
@ -103,7 +106,7 @@ func runInstall(cmd *Command, args []string) {
// Download packages. // Download packages.
commits := make([]string, len(args)) commits := make([]string, len(args))
downloadPackages(args, commits) downloadPackages(args, commits, cmdInstall.Flags["-e"])
if !cmdInstall.Flags["d"] && cmdInstall.Flags["-p"] { if !cmdInstall.Flags["d"] && cmdInstall.Flags["-p"] {
// Install packages all together. // Install packages all together.
@ -116,7 +119,7 @@ func runInstall(cmd *Command, args []string) {
// downloadPackages downloads packages with certain commit, // downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies, // if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only. // otherwise, it only downloada package with specific commit only.
func downloadPackages(pkgs, commits []string) { func downloadPackages(pkgs, commits []string, isDownloadEx bool) {
// Check all packages, they may be bundles, snapshots or raw packages path. // Check all packages, they may be bundles, snapshots or raw packages path.
for i, p := range pkgs { for i, p := range pkgs {
// Check if it is a bundle or snapshot. // Check if it is a bundle or snapshot.
@ -128,11 +131,11 @@ func downloadPackages(pkgs, commits []string) {
case utils.IsValidRemotePath(p): case utils.IsValidRemotePath(p):
if !downloadCache[p] { if !downloadCache[p] {
// Download package. // Download package.
pkg, imports := downloadPackage(p, commits[i]) pkg, imports := downloadPackage(p, commits[i], isDownloadEx)
if len(imports) > 0 { if len(imports) > 0 {
// Need to download dependencies. // Need to download dependencies.
tags := make([]string, len(imports)) tags := make([]string, len(imports))
downloadPackages(imports, tags) downloadPackages(imports, tags, isDownloadEx)
continue continue
} }
@ -152,7 +155,7 @@ func downloadPackages(pkgs, commits []string) {
} }
// downloadPackage download package either use version control tools or not. // 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, isDownloadEx bool) (pkg *doc.Package, imports []string) {
// Check if use version control tools. // Check if use version control tools.
switch { switch {
case !cmdInstall.Flags["-p"] && case !cmdInstall.Flags["-p"] &&
@ -173,14 +176,13 @@ func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) {
downloadCache[path] = true downloadCache[path] = true
var err error var err error
pkg, imports, err = pureDownload(path, commit) pkg, imports, err = pureDownload(path, commit, isDownloadEx)
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
} }
//fmt.Println(pkg) //fmt.Println(pkg)
//fmt.Printf("Downloaded package: %s.\n", path)
return pkg, imports return pkg, imports
} }
} }
@ -202,7 +204,7 @@ func checkGoGetFlags() (args []string) {
type service struct { type service struct {
pattern *regexp.Regexp pattern *regexp.Regexp
prefix string prefix string
get func(*http.Client, map[string]string, string) (*doc.Package, []string, error) get func(*http.Client, map[string]string, string, bool) (*doc.Package, []string, error)
} }
// services is the list of source code control services handled by gopkgdoc. // services is the list of source code control services handled by gopkgdoc.
@ -214,7 +216,7 @@ var services = []*service{
} }
// pureDownload downloads package without version control. // pureDownload downloads package without version control.
func pureDownload(path, commit string) (pinfo *doc.Package, imports []string, err error) { func pureDownload(path, commit string, isDownloadEx bool) (pinfo *doc.Package, imports []string, err error) {
for _, s := range services { for _, s := range services {
if s.get == nil || !strings.HasPrefix(path, s.prefix) { if s.get == nil || !strings.HasPrefix(path, s.prefix) {
continue continue
@ -233,7 +235,7 @@ func pureDownload(path, commit string) (pinfo *doc.Package, imports []string, er
match[n] = m[i] match[n] = m[i]
} }
} }
return s.get(doc.HttpClient, match, commit) return s.get(doc.HttpClient, match, commit, isDownloadEx)
} }
return nil, nil, doc.ErrNoMatch return nil, nil, doc.ErrNoMatch
} }

Loading…
Cancel
Save