当前位置: 首页>>代码示例>>Golang>>正文


Golang base.IsExist函数代码示例

本文整理汇总了Golang中github.com/gpmgo/gopm/modules/base.IsExist函数的典型用法代码示例。如果您正苦于以下问题:Golang IsExist函数的具体用法?Golang IsExist怎么用?Golang IsExist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了IsExist函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetVcsName

// GetVcsName checks whether dirPath has .git .hg .svn else return ""
func GetVcsName(dirPath string) string {
	switch {
	case base.IsExist(path.Join(dirPath, ".git")):
		return "git"
	case base.IsExist(path.Join(dirPath, ".hg")):
		return "hg"
	case base.IsExist(path.Join(dirPath, ".svn")):
		return "svn"
	}
	return ""
}
开发者ID:CowLeo,项目名称:gopm,代码行数:12,代码来源:utils.go

示例2: LoadConfig

// LoadConfig loads gopm global configuration.
func LoadConfig() (err error) {
	if !base.IsExist(ConfigFile) {
		os.MkdirAll(path.Dir(ConfigFile), os.ModePerm)
		if _, err = os.Create(ConfigFile); err != nil {
			return fmt.Errorf("fail to create config file: %v", err)
		}
	}

	Cfg, err = goconfig.LoadConfigFile(ConfigFile)
	if err != nil {
		return fmt.Errorf("fail to load config file: %v", err)
	}

	HttpProxy = Cfg.MustValue("settings", "HTTP_PROXY")
	return nil
}
开发者ID:Lane391,项目名称:golangdemo,代码行数:17,代码来源:setting.go

示例3: loadLocalVerInfo

func loadLocalVerInfo() (ver version) {
	verPath := path.Join(setting.HomeDir, setting.VERINFO)

	// First time run should not exist.
	if !base.IsExist(verPath) {
		return ver
	}

	f, err := os.Open(verPath)
	if err != nil {
		log.Error("Update", "Fail to open VERSION.json")
		log.Fatal("", err.Error())
	}

	if err := json.NewDecoder(f).Decode(&ver); err != nil {
		log.Error("Update", "Fail to decode VERSION.json")
		log.Fatal("", err.Error())
	}
	return ver
}
开发者ID:Lane391,项目名称:golangdemo,代码行数:20,代码来源:update.go

示例4: runBin

