Пример #1
0
func readSongsFromDataset(ds *dataset.Dataset) ListOfSong {
	songs := NewListOfSong()
	if commit, ok := ds.MaybeHead(); ok {
		songs = commit.Value().(ListOfSong)
	}
	return songs
}
Пример #2
0
func addMp3(ds *dataset.Dataset, filename string) {
	id3, err := id3go.Open(filename)
	if err != nil {
		log.Fatalf("Failed to read id3 data from %s: %s\n", filename, err)
	}
	defer id3.Close()

	mp3_file, err := os.Open(filename)
	if err != nil {
		log.Fatalf("Failed to open %s: %s\n", filename, err)
	}
	defer mp3_file.Close()

	new_song := SongDef{
		Title:  id3.Title(),
		Artist: id3.Artist(),
		Album:  id3.Album(),
		Year:   id3.Year(),
		Mp3:    types.NewBlob(bufio.NewReader(mp3_file)),
	}.New()
	songs := readSongsFromDataset(ds).Append(new_song)
	if _, err := ds.Commit(songs); err == nil {
		fmt.Println("Successfully committed", filename)
		printSong(new_song)
	} else {
		log.Fatalf("Failed to commit: %s, error: %s\n", filename, err)
	}
}
Пример #3
0
func parsePackageFile(packageName string, in string, pkgDS dataset.Dataset) pkg.Parsed {
	inFile, err := os.Open(in)
	d.Chk.NoError(err)
	defer inFile.Close()

	return pkg.ParseNomDL(packageName, inFile, filepath.Dir(in), pkgDS.Store())
}
Пример #4
0
func generate(packageName, in, out, outDir string, written map[string]bool, parsed pkg.Parsed, localPkgs refSet, pkgDS dataset.Dataset) dataset.Dataset {
	// Generate code for all p's deps first.
	deps := generateDepCode(packageName, outDir, written, parsed.Package, localPkgs, pkgDS.Store())
	generateAndEmit(getBareFileName(in), out, written, deps, parsed)

	// Since we're just building up a set of refs to all the packages in pkgDS, simply retrying is the logical response to commit failure.
	err := datas.ErrOptimisticLockFailed
	for ; err == datas.ErrOptimisticLockFailed; pkgDS, err = pkgDS.Commit(buildSetOfRefOfPackage(parsed, deps, pkgDS)) {
	}
	return pkgDS
}
Пример #5
0
func buildSetOfRefOfPackage(pkg pkg.Parsed, deps depsMap, ds dataset.Dataset) types.SetOfRefOfPackage {
	// Can do better once generated collections implement types.Value.
	s := types.NewSetOfRefOfPackage()
	if h, ok := ds.MaybeHead(); ok {
		s = h.Value().(types.SetOfRefOfPackage)
	}
	for _, dep := range deps {
		// Writing the deps into ds should be redundant at this point, but do it to be sure.
		// TODO: consider moving all dataset work over into nomdl/pkg BUG 409
		s = s.Insert(ds.Store().WriteValue(dep).(types.RefOfPackage))
	}
	r := ds.Store().WriteValue(pkg.Package).(types.RefOfPackage)
	return s.Insert(r)
}