示例#1
0
func getContext(client *server.Client) (*projects.DirectoryResource, error) {

	cur, err := os.Getwd()

	if err != nil {
		return nil, err
	}

	p := filepath.Join(cur, ".projects")

	configDir, _ := projects.ConfigDir()

	if p == configDir {
		return nil, nil
	}

	if !utils.FileExists(p) {
		return nil, nil
	}

	pFile := filepath.Join(p, "projects.toml")

	if !utils.FileExists(pFile) {
		return nil, nil
	}

	/*file, err := os.Open(pFile)

	if err != nil {
		return nil, err
	}*/

	/*defer file.Close()

	var conf projects.DirectoryResourceConfig
	_, err = toml.DecodeReader(file, &conf)

	pp := client.Projects()
	q := messages.ProjectQuery{
		Id: conf.Project.Id,
	}

	ppp, _ := pp.Get(context.Background(), &q)

	conf.Project = ppp

	return &projects.DirectoryResource{
		Config: &conf,
	}, err*/
	return nil, nil

}
示例#2
0
func (self *Config) Discover() error {

	pluginsdir, err := projects.PluginDir()

	if err != nil {
		return err
	}

	files, e := ioutil.ReadDir(pluginsdir)

	if e != nil {
		return e
	}

	for _, file := range files {

		if !file.IsDir() {
			continue
		}

		pDir := filepath.Join(pluginsdir, file.Name())
		pConfigDir := filepath.Join(pDir, "plugin.toml")

		if !utils.FileExists(pConfigDir) {
			continue
		}

		fmt.Printf(pConfigDir)

	}
	return nil
}
示例#3
0
func (self *DirectoryResourceType) Create(ctx types.Context, b []byte) (*types.Message, error) {

	path := string(b)

	if !utils.FileExists(path) || !utils.IsDir(path) {
		return nil, errors.New("path not a file or a directory")
	}

	msg := types.Message{
		"Path": path,
	}

	return &msg, nil
}
示例#4
0
func (self *DirectoryResource) Create(b []byte) (map[string]interface{}, error) {

	path := string(b)

	if !utils.FileExists(path) || !utils.IsDir(path) {
		return nil, errors.New("path not a file or a directory")
	}

	m := database.Query{
		"Path": path,
	}

	return m, nil
}
示例#5
0
func PluginDir() (string, error) {

	configdir, err := configDir()

	if err != nil {
		return "", err
	}
	pd := filepath.Join(configdir, "plugins")

	if !utils.FileExists(pd) {
		if err = os.MkdirAll(pd, 0755); err != nil {
			return "", err
		}
	}
	return pd, nil
}
示例#6
0
func init() {

	configDir, err := projects.ConfigDir()

	if err != nil {
		panic(err)
	}

	os.Setenv("PROJECTS_PATH", configDir)

	if !utils.FileExists(configDir) {

		err := os.MkdirAll(configDir, 0755)
		if err != nil {
			panic(err)
		}
	}

}