/
collection.go
75 lines (68 loc) · 1.95 KB
/
collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Package courgette contains everything necessary to manage a bunch of photos using their metadata.
// Useful if you organize your picture with a different folder for each month.
package courgette
import (
"errors"
"fmt"
"os"
"path/filepath"
)
// Collection represents a collection of Pictures
type Collection struct {
Config
Contents []SubDirectory
}
// Import from card.
func (c *Collection) Import(from string) (numImported int, err error) {
incomingTarget := filepath.Join(c.Root, c.Incoming)
// if it does not exist, create
if _, err = os.Stat(incomingTarget); os.IsNotExist(err) {
fmt.Println("Creating directory " + incomingTarget)
os.MkdirAll(incomingTarget, 0700)
}
fmt.Println("Moving pictures to " + incomingTarget)
// from -> c.Incoming
// TODO walk from card, create Picture, copy
// copy then remove source
return
}
// SortNew Pictures in the incoming directory.
func (c *Collection) SortNew() (numSorted int, err error) {
// c.Incoming -> p.NewPath
return
}
// AnalyzeContents of a given subdirectory.
func (c *Collection) AnalyzeContents(subdir string) (numFiles int, err error) {
subd, err := c.GetSubDir(subdir)
if err != nil {
return 0, err
}
numFiles, err = subd.Analyze(*c)
return
}
// Refresh filenames in a given subdirectory.
func (c *Collection) Refresh(subdir string) (numRenamed int, err error) {
subd, err := c.GetSubDir(subdir)
if err != nil {
return 0, err
}
// TODO loop over Pictures, BwPictures, RawFiles
for _, pic := range subd.Jpgs {
fmt.Println(pic.Filename)
// TODO analyze, rename
}
return
}
// GetSubDir returns the SubDirectory from its name
func (c *Collection) GetSubDir(subdir string) (SubDirectory, error) {
fullPath := filepath.Join(c.Root, subdir)
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
return SubDirectory{}, err
}
for _, subd := range c.Contents {
if subd.Name == subdir {
return subd, nil
}
}
return SubDirectory{}, errors.New("Subdirectory " + subdir + " not found")
}