func runBin(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) != 1 {
		errors.SetError(fmt.Errorf("Incorrect number of arguments for command: should have 1"))
		return
	}

	// Check if given directory exists if specified.
	if ctx.IsSet("dir") && !base.IsDir(ctx.String("dir")) {
		errors.SetError(fmt.Errorf("Indicated path does not exist or not a directory"))
		return
	}

	// Parse package version.
	info := ctx.Args().First()
	pkgPath := info
	n := doc.NewNode(pkgPath, doc.BRANCH, "", true)
	if i := strings.Index(info, "@"); i > -1 {
		pkgPath = info[:i]
		var err error
		tp, val, err := validPkgInfo(info[i+1:])
		if err != nil {
			errors.SetError(err)
			return
		}
		n = doc.NewNode(pkgPath, tp, val, !ctx.Bool("download"))
	}

	// Check package name.
	if !strings.Contains(pkgPath, "/") {
		tmpPath, err := setting.GetPkgFullPath(pkgPath)
		if err != nil {
			errors.SetError(err)
			return
		}
		if tmpPath != pkgPath {
			n = doc.NewNode(tmpPath, n.Type, n.Value, n.IsGetDeps)
		}
	}

	if err := downloadPackages(".", ctx, []*doc.Node{n}); err != nil {
		errors.SetError(err)
		return
	}

	// Check if previous steps were successful.
	if !n.IsExist() {
		errors.SetError(fmt.Errorf("Download steps weren't successful"))
		return
	}

	tmpVendor := path.Join("vendor", path.Base(n.RootPath))
	os.RemoveAll(tmpVendor)
	os.RemoveAll(setting.VENDOR)
	// TODO: should use .gopm/temp path.
	if err := autoLink(n.InstallPath, tmpVendor); err != nil {
		errors.SetError(fmt.Errorf("Fail to link slef: %v", err))
		return
	}
	os.Chdir(tmpVendor)
	oldWorkDir := setting.WorkDir
	setting.WorkDir = path.Join(setting.WorkDir, tmpVendor)
	if !setting.Debug {
		defer func() {
			os.Chdir(oldWorkDir)
			os.RemoveAll("vendor")
			os.RemoveAll(setting.VENDOR)
		}()
	}

	// if err := buildBinary(ctx); err != nil {
	// 	errors.SetError(err)
	// 	return
	// }

	if err := linkVendors(ctx, n.ImportPath); err != nil {
		errors.SetError(err)
		return
	}

	log.Info("Installing...")

	cmdArgs := []string{"go", "install"}
	if ctx.Bool("verbose") {
		cmdArgs = append(cmdArgs, "-v")
	}
	cmdArgs = append(cmdArgs, n.ImportPath)
	if err := execCmd(setting.DefaultVendor, setting.WorkDir, cmdArgs...); err != nil {
		errors.SetError(fmt.Errorf("fail to run program: %v", err))
		return
	}

	gf, _, err := parseGopmfile(setting.GOPMFILE)
	if err != nil {
		errors.SetError(err)
		return
//.........这里部分代码省略.........
开发者ID:juqkai,项目名称:gopm,代码行数:101,代码来源:bin.go

示例5: IsExistGopath

// IsExistGopath returns true if package exists in GOPATH.
func (n *Node) IsExistGopath() bool {
	return base.IsExist(n.InstallGopath)
}
开发者ID:juqkai,项目名称:gopm,代码行数:4,代码来源:struct.go

示例6: IsExist

// IsExist returns true if package exists in local repository.
func (n *Node) IsExist() bool {
	return base.IsExist(n.InstallPath)
}
开发者ID:juqkai,项目名称:gopm,代码行数:4,代码来源:struct.go

示例7: runUpdate

func runUpdate(ctx *cli.Context) {
	if setting.LibraryMode {
		errors.SetError(fmt.Errorf("Library mode does not support update command"))
		return
	}
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	isAnythingUpdated := false
	localVerInfo := loadLocalVerInfo()

	// Get remote version info.
	var remoteVerInfo version
	if err := base.HttpGetJSON(doc.HttpClient, "http://gopm.io/VERSION.json", &remoteVerInfo); err != nil {
		log.Fatal("Fail to fetch VERSION.json: %v", err)
	}

	// Package name list.
	if remoteVerInfo.PackageNameList > localVerInfo.PackageNameList {
		log.Info("Updating pkgname.list...%v > %v",
			localVerInfo.PackageNameList, remoteVerInfo.PackageNameList)
		data, err := base.HttpGetBytes(doc.HttpClient, "https://raw.githubusercontent.com/gpmgo/docs/master/pkgname.list", nil)
		if err != nil {
			log.Warn("Fail to update pkgname.list: %v", err)
		} else {
			if err = ioutil.WriteFile(setting.PkgNameListFile, data, os.ModePerm); err != nil {
				log.Fatal("Fail to save pkgname.list: %v", err)
			}
			log.Info("Update pkgname.list to %v succeed!", remoteVerInfo.PackageNameList)
			isAnythingUpdated = true
		}
	}

	// Gopm.
	if remoteVerInfo.Gopm > setting.VERSION {
		log.Info("Updating gopm...%v > %v", setting.VERSION, remoteVerInfo.Gopm)

		tmpDir := base.GetTempDir()
		tmpBinPath := path.Join(tmpDir, "gopm")
		if runtime.GOOS == "windows" {
			tmpBinPath += ".exe"
		}

		os.MkdirAll(path.Dir(tmpBinPath), os.ModePerm)
		os.Remove(tmpBinPath)

		// Fetch code.
		args := []string{"bin", "-u", "-r", "-d=" + tmpDir}
		if ctx.Bool("verbose") {
			args = append(args, "-v")
		}
		args = append(args, "github.com/gpmgo/gopm")
		stdout, stderr, err := base.ExecCmd("gopm", args...)
		if err != nil {
			log.Fatal("Fail to execute 'bin -u -r -d=/Users/jiahuachen/.gopm/temp -v github.com/gpmgo/gopm: %s", stderr)
		}
		if len(stdout) > 0 {
			fmt.Print(stdout)
		}

		// Check if previous steps were successful.
		if !base.IsExist(tmpBinPath) {
			log.Error("Fail to continue command")
			log.Fatal("Previous steps weren't successful, no binary produced")
		}

		movePath, err := execPath()
		if err != nil {
			log.Fatal("Fail to get execute path: %v", err)
		}
		log.Info("New binary will be replaced for %s", movePath)
		// Move binary to given directory.
		if runtime.GOOS != "windows" {
			err := os.Rename(tmpBinPath, movePath)
			if err != nil {
				log.Fatal("Fail to move binary: %v", err)
			}
			os.Chmod(movePath+"/"+path.Base(tmpBinPath), os.ModePerm)
		} else {
			batPath := path.Join(tmpDir, "update.bat")
			f, err := os.Create(batPath)
			if err != nil {
				log.Error("Update", "Fail to generate bat file")
				log.Fatal("", err.Error())
			}
			f.WriteString("@echo off\r\n")
			f.WriteString(fmt.Sprintf("ping -n 1 127.0.0.1>nul\r\ncopy \"%v\" \"%v\" >nul\r\ndel \"%v\" >nul\r\n\r\n",
				tmpBinPath, movePath, tmpBinPath))
			f.Close()

			attr := &os.ProcAttr{
				Dir:   setting.WorkDir,
				Env:   os.Environ(),
				Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
			}

			if _, err = os.StartProcess(batPath, []string{batPath}, attr); err != nil {
				log.Error("Update", "Fail to start bat process")
//.........这里部分代码省略.........
开发者ID:Lane391,项目名称:golangdemo,代码行数:101,代码来源:update.go

示例8: runGen

func runGen(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	gfPath := path.Join(setting.WorkDir, setting.GOPMFILE)
	if !setting.HasGOPATHSetting && !base.IsFile(gfPath) {
		log.Warn("Dependency list may contain package itself without GOPATH setting and gopmfile.")
	}
	gf, target, err := parseGopmfile(gfPath)
	if err != nil {
		errors.SetError(err)
		return
	}

	list, err := getDepList(ctx, target, setting.WorkDir, setting.DefaultVendor)
	if err != nil {
		errors.SetError(err)
		return
	}
	for _, name := range list {
		// Check if user has specified the version.
		if val := gf.MustValue("deps", name); len(val) == 0 {
			gf.SetValue("deps", name, "")
		}
	}

	// Check resources.
	if _, err = gf.GetValue("res", "include"); err != nil {
		resList := make([]string, 0, len(setting.CommonRes))
		for _, res := range setting.CommonRes {
			if base.IsExist(res) {
				resList = append(resList, res)
			}
		}
		gf.SetValue("res", "include", strings.Join(resList, "|"))
	}

	if err = setting.SaveGopmfile(gf, gfPath); err != nil {
		errors.SetError(err)
		return
	}

	if ctx.Bool("local") {
		localGopath := gf.MustValue("project", "local_gopath")
		if len(localGopath) == 0 {
			localGopath = "./vendor"
			gf.SetValue("project", "local_gopath", localGopath)
			if err = setting.SaveGopmfile(gf, gfPath); err != nil {
				errors.SetError(err)
				return
			}
		}

		for _, name := range []string{"src", "pkg", "bin"} {
			os.MkdirAll(path.Join(localGopath, name), os.ModePerm)
		}
	}

	log.Info("Generate gopmfile successfully!")
}
开发者ID:juqkai,项目名称:gopm,代码行数:62,代码来源:gen.go

示例9: linkVendors

func linkVendors(ctx *cli.Context, optTarget string) error {
	gfPath := path.Join(setting.WorkDir, setting.GOPMFILE)
	gf, target, err := parseGopmfile(gfPath)
	if err != nil {
		return fmt.Errorf("fail to parse gopmfile: %v", err)
	}
	if len(optTarget) > 0 {
		target = optTarget
	}
	rootPath := doc.GetRootPath(target)

	// TODO: local support.

	// Make link of self.
	log.Debug("Linking %s...", rootPath)
	from := setting.WorkDir
	to := path.Join(setting.DefaultVendorSrc, rootPath)
	if setting.Debug {
		log.Debug("Linking from %s to %s", from, to)
	}
	if err := autoLink(from, to); err != nil {
		return fmt.Errorf("fail to link self: %v", err)
	}

	// Check and loads dependency packages.
	log.Debug("Loading dependencies...")
	imports, err := doc.ListImports(target, rootPath, setting.DefaultVendor, setting.WorkDir, ctx.String("tags"), ctx.Bool("test"))
	if err != nil {
		return fmt.Errorf("fail to list imports: %v", err)
	}

	stack := make([]*doc.Pkg, len(imports))
	for i, name := range imports {
		name := doc.GetRootPath(name)
		tp, val, err := validPkgInfo(gf.MustValue("deps", name))
		if err != nil {
			return fmt.Errorf("fail to validate package(%s): %v", name, err)
		}

		stack[i] = doc.NewPkg(name, tp, val)
	}

	// FIXME: at least link once, need a set
	lastIdx := len(stack) - 1
	for lastIdx >= 0 {
		pkg := stack[lastIdx]
		linkPath := path.Join(setting.DefaultVendorSrc, pkg.RootPath)
		if setting.Debug {
			log.Debug("Import path: %s", pkg.ImportPath)
			log.Debug("Linking path: %s", linkPath)
		}
		if base.IsExist(linkPath) {
			stack = stack[:lastIdx]
			lastIdx = len(stack) - 1
			continue
		}

		if pkg.IsEmptyVal() && setting.HasGOPATHSetting &&
			base.IsExist(path.Join(setting.InstallGopath, pkg.RootPath)) {
			stack = stack[:lastIdx]
			lastIdx = len(stack) - 1
			continue
		}

		venderPath := path.Join(setting.InstallRepoPath, pkg.RootPath+pkg.ValSuffix())
		if !base.IsExist(venderPath) {
			return fmt.Errorf("package not installed: %s", pkg.RootPath+pkg.VerSuffix())
		}

		log.Debug("Linking %s...", pkg.RootPath+pkg.ValSuffix())
		if err := autoLink(venderPath, linkPath); err != nil {
			return fmt.Errorf("fail to link dependency(%s): %v", pkg.RootPath, err)
		}
		stack = stack[:lastIdx]

		gf, target, err := parseGopmfile(path.Join(linkPath, setting.GOPMFILE))
		if err != nil {
			return fmt.Errorf("fail to parse gopmfile(%s): %v", linkPath, err)
		}
		// parseGopmfile only returns right target when parse work directory.
		target = pkg.RootPath
		rootPath := target
		imports, err := doc.ListImports(target, rootPath, setting.DefaultVendor, linkPath, ctx.String("tags"), ctx.Bool("test"))
		if err != nil {
			errors.SetError(err)
		}
		for _, name := range imports {
			if name == "C" {
				continue
			}

			name := doc.GetRootPath(name)
			tp, val, err := validPkgInfo(gf.MustValue("deps", name))
			if err != nil {
				return fmt.Errorf("fail to validate package(%s): %v", name, err)
			}

			stack = append(stack, doc.NewPkg(name, tp, val))
		}
		lastIdx = len(stack) - 1
//.........这里部分代码省略.........
开发者ID:Goyoo,项目名称:codis-docker,代码行数:101,代码来源:run.go


注:本文中的github.com/gpmgo/gopm/modules/base.IsExist函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。