Beispiel #1
0
func refresh(cc courgette.Collection, subdir string) (err error) {
	toParse := []courgette.SubDirectory{}
	if subdir != "" {
		// check it exists, get SubDirectory object if it does
		subd, err := cc.GetSubDir(subdir)
		if err != nil {
			return err
		}
		// add to list
		toParse = append(toParse, subd)
	} else {
		toParse = cc.Contents
	}

	numRenamed := 0
	for _, subd := range toParse {
		// Analyze
		_, err := subd.Analyze(cc)
		if err != nil {
			return err
		}
		// TODO better
		for _, p := range subd.Jpgs {
			wasRenamed, err := p.Rename(cc)
			if err != nil {
				panic(err)
			}
			if wasRenamed {
				numRenamed++
			}
		}
		for _, p := range subd.BwJpgs {
			wasRenamed, err := p.Rename(cc)
			if err != nil {
				panic(err)
			}
			if wasRenamed {
				numRenamed++
			}
		}
		for _, p := range subd.RawFiles {
			wasRenamed, err := p.Rename(cc)
			if err != nil {
				panic(err)
			}
			if wasRenamed {
				numRenamed++
			}
		}
	}
	fmt.Printf("Renamed %d pictures.", numRenamed)
	return
}
Beispiel #2
0
func findOrphans(cc courgette.Collection, subdir string) (err error) {
	toParse := []courgette.SubDirectory{}
	if subdir != "" {
		// check it exists, get SubDirectory object if it does
		subd, err := cc.GetSubDir(subdir)
		if err != nil {
			return err
		}
		// add to list
		toParse = append(toParse, subd)
	} else {
		toParse = cc.Contents
	}

	allOrphans := courgette.Pictures{}
	for _, subd := range toParse {
		// find orphans
		orphans, err := subd.FindOrphans(cc)
		if err != nil {
			return err
		}
		// append to list
		for _, o := range orphans {
			allOrphans = append(allOrphans, o)
		}
	}

	if len(allOrphans) != 0 {
		fmt.Println("Found orphans:")
		for _, o := range allOrphans {
			fmt.Println("\t - " + filepath.Base(o.Filename))
		}
		fmt.Println("Remove? Y/n")
		// TODO scan and remove if necessary
	}

	return
}