示例#1
0
文件: struct.go 项目: swan-go/gopm
func (n *Node) DownloadByGoGet(ctx *cli.Context, u *url.URL) error {
	baseDir := path.Join(setting.HomeDir, ".gopm/temp/goget")
	os.MkdirAll(baseDir, os.ModePerm)
	defer func() {
		os.RemoveAll(baseDir)
	}()

	oriGopath := os.Getenv("GOPATH")
	os.Setenv("GOPATH", baseDir)
	fmt.Println(baseDir)
	defer func() {
		os.Setenv("GOPATH", oriGopath)
	}()

	log.Debug("RUN 'go get %s'", n.RootPath)
	_, stderr, err := base.ExecCmdDir(baseDir, "go", "get", n.RootPath)
	if err != nil {
		log.Error("Error occurs when 'go get" + n.RootPath + "'")
		log.Error("\t" + stderr)
		return errors.New(stderr)
	}
	tmpPath := path.Join(baseDir, "src", n.RootPath)
	if !n.IsEmptyVal() {
		base.ExecCmdDir(tmpPath, "git", "checkout", n.Value)
		if err != nil {
			log.Error("Error occurs when 'git checkout" + n.Value + "'")
			log.Error("\t" + stderr)
			return errors.New(stderr)
		}
	}
	os.MkdirAll(path.Dir(n.InstallPath), os.ModePerm)
	os.Rename(tmpPath, n.InstallPath)
	return nil
}
示例#2
0
文件: struct.go 项目: swan-go/gopm
func (n *Node) DownloadByGit(ctx *cli.Context, u *url.URL) error {
	var remoteAddr string
	switch u.Scheme {
	case "git+ssh":
		remoteAddr = fmt.Sprintf("git@%s:%s.git", u.Host, u.Path)
	case "git+http":
		remoteAddr = fmt.Sprintf("http://%s/%s", u.Host, u.Path)
	case "git+https":
		remoteAddr = fmt.Sprintf("https://%s/%s", u.Host, u.Path)
	}
	baseDir := path.Dir(n.InstallPath)
	os.MkdirAll(baseDir, os.ModePerm)
	_, stderr, err := base.ExecCmdDir(baseDir, "git", "clone", remoteAddr, n.InstallPath)
	if err != nil {
		log.Error("Error occurs when 'git clone " + remoteAddr + "'")
		log.Error("\t" + stderr)
		return errors.New(stderr)
	}
	if !n.IsEmptyVal() {
		base.ExecCmdDir(n.InstallPath, "git", "checkout", n.Value)
		if err != nil {
			log.Error("Error occurs when 'git checkout" + n.Value + "'")
			log.Error("\t" + stderr)
			return errors.New(stderr)
		}
	}
	return nil
}
示例#3
0
文件: struct.go 项目: swan-go/gopm
// If vcs has been detected, use corresponding command to update package.
func (n *Node) UpdateByVcs(vcs string) error {
	switch vcs {
	case "git":
		branch, stderr, err := base.ExecCmdDir(n.InstallGopath,
			"git", "rev-parse", "--abbrev-ref", "HEAD")
		if err != nil {
			log.Error("", "Error occurs when 'git rev-parse --abbrev-ref HEAD'")
			log.Error("", "\t"+stderr)
			return errors.New(stderr)
		}
		branch = strings.TrimSpace(branch)

		_, stderr, err = base.ExecCmdDir(n.InstallGopath,
			"git", "pull", "origin", branch)
		if err != nil {
			log.Error("", "Error occurs when 'git pull origin "+branch+"'")
			log.Error("", "\t"+stderr)
			return errors.New(stderr)
		}
	case "hg":
		_, stderr, err := base.ExecCmdDir(n.InstallGopath,
			"hg", "pull")
		if err != nil {
			log.Error("", "Error occurs when 'hg pull'")
			log.Error("", "\t"+stderr)
			return errors.New(stderr)
		}

		_, stderr, err = base.ExecCmdDir(n.InstallGopath,
			"hg", "up")
		if err != nil {
			log.Error("", "Error occurs when 'hg up'")
			log.Error("", "\t"+stderr)
			return errors.New(stderr)
		}
	case "svn":
		_, stderr, err := base.ExecCmdDir(n.InstallGopath,
			"svn", "update")
		if err != nil {
			log.Error("", "Error occurs when 'svn update'")
			log.Error("", "\t"+stderr)
			return errors.New(stderr)
		}
	}
	return nil
}
示例#4
0
文件: struct.go 项目: swan-go/gopm
func (n *Node) DownloadLocalRepository(ctx *cli.Context, localize *goconfig.Localize) error {
	var repoAddr string
	switch localize.Download {
	case "git+ssh":
		repoAddr = fmt.Sprintf("git@%s:%s.git", localize.Domain, n.RootPath[len(localize.Domain)+1:])
	case "git+https":
		repoAddr = fmt.Sprintf("https://%s", n.RootPath)
	case "git+http":
		repoAddr = fmt.Sprintf("http://%s", n.RootPath)
	}
	downBaseDir := path.Dir(path.Join(setting.HomeDir, ".gopm/repos", n.RootPath))
	os.MkdirAll(downBaseDir, os.ModePerm)
	_, stderr, err := base.ExecCmdDir(downBaseDir, "git", "clone", repoAddr)
	if err != nil {
		//log.Error("", "Error occurs when 'git clone'")
		//log.Error("", "\t"+stderr)
		log.Error("Error occurs when 'git checkout" + n.Value + "'")
		log.Error("\t" + stderr)
		return errors.New(stderr)
	}
	return nil
}