當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。