Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Sep 17, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.py
More file actions
Latest commit
104 lines (96 loc) · 2.89 KB
/
Copy pathschema.py
File metadata and controls
104 lines (96 loc) · 2.89 KB
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
importARgorithmToolkit
importyaml
importsys
importjson
fromosimportlistdir
fromos.pathimportjoin
defget_files():
mypath='designs'
onlyfiles= [join(mypath,x) forxinlistdir("designs") ifx[-9:]=='design.yml']
returnonlyfiles
defget_schema(x):
withopen(x, 'r') asstream:
try:
schema=yaml.safe_load(stream)
returnschema
exceptyaml.YAMLErrorasexc:
print(exc)
defis_present(loc):
keywords=loc.split('.')[1:]
model=ARgorithmToolkit
try:
forwordinkeywords:
model=getattr(model,word)
except:
returnFalse
returnTrue
defcheck_schema(x):
required_tags= ['date', 'category', 'author', 'states', 'functions']
schema=get_schema(x)
forrinrequired_tags:
ifrnotinschema.keys():
return"error"
status= {
"class" : {},
"functions" : {}
}
classflag='class'inschema
ifclassflag:
forcinschema['class']:
loc=list(c.keys())[0]
status['class'][loc] ="present"ifis_present(loc) else"error"
forfinschema['functions']:
func_name=list(f.keys())[0]
function=f[func_name]['function']
iffunction=='None' :
status['functions'][func_name] ="missing"
else:
loc=function['name']
status['functions'][func_name] ="present"ifis_present(loc) else"error"
returnstatus
defflatten_dict(dd, separator='_', prefix=''):
return { prefix+separator+kifprefixelsek : v
forkk, vvindd.items()
fork, vinflatten_dict(vv, separator, kk).items()
} ifisinstance(dd, dict) else { prefix : dd }
if__name__=="__main__":
files=get_files()
status= {}
forxinfiles:
status[x] =check_schema(x)
flat_status=flatten_dict(status,separator="/")
count= {
"total" : 0,
"present" : [],
"missing" : [],
"error" : []
}
forfinflat_status:
count["total"] +=1
count[flat_status[f]].append(f)
argument=sys.argv[1] iflen(sys.argv) >1elseNone
present=len(count['present'])
missing=len(count['missing'])
color="00FFEE"
tag="All verified"
ifcount["total"] ==present:
color="00ab4b"
elifcount['total'] ==present+missing:
color="CAC235"
pc=present/count["total"] *100
tag=f"{pc:.2f}%"
else:
color="ED1B12"
tag="ERROR"
withopen("shields.json",'w') asfile:
shields= {
"Schema" : {
"label" : "Up-to-date",
"status" : tag,
"color" : color
}
}
file.write(json.dumps(shields))
[print("ERROR : " , x) forxincount['error']]
[print("MISSING : ",x) forxincount['missing']]
print(tag)