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


Golang common.DirExists函数代码示例

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


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

示例1: UninstallPlugin

// UninstallPlugin uninstall the given plugin of the given version
// If version is not specified, it uninstalls all the versions of given plugin
func UninstallPlugin(pluginName string, version string) {
	pluginsHome, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		logger.Fatalf("Failed to uninstall plugin %s. %s", pluginName, err.Error())
	}
	if !common.DirExists(filepath.Join(pluginsHome, pluginName, version)) {
		logger.Errorf("Plugin %s not found.", strings.TrimSpace(pluginName+" "+version))
		os.Exit(0)
	}
	var failed bool
	pluginsDir := filepath.Join(pluginsHome, pluginName)
	filepath.Walk(pluginsDir, func(dir string, info os.FileInfo, err error) error {
		if err == nil && info.IsDir() && dir != pluginsDir && strings.HasPrefix(filepath.Base(dir), version) {
			if err := uninstallVersionOfPlugin(dir, pluginName, filepath.Base(dir)); err != nil {
				logger.Errorf("Failed to uninstall plugin %s %s. %s", pluginName, version, err.Error())
				failed = true
			}
		}
		return nil
	})
	if failed {
		os.Exit(1)
	}
	if version == "" {
		if err := os.RemoveAll(pluginsDir); err != nil {
			logger.Fatalf("Failed to remove directory %s. %s", pluginsDir, err.Error())
		}
	}
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:31,代码来源:install.go

示例2: Download

// Download fires a HTTP GET request to download a resource to target directory
func Download(url, targetDir, fileName string, silent bool) (string, error) {
	if !common.DirExists(targetDir) {
		return "", fmt.Errorf("Error downloading file: %s\nTarget dir %s doesn't exists.", url, targetDir)
	}

	if fileName == "" {
		fileName = filepath.Base(url)
	}
	targetFile := filepath.Join(targetDir, fileName)

	resp, err := http.Get(url)
	if err != nil {
		return "", err
	}
	if resp.StatusCode >= 400 {
		return "", fmt.Errorf("Error downloading file: %s.\n%s", url, resp.Status)
	}
	defer resp.Body.Close()

	out, err := os.Create(targetFile)
	if err != nil {
		return "", err
	}
	defer out.Close()
	if silent {
		_, err = io.Copy(out, resp.Body)
	} else {
		progressReader := &progressReader{Reader: resp.Body, totalBytes: resp.ContentLength}
		_, err = io.Copy(out, progressReader)
		fmt.Println()
	}
	return targetFile, err
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:34,代码来源:httpUtils.go

示例3: loadEnvironment

// Loads all the properties files available in the specified env directory
func loadEnvironment(env string) error {
	envDir := filepath.Join(config.ProjectRoot, common.EnvDirectoryName)

	dirToRead := path.Join(envDir, env)
	if !common.DirExists(dirToRead) {
		return errors.New(fmt.Sprintf("%s is an invalid environment", env))
	}

	isProperties := func(fileName string) bool {
		return filepath.Ext(fileName) == ".properties"
	}

	err := filepath.Walk(dirToRead, func(path string, info os.FileInfo, err error) error {
		if isProperties(path) {
			p, e := properties.Load(path)
			if e != nil {
				return errors.New(fmt.Sprintf("Failed to parse: %s. %s", path, e.Error()))
			}

			for k, v := range p {
				err := common.SetEnvVariable(k, v)
				if err != nil {
					return errors.New(fmt.Sprintf("%s: %s", path, err.Error()))
				}
			}
		}
		return nil
	})

	return err
}
开发者ID:Jayasagar,项目名称:gauge,代码行数:32,代码来源:env.go

示例4: getEclipseClasspath

func getEclipseClasspath() string {
	eclipseOutDir := path.Join("bin")
	if !common.DirExists(eclipseOutDir) {
		return ""
	}

	return eclipseOutDir
}
开发者ID:deluan,项目名称:gauge-java,代码行数:8,代码来源:gauge-java.go

示例5: createDirectory

func createDirectory(dir string) {
	if common.DirExists(dir) {
		return
	}
	if err := os.MkdirAll(dir, common.NewDirectoryPermissions); err != nil {
		fmt.Printf("Failed to create directory %s: %s\n", defaultReportsDir, err)
		os.Exit(1)
	}
}
开发者ID:jean,项目名称:html-report,代码行数:9,代码来源:htmlReport.go

示例6: GetSpecFiles

func GetSpecFiles(specSource string) []string {
	specFiles := make([]string, 0)
	if common.DirExists(specSource) {
		specFiles = append(specFiles, FindSpecFilesIn(specSource)...)
	} else if common.FileExists(specSource) && IsValidSpecExtension(specSource) {
		specFile, _ := filepath.Abs(specSource)
		specFiles = append(specFiles, specFile)
	}
	return specFiles
}
开发者ID:ranjeet-floyd,项目名称:gauge,代码行数:10,代码来源:finder.go

示例7: GetSpecFiles

// GetSpecFiles returns the list of spec files present at the given path.
// If the path itself represents a spec file, it returns the same.
func GetSpecFiles(path string) []string {
	var specFiles []string
	if common.DirExists(path) {
		specFiles = append(specFiles, FindSpecFilesIn(path)...)
	} else if common.FileExists(path) && IsValidSpecExtension(path) {
		f, _ := filepath.Abs(path)
		specFiles = append(specFiles, f)
	}
	return specFiles
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:12,代码来源:fileUtils.go

示例8: createDirectory

func createDirectory(filePath string) {
	showMessage("create", filePath)
	if !common.DirExists(filePath) {
		err := os.MkdirAll(filePath, 0755)
		if err != nil {
			fmt.Printf("Failed to make directory. %s\n", err.Error())
		}
	} else {
		showMessage("skip", filePath)
	}
}
开发者ID:haroon-sheikh,项目名称:gauge-java,代码行数:11,代码来源:gauge-java.go

示例9: loadEnvDir

func loadEnvDir(envName string) error {
	envDirPath := filepath.Join(config.ProjectRoot, common.EnvDirectoryName, envName)
	if !common.DirExists(envDirPath) {
		if envName != "default" {
			return fmt.Errorf("%s environment does not exist", envName)
		}
		return nil
	}

	return filepath.Walk(envDirPath, loadEnvFile)
}
开发者ID:0-T-0,项目名称:gauge,代码行数:11,代码来源:env.go

示例10: createDirectory

func createDirectory(dirPath string) {
	showMessage("create", dirPath)
	if !common.DirExists(dirPath) {
		err := os.MkdirAll(dirPath, common.NewDirectoryPermissions)
		if err != nil {
			fmt.Printf("Failed to make directory. %s\n", err.Error())
		}
	} else {
		fmt.Println("skip ", dirPath)
	}
}
开发者ID:manuviswam,项目名称:gauge-go,代码行数:11,代码来源:main.go

示例11: copyPluginFilesToGauge

func copyPluginFilesToGauge(installDesc *installDescription, versionInstallDesc *versionInstallDescription, pluginContents string) error {
	pluginsDir, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		return err
	}
	versionedPluginDir := path.Join(pluginsDir, installDesc.Name, versionInstallDesc.Version)
	if common.DirExists(versionedPluginDir) {
		return errors.New(fmt.Sprintf("Plugin %s %s already installed at %s", installDesc.Name, versionInstallDesc.Version, versionedPluginDir))
	}
	return common.MirrorDir(pluginContents, versionedPluginDir)
}
开发者ID:krwhitney,项目名称:gauge,代码行数:11,代码来源:install.go

示例12: getPluginInstallDir

func getPluginInstallDir(pluginID, pluginDirName string) (string, error) {
	pluginsDir, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		return "", err
	}
	pluginDirPath := filepath.Join(pluginsDir, pluginID, pluginDirName)
	if common.DirExists(pluginDirPath) {
		return "", fmt.Errorf("Plugin %s %s already installed at %s", pluginID, pluginDirName, pluginDirPath)
	}
	return pluginDirPath, nil
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:11,代码来源:install.go

示例13: copyPluginFilesToGaugeInstallDir

func copyPluginFilesToGaugeInstallDir(unzippedPluginDir string, pluginId string, version string) error {
	logger.Log.Info("Installing Plugin => %s %s\n", pluginId, version)

	pluginsDir, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		return err
	}
	versionedPluginDir := path.Join(pluginsDir, pluginId, version)
	if common.DirExists(versionedPluginDir) {
		return errors.New(fmt.Sprintf("Plugin %s %s already installed at %s", pluginId, version, versionedPluginDir))
	}
	return common.MirrorDir(unzippedPluginDir, versionedPluginDir)
}
开发者ID:krwhitney,项目名称:gauge,代码行数:13,代码来源:install.go

