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


Golang utils.IsFileExist函数代码示例

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


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

示例1: getThemePreview

func (t *Theme) getThemePreview(themeType string) string {
	var target string
	switch themeType {
	case "gtk":
		target = path.Join("WindowThemes", t.GtkTheme)
	case "icon":
		target = path.Join("IconThemes", t.IconTheme)
	case "cursor":
		target = path.Join("CursorThemes", t.CursorTheme)
	}

	filename := path.Join(os.Getenv("HOME"), userPreviewPath,
		target+"-preview.png")
	if dutils.IsFileExist(filename) {
		return dutils.EncodeURI(filename, dutils.SCHEME_FILE)
	}

	filename = path.Join(systemPreviewPath,
		target+"-preview.png")
	if dutils.IsFileExist(filename) {
		return dutils.EncodeURI(filename, dutils.SCHEME_FILE)
	}

	return ""
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:25,代码来源:theme.go

示例2: copyBroswerConfig

// Default broswer: google-chrome
func copyBroswerConfig(home, lang string) error {
	dest := path.Join(home, ".config/google-chrome")
	if dutils.IsFileExist(dest) {
		return nil
	}

	var (
		override   = "/usr/share/deepin-default-settings/google-chrome/override-chrome-config.tar"
		configLang = fmt.Sprintf("/usr/share/deepin-default-settings/google-chrome/chrome-config-%s.tar", lang)
		config     = "/usr/share/deepin-default-settings/google-chrome/chrome-config.tar"

		broswerConfig string
	)
	switch {
	case dutils.IsFileExist(override):
		broswerConfig = override
	case dutils.IsFileExist(configLang):
		broswerConfig = configLang
	case dutils.IsFileExist(config):
		broswerConfig = config
	}
	if len(broswerConfig) == 0 {
		return fmt.Errorf("Not found broswer configure file")
	}

	_, err := archive.Extracte(broswerConfig, path.Join(home, ".config"))
	return err
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:29,代码来源:config_datas.go

示例3: renameXDGDirs

func renameXDGDirs(home, lang string) {
	var (
		desktop   = path.Join(home, "Desktop")
		templates = path.Join(home, "Templates")
	)

	switch lang {
	case "zh_CN":
		if dutils.IsFileExist(desktop) {
			os.Rename(desktop, path.Join(home, "桌面"))
		}

		if dutils.IsFileExist(templates) {
			os.Rename(templates, path.Join(home, "模板"))
			//dutils.CreateFile(path.Join(home, "模板", "文本文件"))
		}
	case "zh_TW":
		if dutils.IsFileExist(desktop) {
			os.Rename(desktop, path.Join(home, "桌面"))
		}

		if dutils.IsFileExist(templates) {
			os.Rename(templates, path.Join(home, "模板"))
			dutils.CreateFile(path.Join(home, "模板", "新增檔案"))
		}
	default:
		if dutils.IsFileExist(templates) {
			dutils.CreateFile(path.Join(templates, "New file"))
		}
	}
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:31,代码来源:config_datas.go

示例4: modifyCustomTheme

func (m *Manager) modifyCustomTheme(info *Theme) bool {
	homeDir := dutils.GetHomeDir()
	dir := path.Join(homeDir, userThemePath, "Custom")
	if !dutils.IsFileExist(dir) {
		err := os.MkdirAll(dir, dirPermMode)
		if err != nil {
			logger.Debug(err)
			return false
		}
	}

	filename := path.Join(dir, "theme.ini")
	var newFile bool
	if !dutils.IsFileExist(filename) {
		err := dutils.CopyFile(tempDThemeCustom, filename)
		if err != nil {
			logger.Debug(err)
			return false
		}
		newFile = true
	}

	kFile := glib.NewKeyFile()
	defer kFile.Free()
	_, err := kFile.LoadFromFile(filename,
		glib.KeyFileFlagsKeepComments|
			glib.KeyFileFlagsKeepTranslations)
	if err != nil {
		return false
	}

	kFile.SetString(groupKeyComponent, themeKeyGtk, info.GtkTheme)
	kFile.SetString(groupKeyComponent, themeKeyIcon, info.IconTheme)
	kFile.SetString(groupKeyComponent, themeKeyCursor, info.CursorTheme)
	kFile.SetString(groupKeyComponent, themeKeySound, info.SoundTheme)
	kFile.SetString(groupKeyComponent, themeKeyBackground, info.Background)
	kFile.SetString(groupKeyComponent, themeKeyFontName, info.FontName)
	kFile.SetString(groupKeyComponent, themeKeyFontMono, info.FontMono)
	kFile.SetInteger(groupKeyComponent, themeKeyFontSize, info.FontSize)

	_, contents, err := kFile.ToData()
	if err != nil {
		return false
	}

	m.wLocker.Lock()
	defer m.wLocker.Unlock()
	ok := dutils.WriteStringToKeyFile(filename, contents)
	if newFile && ok {
		touchFile()
	}

	return ok
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:54,代码来源:deepin_theme.go

示例5: doGenCursorThumb

func doGenCursorThumb(forceFlag bool, outDir string) {
	list := getCursorList()
	for _, l := range list {
		dest := getThumbCachePath("--cursor", l.Path, outDir)
		if len(dest) < 1 || (!forceFlag && dutils.IsFileExist(dest)) {
			continue
		}
		bg := getThumbBg()
		if !genCursorThumbnail(l, dest, bg) {
			logger.Debugf("ERROR: Generate Cursor Thumbnail\n")
		}
	}
	if dutils.IsFileExist(XCUR2PNG_OUTDIR) {
		os.RemoveAll(XCUR2PNG_OUTDIR)
	}
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:16,代码来源:main.go

示例6: getCPUInfoFromFile

func getCPUInfoFromFile(config string) (string, error) {
	if !dutils.IsFileExist(config) {
		return "", errFileNotExist
	}

	contents, err := ioutil.ReadFile(config)
	if err != nil {
		return "", err
	}

	var (
		info string
		cnt  int
	)
	lines := strings.Split(string(contents), "\n")
	for _, line := range lines {
		if strings.Contains(line, "model name") {
			vars := strings.Split(line, ":")
			if len(vars) != 2 {
				break
			}
			cnt++
			if len(info) == 0 {
				info += vars[1]
			}
		}
	}
	if cnt > 1 {
		info = fmt.Sprintf("%s x %v", info, cnt)
	}

	return strings.TrimSpace(info), nil
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:33,代码来源:system_info.go

示例7: getDscConfInfo

func getDscConfInfo() (isUpdate bool, duration int32) {
	isUpdate = true
	duration = 3

	homeDir := dutils.GetHomeDir()
	filename := path.Join(homeDir, DSC_CONFIG_PATH)
	if !dutils.IsFileExist(filename) {
		return
	}

	str, _ := dutils.ReadKeyFromKeyFile(filename,
		"update", "auto", "")
	if v, ok := str.(string); ok && v == "False" {
		isUpdate = false
	}

	interval, ok1 := dutils.ReadKeyFromKeyFile(filename,
		"update", "interval", int32(0))
	if ok1 {
		if i, ok := interval.(int32); ok {
			duration = int32(i)
		}
	}

	return

}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:27,代码来源:dsc.go

示例8: Set

func (bg *Background) Set(uri string) error {
	settings := NewGSettings("com.deepin.wrap.gnome.desktop.background")
	defer Unref(settings)

	value := settings.GetString(settingsKeyPictureURI)
	if isBackgroundSame(uri, value) {
		return nil
	}

	if isBackgroundInInfoList(uri, bg.infoList) {
		settings.SetString(settingsKeyPictureURI, uri)
		return nil
	}

	// cp uri to user wallpapers
	src := dutils.DecodeURI(uri)
	if !dutils.IsFileExist(src) {
		src = defaultBgFile
	}
	dir := getUserWallpaper()
	if len(dir) == 0 {
		return errUserPict
	}

	filename := path.Join(dir, path.Base(src))
	err := dutils.CopyFile(src, filename)
	if err != nil {
		return err
	}
	settings.SetString(settingsKeyPictureURI,
		dutils.EncodeURI(filename, dutils.SCHEME_FILE))

	return nil
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:34,代码来源:background.go

示例9: isVersionSame

func isVersionSame() bool {
	versionFile := path.Join(THUMB_CACHE_SYS_PATH, VERSION_FILE)
	if !dutils.IsFileExist(versionFile) {
		err := writeVersionFile(versionFile)
		if err != nil {
			logger.Warning("writeVersionFile failed:", err)
		}
		return false
	}

	contents, err := ioutil.ReadFile(versionFile)
	if err != nil {
		logger.Warning("Read version file failed:", err)
		return false
	}

	if string(contents) == VERSION {
		return true
	}
	if err := writeVersionFile(versionFile); err != nil {
		logger.Warning("writeVersionFile failed:", err)
	}

	return false
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:25,代码来源:check_version.go

示例10: getPngList

func getPngList(dir string) []string {
	list := []string{}

	if !dutils.IsFileExist(dir) {
		return list
	}

	fp, err := os.Open(dir)
	if err != nil {
		return list
	}
	defer fp.Close()

	names, err1 := fp.Readdirnames(0)
	if err1 != nil {
		return list
	}

	for _, n := range names {
		ok, _ := regexp.MatchString(`\.png$`, n)
		if !ok {
			continue
		}

		filename := path.Join(dir, n)
		list = append(list, filename)
	}

	return list
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:30,代码来源:icon.go

示例11: searchString

func searchString(key, md5 string) []string {
	list := []string{}
	cachePath, ok := getCachePath()
	if !ok {
		return list
	}

	filename := path.Join(cachePath, md5)
	if !dutils.IsFileExist(filename) {
		logger.Warningf("'%s' not exist", filename)
		return list
	}

	datas := []dataInfo{}
	if !readDatasFromFile(&datas, filename) {
		return list
	}

	matchers := getMatchers(key)
	var matchRes = matchResInfo{}
	for _, v := range datas {
		getMatchReuslt(&v, matchers, &matchRes)
	}

	list = sortMatchResult(&matchRes)

	return list
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:28,代码来源:search.go

示例12: searchStartWithString

func searchStartWithString(key, md5 string) []string {
	list := []string{}
	cachePath, ok := getCachePath()
	if !ok {
		return list
	}

	filename := path.Join(cachePath, md5)
	if !dutils.IsFileExist(filename) {
		logger.Warningf("'%s' not exist", filename)
		return list
	}

	datas := []dataInfo{}
	if !readDatasFromFile(&datas, filename) {
		return list
	}

	match := regexp.MustCompile(fmt.Sprintf(`(?i)^(%s)`, key))
	for _, v := range datas {
		if match.MatchString(v.Key) {
			list = append(list, v.Value)
		}
	}

	return list
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:27,代码来源:search.go

示例13: getKDMAutoLoginUser

//Default config: /usr/share/config/kdm/kdmrc
func getKDMAutoLoginUser(file string) (string, error) {
	if !dutils.IsFileExist(file) {
		return "", fmt.Errorf("Not found this file: %s", file)
	}

	v, exist := dutils.ReadKeyFromKeyFile(file,
		"X-:0-Core", "AutoLoginEnable", true)
	if !exist {
		return "", nil
	}

	enable, ok := v.(bool)
	if !ok {
		return "", fmt.Errorf("The value's type error.")
	}

	if !enable {
		return "", nil
	}

	v, exist = dutils.ReadKeyFromKeyFile(file,
		"X-:0-Core", "AutoLoginUser", "")
	if !exist {
		return "", nil
	}

	var name string
	name, ok = v.(string)
	if !ok {
		return "", fmt.Errorf("The value's type error.")
	}

	return name, nil
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:35,代码来源:manager.go

示例14: isAppInBlackList

func isAppInBlackList() bool {
	X := getXUtil()
	if X == nil {
		return false
	}

	xid, _ := getActiveWindow(X)
	pid, _ := getWindowPid(X, xid)

	filename := fmt.Sprintf("/proc/%v/cmdline", pid)
	if !dutils.IsFileExist(filename) {
		return false
	}

	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		logger.Warningf("ReadFile '%s' failed: %v", filename, err)
		return false
	}

	blackList := zoneSettings().GetStrv("black-list")
	for _, target := range blackList {
		if strings.Contains(string(contents), target) {
			return true
		}
	}

	return false
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:29,代码来源:window_state.go

示例15: CopyFile

func CopyFile(src, dst string, copyFlag CopyFlag) error {
	srcStat, err := os.Lstat(src)
	if err != nil {
		return err
	}

	if srcStat.IsDir() {
		return fmt.Errorf("error src is a directory: %s", src)
	}

	if utils.IsFileExist(dst) {
		dstStat, err := os.Lstat(dst)
		if err != nil {
			return fmt.Errorf("error os.Lstat dst %s: %s", dst, err)
		}

		if dstStat.IsDir() {
			dst = path.Join(dst, path.Base(src))
		} else {
			if (copyFlag & CopyFileOverWrite) == 0 {
				return fmt.Errorf("error dst %s is alreadly exist", dst)
			}
		}
	}

	return copyFileAux(src, dst, copyFlag)
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:27,代码来源:copyfile.go


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