Exemplo n.º 1
0
// ProjectNamesFromArgs will return all projects or all projects with
// subprojects if the length of the args is not 0.
func ProjectNamesFromArgs(store store.Store, args []string, showarchive bool) (data.Projects, error) {
	projects, err := store.ListProjects(showarchive)
	if err != nil {
		return data.Projects{}, errgo.Notef(err, "can not get list of projects")
	}

	log.Debug("Args: ", args)

	out := data.NewProjects()
	if len(args) == 0 {
		out = projects
	} else {
		for _, arg := range args {
			name, err := data.ParseProjectName(arg)
			if err != nil {
				return data.Projects{}, errgo.Notef(err, "can not parse project name")
			}

			items := projects.List(data.Project{Name: name})
			for _, item := range items {
				out.Add(item)
			}
		}
	}

	return out, nil
}
Exemplo n.º 2
0
func main() {
	flag.StringVar(&flagDataDir, "datadir", ".lablog", "the path to the datadir to use as the source of files.")
	flag.StringVar(&flagOutDir, "outdir", "output", "the path to the output directroy in which the converted files will be saved.")

	flag.Parse()

	log.Debug("DataDir: ", flagDataDir)
	log.Debug("OutDir: ", flagOutDir)

	dbread := dbfiles.New()
	dbread.Structure = dbfiles.NewFlat()
	dbread.BaseDir = flagDataDir

	readKeys, err := dbread.Keys()
	if err != nil {
		log.Fatal(errgo.Notef(err, "can not get keys from datadir"))
	}

	store, err := store.NewFolderStore(flagOutDir)
	if err != nil {
		log.Fatal(errgo.Notef(err, "can not create new store"))
	}

	for _, key := range readKeys {
		log.Info("Converting key '", strings.Join(key, "."), "'")

		project, err := data.ParseProjectName(strings.Join(key, data.ProjectNameSepperator))
		if err != nil {
			log.Warning(errgo.Notef(err, "can not convert key to project name"))
			continue
		}

		log.Debug("Project: ", project)

		values, err := dbread.Get(key...)
		if err != nil {
			log.Warning(errgo.Notef(err, "can not get values for key '"+strings.Join(key, ".")+"'"))
			continue
		}

		log.Debug("Values: ", values)

		err = convertValues(store, project, values)
		if err != nil {
			log.Warning(errgo.Notef(err, "can no convert values for key '"+strings.Join(key, ".")+"'"))
			continue
		}

		log.Info("Converted key '", strings.Join(key, "."), "'")
	}
}
Exemplo n.º 3
0
//ArgsToEntryValues will take the given args and try to parse the parameters and
//flags to the values a normaly entry (note, todo, etc.) would need.
func ArgsToEntryValues(args []string, addTimeStamp time.Time, rawTimeStamp string) (
	data.ProjectName,
	time.Time,
	string,
	error) {

	if len(args) < 2 {
		return data.ProjectName{}, time.Time{}, "", errgo.New("need at least two arguments to run")
	}

	project, err := data.ParseProjectName(args[0])
	if err != nil {
		return data.ProjectName{}, time.Time{}, "", errgo.Notef(err, "can not parse project name")
	}

	value := strings.Join(args[1:], " ")

	timestamp, err := DefaultOrRawTimestamp(addTimeStamp, rawTimeStamp)
	if err != nil {
		return data.ProjectName{}, time.Time{}, "", errgo.Notef(err, "can not get timestamp")
	}

	return project, timestamp, value, nil
}