本文整理汇总了Golang中github.com/getgauge/common.DirExists函数的典型用法代码示例。如果您正苦于以下问题:Golang DirExists函数的具体用法?Golang DirExists怎么用?Golang DirExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DirExists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: SetWorkingDir
// SetWorkingDir sets the current working directory to specified location
func SetWorkingDir(workingDir string) {
targetDir, err := filepath.Abs(workingDir)
if err != nil {
logger.Log.Critical("Unable to set working directory : %s\n", err.Error())
}
if !common.DirExists(targetDir) {
err = os.Mkdir(targetDir, 0777)
if err != nil {
logger.Log.Critical("Unable to set working directory : %s\n", err.Error())
}
}
err = os.Chdir(targetDir)
_, err = os.Getwd()
if err != nil {
logger.Log.Critical("Unable to set working directory : %s\n", err.Error())
}
}
开发者ID:CarterTsai,项目名称:gauge,代码行数:18,代码来源:init.go
示例17: IsPluginInstalled
func IsPluginInstalled(pluginName, pluginVersion string) bool {
pluginsInstallDir, err := common.GetPluginsInstallDir(pluginName)
if err != nil {
return false
}
thisPluginDir := filepath.Join(pluginsInstallDir, pluginName)
if !common.DirExists(thisPluginDir) {
return false
}
if pluginVersion != "" {
pluginJSON := filepath.Join(thisPluginDir, pluginVersion, common.PluginJSONFile)
if common.FileExists(pluginJSON) {
return true
}
return false
}
return true
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:20,代码来源:plugin.go
示例18: UninstallPlugin
func UninstallPlugin(pluginName string, version string) {
pluginsDir, err := common.GetPrimaryPluginsInstallDir()
if err != nil {
handleUninstallFailure(err, pluginName)
}
pluginInfo := pluginName
if version != "" {
pluginInfo = fmt.Sprintf("%s(%s)", pluginName, version)
}
pluginInstallationDir := path.Join(pluginsDir, pluginName, version)
if common.DirExists(pluginInstallationDir) {
if err = os.RemoveAll(pluginInstallationDir); err != nil {
handleUninstallFailure(err, pluginInfo)
} else {
logger.Info("%s plugin uninstalled successfully", pluginInfo)
}
} else {
logger.Info("%s plugin is not installed", pluginInfo)
}
}
开发者ID:0-T-0,项目名称:gauge,代码行数:20,代码来源:install.go
示例19: getIntelliJClasspath
func getIntelliJClasspath() string {
intellijOutDir := path.Join("out", "production")
if !common.DirExists(intellijOutDir) {
return ""
}
cp := ""
walker := func(path string, info os.FileInfo, err error) error {
if path == intellijOutDir {
return nil
}
if info.IsDir() {
appendClasspath(&cp, path)
// we need only top-level directories. Don't walk nested
return filepath.SkipDir
}
return nil
}
filepath.Walk(intellijOutDir, walker)
return cp
}
开发者ID:deluan,项目名称:gauge-java,代码行数:21,代码来源:gauge-java.go
示例20: createProjectTemplate
func createProjectTemplate(language string) error {
// Create the project manifest
showMessage("create", common.ManifestFile)
if common.FileExists(common.ManifestFile) {
showMessage("skip", common.ManifestFile)
}
manifest := &manifest.Manifest{Language: language, Plugins: defaultPlugins}
if err := manifest.Save(); err != nil {
return err
}
// creating the spec directory
showMessage("create", specsDirName)
if !common.DirExists(specsDirName) {
err := os.Mkdir(specsDirName, common.NewDirectoryPermissions)
if err != nil {
showMessage("error", fmt.Sprintf("Failed to create %s. %s", specsDirName, err.Error()))
}
} else {
showMessage("skip", specsDirName)
}
// Copying the skeleton file
skelFile, err := common.GetSkeletonFilePath(skelFileName)
if err != nil {
return err
}
specFile := path.Join(specsDirName, skelFileName)
showMessage("create", specFile)
if common.FileExists(specFile) {
showMessage("skip", specFile)
} else {
err = common.CopyFile(skelFile, specFile)
if err != nil {
showMessage("error", fmt.Sprintf("Failed to create %s. %s", specFile, err.Error()))
}
}
// Creating the env directory
showMessage("create", common.EnvDirectoryName)
if !common.DirExists(common.EnvDirectoryName) {
err = os.Mkdir(common.EnvDirectoryName, common.NewDirectoryPermissions)
if err != nil {
showMessage("error", fmt.Sprintf("Failed to create %s. %s", common.EnvDirectoryName, err.Error()))
}
}
defaultEnv := path.Join(common.EnvDirectoryName, envDefaultDirName)
showMessage("create", defaultEnv)
if !common.DirExists(defaultEnv) {
err = os.Mkdir(defaultEnv, common.NewDirectoryPermissions)
if err != nil {
showMessage("error", fmt.Sprintf("Failed to create %s. %s", defaultEnv, err.Error()))
}
}
defaultJSON, err := common.GetSkeletonFilePath(path.Join(common.EnvDirectoryName, common.DefaultEnvFileName))
if err != nil {
return err
}
defaultJSONDest := path.Join(defaultEnv, common.DefaultEnvFileName)
showMessage("create", defaultJSONDest)
err = common.CopyFile(defaultJSON, defaultJSONDest)
if err != nil {
showMessage("error", fmt.Sprintf("Failed to create %s. %s", defaultJSONDest, err.Error()))
}
return runner.ExecuteInitHookForRunner(language)
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:67,代码来源:init.go
注:本文中的github.com/getgauge/common.DirExists函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论