本文整理汇总了Golang中github.com/Unknwon/com.IsDir函数的典型用法代码示例。如果您正苦于以下问题:Golang IsDir函数的具体用法?Golang IsDir怎么用?Golang IsDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsDir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: New
// New builder with option
func New(opt *BuildOption) *Builder {
if !com.IsDir(opt.SrcDir) {
return &Builder{Error: ErrSrcDirMissing}
}
if !com.IsDir(opt.TplDir) {
return &Builder{Error: ErrTplDirMissing}
}
builder := &Builder{
parsers: []parser.Parser{
parser.NewCommonParser(),
parser.NewMdParser(),
},
Version: builderVersion{
Num: opt.Version,
Date: opt.VerDate,
},
opt: opt,
}
builder.render = render.New(builder.opt.TplDir)
builder.tasks = []*BuildTask{
{"Data", builder.ReadData, nil},
{"Compile", builder.Compile, nil},
{"Feed", builder.WriteFeed, nil},
{"Copy", builder.CopyAssets, nil},
}
log15.Debug("Build.Source." + opt.SrcDir)
log15.Debug("Build.Template." + opt.TplDir)
log15.Debug("Build.Theme." + opt.Theme)
return builder
}
示例2: TestGetAndRun
func TestGetAndRun(t *testing.T) {
os.Chdir("testproject")
defer func() {
os.RemoveAll("src/github.com")
os.Remove("bin")
os.Remove("pkg")
os.Remove(".gopmfile")
os.Chdir("..")
}()
_, err := exec.Command("gopm", "gen", "-l").Output()
if err != nil {
t.Log(err)
}
if !com.IsDir("bin") || !com.IsDir("pkg") {
t.Fatal("Gen bin and pkg directories failed.")
}
_, err = exec.Command("gopm", "get", "-l").Output()
if !com.IsDir("src/github.com") {
t.Fatal("Get packages failed")
}
out, err := exec.Command("gopm", "run", "-l").Output()
if err != nil || string(out) != "TEST\n" {
t.Fatal("Run failed \t", err.Error())
}
}
示例3: ReadTheme
// ReadTheme read *Theme to *Context
func ReadTheme(ctx *Context) {
if ctx.Source == nil {
ctx.Err = fmt.Errorf("theme depends on loaded source data")
return
}
dir, _ := toDir(ctx.ThemeName)
if !com.IsDir(dir) {
ctx.Err = fmt.Errorf("theme directory '%s' is missing", dir)
return
}
log15.Info("Theme|%s", dir)
ctx.Theme = theme.New(dir)
ctx.Theme.Func("url", func(str ...string) string {
if len(str) > 0 {
if ur, _ := url.Parse(str[0]); ur != nil {
if ur.Host != "" {
return str[0]
}
}
}
return path.Join(append([]string{ctx.Source.Meta.Path}, str...)...)
})
ctx.Theme.Func("fullUrl", func(str ...string) string {
return ctx.Source.Meta.Root + path.Join(str...)
})
if err := ctx.Theme.Validate(); err != nil {
log15.Warn("Theme|%s|%s", dir, err.Error())
}
}
示例4: buildSite
// build site function
func buildSite(opt *builder.BuildOption) func(ctx *cli.Context) {
return func(ctx *cli.Context) {
// ctrl+C capture
signalChan := make(chan os.Signal)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
opt.Theme = ctx.String("theme")
b := builder.New(opt)
if b.Error != nil {
log15.Crit("Builder.Fail", "error", b.Error.Error())
}
targetDir := ctx.String("dest")
log15.Info("Dest." + targetDir)
if com.IsDir(targetDir) {
log15.Warn("Dest." + targetDir + ".Existed")
}
// auto watching
b.Build(targetDir)
if err := b.Context().Error; err != nil {
log15.Crit("Build.Fail", "error", err.Error())
}
if !ctx.Bool("nowatch") {
b.Watch(targetDir)
<-signalChan
}
log15.Info("Build.Close")
}
}
示例5: runRun
func runRun(ctx *cli.Context) {
setup(ctx)
// Get GOPATH.
installGopath = com.GetGOPATHs()[0]
if com.IsDir(installGopath) {
isHasGopath = true
log.Log("Indicated GOPATH: %s", installGopath)
installGopath += "/src"
}
genNewGoPath(ctx, false)
log.Trace("Running...")
cmdArgs := []string{"go", "run"}
cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("run", "Fail to run program:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "run", "Command executed successfully!")
}
示例6: Download
func Download(ctx *middleware.Context) {
ext := "." + ctx.Params(":ext")
var archivePath string
switch ext {
case ".zip":
archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/zip")
case ".tar.gz":
archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/targz")
default:
ctx.Error(404)
return
}
if !com.IsDir(archivePath) {
if err := os.MkdirAll(archivePath, os.ModePerm); err != nil {
ctx.Handle(500, "Download -> os.MkdirAll(archivePath)", err)
return
}
}
archivePath = path.Join(archivePath, ctx.Repo.CommitId+ext)
if !com.IsFile(archivePath) {
if err := ctx.Repo.Commit.CreateArchive(archivePath, git.ZIP); err != nil {
ctx.Handle(500, "Download -> CreateArchive "+archivePath, err)
return
}
}
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(ctx.Repo.CommitId)+ext)
}
示例7: NewTheme
// new theme manager
func NewTheme(dir, name string) *Theme {
// try to create dir
if !com.IsDir(dir) {
os.MkdirAll(dir, os.ModePerm)
}
return &Theme{dir, name}
}
示例8: ZipDownload
func ZipDownload(ctx *middleware.Context, params martini.Params) {
commitId := ctx.Repo.CommitId
archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives")
if !com.IsDir(archivesPath) {
if err := os.Mkdir(archivesPath, 0755); err != nil {
ctx.Handle(404, "ZipDownload -> os.Mkdir(archivesPath)", err)
return
}
}
zipPath := filepath.Join(archivesPath, commitId+".zip")
if com.IsFile(zipPath) {
ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip")
return
}
err := ctx.Repo.Commit.CreateArchive(zipPath)
if err != nil {
ctx.Handle(404, "ZipDownload -> CreateArchive "+zipPath, err)
return
}
ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip")
}
示例9: TestBuilderBuild
func TestBuilderBuild(t *testing.T) {
Convey("Build Process", t, func() {
b.Build(target)
So(b.Error, ShouldBeNil)
So(b.Context(), ShouldNotBeNil)
So(b.Context().Error, ShouldBeNil)
// check dirs and files
Convey("Check Built And Files", func() {
var flag = true
t := path.Join(target, b.Context().Meta.Base)
for _, dir := range shoudlExistDirs {
if flag = flag && com.IsDir(path.Join(t, dir)); !flag {
break
}
}
So(flag, ShouldBeTrue)
for _, f := range shouldExistFiles {
if flag = flag && com.IsFile(path.Join(t, f)); !flag {
break
}
}
So(flag, ShouldBeTrue)
})
})
}
示例10: ReadLang
// ReadLang read languages in srcDir
func ReadLang(srcDir string) map[string]*helper.I18n {
if !com.IsDir(srcDir) {
return nil
}
langs := make(map[string]*helper.I18n)
filepath.Walk(srcDir, func(p string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if fi.IsDir() {
return nil
}
p = filepath.ToSlash(p)
ext := filepath.Ext(p)
if ext == ".toml" || ext == ".ini" {
log15.Debug("Read|%s", p)
b, err := ioutil.ReadFile(p)
if err != nil {
log15.Warn("Read|Lang|%s|%v", p, err)
return nil
}
lang := strings.TrimSuffix(filepath.Base(p), ext)
i18n, err := helper.NewI18n(lang, b, ext)
if err != nil {
log15.Warn("Read|Lang|%s|%v", p, err)
return nil
}
langs[lang] = i18n
}
return nil
})
return langs
}
示例11: LoadRepoConfig
func LoadRepoConfig() {
// Load .gitignore and license files.
types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2)
for i, t := range types {
files := getAssetList(path.Join("conf", t))
customPath := path.Join(setting.CustomPath, "conf", t)
if com.IsDir(customPath) {
customFiles, err := com.StatDir(customPath)
if err != nil {
log.Fatal("Fail to get custom %s files: %v", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
files = append(files, f)
}
}
}
typeFiles[i] = files
}
LanguageIgns = typeFiles[0]
Licenses = typeFiles[1]
sort.Strings(LanguageIgns)
sort.Strings(Licenses)
}
示例12: LoadRepoConfig
func LoadRepoConfig() {
workDir, err := base.ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
// Load .gitignore and license files.
types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2)
for i, t := range types {
cfgPath := filepath.Join(workDir, "conf", t)
files, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get default %s files: %v\n", t, err)
}
cfgPath = filepath.Join(workDir, "custom/conf/gitignore")
if com.IsDir(cfgPath) {
customFiles, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get custom %s files: %v\n", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
files = append(files, f)
}
}
}
typeFiles[i] = files
}
LanguageIgns = typeFiles[0]
Licenses = typeFiles[1]
}
示例13: MigratePost
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_migrate")
ctxUser := checkContextUser(ctx, form.Uid)
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
ctx.HTML(200, MIGRATE)
return
}
// Remote address can be HTTP/HTTPS/Git URL or local path.
// Note: remember to change api/v1/repo.go: MigrateRepo
// FIXME: merge these two functions with better error handling
remoteAddr := form.CloneAddr
if strings.HasPrefix(form.CloneAddr, "http://") ||
strings.HasPrefix(form.CloneAddr, "https://") ||
strings.HasPrefix(form.CloneAddr, "git://") {
u, err := url.Parse(form.CloneAddr)
if err != nil {
ctx.Data["Err_CloneAddr"] = true
ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form)
return
}
if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 {
u.User = url.UserPassword(form.AuthUsername, form.AuthPassword)
}
remoteAddr = u.String()
} else if !com.IsDir(remoteAddr) {
ctx.Data["Err_CloneAddr"] = true
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form)
return
}
repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
if err == nil {
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName)
return
}
if repo != nil {
if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
if strings.Contains(err.Error(), "Authentication failed") ||
strings.Contains(err.Error(), " not found") ||
strings.Contains(err.Error(), "could not read Username") {
ctx.Data["Err_Auth"] = true
ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
return
}
handleCreateError(ctx, err, "MigratePost", MIGRATE, &form)
}
示例14: LoadRepoConfig
func LoadRepoConfig() {
// Load .gitignore and license files and readme templates.
types := []string{"gitignore", "license", "readme"}
typeFiles := make([][]string, 3)
for i, t := range types {
files, err := bindata.AssetDir("conf/" + t)
if err != nil {
log.Fatal(4, "Fail to get %s files: %v", t, err)
}
customPath := path.Join(setting.CustomPath, "conf", t)
if com.IsDir(customPath) {
customFiles, err := com.StatDir(customPath)
if err != nil {
log.Fatal(4, "Fail to get custom %s files: %v", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
files = append(files, f)
}
}
}
typeFiles[i] = files
}
Gitignores = typeFiles[0]
Licenses = typeFiles[1]
Readmes = typeFiles[2]
sort.Strings(Gitignores)
sort.Strings(Licenses)
sort.Strings(Readmes)
}
示例15: isRepositoryExist
func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
has, err := e.Get(&Repository{
OwnerID: u.Id,
LowerName: strings.ToLower(repoName),
})
return has && com.IsDir(RepoPath(u.Name, repoName)), err
}