コード例 #1
0
ファイル: deploy.go プロジェクト: h2object/h2object
func push(client *api.Client, auth api.Auth, bar *pb.ProgressBar, workdir string, dir string, exclude_suffixes []string) error {
	stat, err := os.Stat(dir)
	if err != nil {
		return err
	}

	if stat.IsDir() {
		infos, err := ioutil.ReadDir(path.Join(dir))
		if err != nil {
			return err
		}

		for _, info := range infos {
			if info.IsDir() {
				if err := push(client, auth, bar,
							   workdir, 
							   path.Join(dir, info.Name()), exclude_suffixes); err != nil {
					return err
				}
				continue
			}

			hit := false
			for _, suffix := range exclude_suffixes {
				if util.HasSuffix(info.Name(), suffix) {
					hit = true
					break
				}
			}
			if hit == true {
				continue
			}

			u := uri(workdir, path.Join(dir, info.Name()))
			if err := file_push(client, auth, bar, path.Join(dir, info.Name()), u); err != nil {
				return err
			}
		}
	} else {
		u := uri(workdir, dir)
		if err := file_push(client, auth, bar, dir, u); err != nil {
			return err
		}		
	}	
	return nil
}
コード例 #2
0
ファイル: context.go プロジェクト: h2object/h2object
func (ctx *context) folder_pages(root, folder string, suffixes []string) error {
	stat, err := os.Stat(folder)
	if err != nil {
		return err
	}
	if !stat.IsDir() {
		return errors.New(folder + " is not folder")
	}
	if infos, err := ioutil.ReadDir(folder); err == nil {
		for _, info := range infos {
			if info.IsDir() {
				if err := ctx.folder_pages(path.Join(root, info.Name()),
					path.Join(folder, info.Name()), suffixes); err != nil {
					return err
				}
				continue
			}

			for _, suffix := range suffixes {
				if !util.HasSuffix(info.Name(), suffix) {
					continue
				}

				uri := path.Join(root, info.Name())
				fn := path.Join(folder, info.Name())
				pg := page.NewPage(uri)
				if err := pg.Load(fn); err != nil {
					return err
				}

				ctx.put_page(uri, pg)
			}
		}
	}
	return nil
}