-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathjournal.go
86 lines (76 loc) · 3.01 KB
/
journal.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
76
77
78
79
80
81
82
83
84
85
86
package logger
import (
"strings"
)
type Journal struct {
counts map[Action]int
Logger
}
type Action string
const (
DISCOVERED_FILE Action = "File"
SCANNED_IMAGE Action = "Scanned image"
SCANNED_VIDEO Action = "Scanned video"
DISCARDED Action = "Discarded"
UPLOADED Action = "Uploaded"
UPGRADED Action = "Server's asset upgraded"
ERROR Action = "Error"
LOCAL_DUPLICATE Action = "Local duplicate"
SERVER_DUPLICATE Action = "Server has photo"
STACKED Action = "Stacked"
SERVER_BETTER Action = "Server's asset is better"
ALBUM Action = "Added to an album"
LIVE_PHOTO Action = "Live photo"
FAILED_VIDEO Action = "Failed video"
UNSUPPORTED Action = "File type not supported"
METADATA Action = "Metadata files"
ASSOCIATED_META Action = "Associated with metadata"
INFO Action = "Info"
NOT_SELECTED Action = "Not selected because options"
)
func NewJournal(log Logger) *Journal {
return &Journal{
// files: map[string]Entries{},
Logger: log,
counts: map[Action]int{},
}
}
func (j *Journal) AddEntry(file string, action Action, comment ...string) {
if j == nil {
return
}
c := strings.Join(comment, ", ")
if j.Logger != nil {
switch action {
case ERROR:
j.Logger.Error("%-25s: %s: %s", action, file, c)
case UPLOADED, SCANNED_IMAGE, SCANNED_VIDEO:
j.Logger.OK("%-25s: %s: %s", action, file, c)
default:
j.Logger.Info("%-25s: %s: %s", action, file, c)
}
}
j.counts[action] = j.counts[action] + 1
}
func (j *Journal) Report() {
checkFiles := j.counts[SCANNED_IMAGE] + j.counts[SCANNED_VIDEO] + j.counts[METADATA] + j.counts[UNSUPPORTED] + j.counts[FAILED_VIDEO] + j.counts[ERROR] + j.counts[DISCARDED]
j.Logger.OK("Scan of the sources:")
j.Logger.OK("%6d files in the input", j.counts[DISCOVERED_FILE])
j.Logger.OK("--------------------------------------------------------")
j.Logger.OK("%6d photos", j.counts[SCANNED_IMAGE])
j.Logger.OK("%6d videos", j.counts[SCANNED_VIDEO])
j.Logger.OK("%6d metadata files", j.counts[METADATA])
j.Logger.OK("%6d discarded files", j.counts[DISCARDED])
j.Logger.OK("%6d files having a type not supported", j.counts[UNSUPPORTED])
j.Logger.OK("%6d discarded files because in folder failed videos", j.counts[FAILED_VIDEO])
j.Logger.OK("%6d errors", j.counts[ERROR])
j.Logger.OK("%6d total (difference %d)", checkFiles, j.counts[DISCOVERED_FILE]-checkFiles)
j.Logger.OK("--------------------------------------------------------")
j.Logger.OK("%6d files with metadata", j.counts[ASSOCIATED_META])
j.Logger.OK("%6d discarded files because of options", j.counts[NOT_SELECTED])
j.Logger.OK("%6d discarded files because duplicated in the input", j.counts[LOCAL_DUPLICATE])
j.Logger.OK("%6d files already on the server", j.counts[SERVER_DUPLICATE])
j.Logger.OK("%6d uploaded files on the server", j.counts[UPLOADED])
j.Logger.OK("%6d upgraded files on the server", j.counts[UPGRADED])
j.Logger.OK("%6d discarded files because server has a better image", j.counts[SERVER_BETTER])
}