-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.py
executable file
·42 lines (40 loc) · 1.71 KB
/
validate.py
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
import os
import frontmatter
from schema import Schema, And, Use, Or, Optional, Forbidden, SchemaError
from datetime import datetime
from urllib.parse import urlparse
from reeco import Validator
import yaml
def validate_yml():
VALIDATOR = Validator()
report = {}
for root, subFolders, files in os.walk('content'):
for fi in files:
with open(root + "/" + fi) as f:
try:
annotations, content = frontmatter.parse(f.read())
if 'component-id' in annotations.keys() or 'container-id' in annotations.keys():
errors = []
try:
## Start validation
if 'component-id' in annotations.keys():
### Validate as component
errors = VALIDATOR.asComponent(annotations)
elif 'container-id' in annotations.keys():
### Validate as container
errors = VALIDATOR.asContainer(annotations)
else:
# do nothing
print("neither a component nor a container")
except Exception as e:
errors.append(e)
if errors: # TODO print nicely
report[root + "/" + fi] = errors
except Exception as e:
# Malformed YAML in Markdown
report[root + "/" + fi] = [e]
asYaml = yaml.dump(report)
with open("./_data/validation.yml", "w") as f :
f.write(asYaml)
f.close()
validate_yml()