示例14: UninstallPlugin

func UninstallPlugin(pluginName string) {
	pluginsDir, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		handleUninstallFailure(err, pluginName)
	}
	pluginInstallationDir := path.Join(pluginsDir, pluginName)
	if common.DirExists(pluginInstallationDir) {
		if err = os.RemoveAll(pluginInstallationDir); err != nil {
			handleUninstallFailure(err, pluginName)
		} else {
			logger.Log.Info("%s plugin uninstalled successfully", pluginName)
		}
	} else {
		logger.Log.Info("%s plugin is not installed", pluginName)
	}
}
开发者ID:krwhitney,项目名称:gauge,代码行数:16,代码来源:install.go

示例15: setWorkingDir

func setWorkingDir(workingDir string) {
	targetDir, err := filepath.Abs(workingDir)
	if err != nil {
		handleCriticalError(errors.New(fmt.Sprintf("Unable to set working directory : %s\n", err)))
	}
	if !common.DirExists(targetDir) {
		err = os.Mkdir(targetDir, 0777)
		if err != nil {
			handleCriticalError(errors.New(fmt.Sprintf("Unable to set working directory : %s\n", err)))
		}
	}
	err = os.Chdir(targetDir)
	_, err = os.Getwd()
	if err != nil {
		handleCriticalError(errors.New(fmt.Sprintf("Unable to set working directory : %s\n", err)))
	}
}
开发者ID:Jayasagar,项目名称:gauge,代码行数:17,代码来源:gauge.go


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