-
Notifications
You must be signed in to change notification settings - Fork 9
/
iiif-dump-config.go
190 lines (133 loc) · 3.86 KB
/
iiif-dump-config.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package main
// because this: https://github.com/thisisaaronland/go-iiif/issues/12
import (
"flag"
"fmt"
iiifcompliance "github.com/thisisaaronland/go-iiif/compliance"
iiifconfig "github.com/thisisaaronland/go-iiif/config"
iiiflevel "github.com/thisisaaronland/go-iiif/level"
"log"
"sort"
)
type FeatureDetails struct {
feature string
syntax string
required_spec bool
supported_spec bool
required_config bool
supported_config bool
}
func Sorted(h map[string]FeatureDetails) []string {
keys := make([]string, 0)
for k, _ := range h {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
func main() {
var cfg = flag.String("config", "", "Path to a valid go-iiif config file")
flag.Parse()
if *cfg == "" {
log.Fatal("Missing config file")
}
config, err := iiifconfig.NewConfigFromFile(*cfg)
if err != nil {
log.Fatal(err)
}
level, err := iiiflevel.NewLevelFromConfig(config, "example.com")
if err != nil {
log.Fatal(err)
}
//
fd := make(map[string]map[string]FeatureDetails)
//
spec, err := iiifcompliance.NewLevel2ComplianceSpec()
if err != nil {
log.Fatal(err)
}
//
var image iiifcompliance.ImageCompliance // because we're going to instantiate this twice with two different values
compliance := level.Compliance()
actual := compliance.Spec()
image = actual.Image
params := map[string]map[string]iiifcompliance.ComplianceDetails{
"region": image.Region,
"size": image.Size,
"rotation": image.Rotation,
"quality": image.Quality,
"format": image.Format,
}
//
for p, rules := range params {
fd[p] = make(map[string]FeatureDetails)
for feature, details := range rules {
fd[p][feature] = FeatureDetails{
feature: feature,
syntax: details.Syntax,
required_spec: details.Required,
supported_spec: details.Supported,
required_config: details.Required,
supported_config: details.Supported,
}
}
}
//
image = spec.Image
params = map[string]map[string]iiifcompliance.ComplianceDetails{
"region": image.Region,
"size": image.Size,
"rotation": image.Rotation,
"quality": image.Quality,
"format": image.Format,
}
for p, rules := range params {
for feature, details := range rules {
_f := fd[p][feature]
_f.required_spec = details.Required
_f.supported_spec = details.Supported
fd[p][feature] = _f
}
}
//
prms := []string{
"region", "size", "rotation", "quality", "format",
}
for _, p := range prms {
rules := fd[p]
fmt.Printf("\n##### [%s](http://iiif.io/api/image/2.1/index.html#%s)\n", p, p)
fmt.Printf("| feature | syntax | required (spec) | supported (spec) | required (config) | supported (config) |\n")
fmt.Printf("|---|---|---|---|---|---|\n")
features := Sorted(rules)
for _, feature := range features {
details := rules[feature]
rs := "green"
ss := "green"
rc := "green"
sc := "green"
if !details.required_spec {
rs = "red"
}
if !details.supported_spec {
ss = "red"
}
if !details.required_config {
rc = "red"
}
if !details.supported_config {
sc = "red"
}
rs_html := fmt.Sprintf("<span style=\"color:%s;\">%t</span>", rs, details.required_spec)
ss_html := fmt.Sprintf("<span style=\"color:%s;\">%t</span>", ss, details.supported_spec)
rc_html := fmt.Sprintf("<span style=\"color:%s;\">%t</span>", rc, details.required_config)
sc_html := fmt.Sprintf("<span style=\"color:%s;\">%t</span>", sc, details.supported_config)
if details.required_config {
rc_html = fmt.Sprintf("<span style=\"color:%s;\">**%t**</span>", rc, details.required_config)
}
if details.supported_config {
sc_html = fmt.Sprintf("<span style=\"color:%s;\">**%t**</span>", sc, details.supported_config)
}
fmt.Printf("| **%s** | %s | %s | %s | %s | %s |\n", feature, details.syntax, rs_html, ss_html, rc_html, sc_html)
}
}
}