tartiflette/appci/analyze.py

68 lines
1.5 KiB
Python
Raw Normal View History

2017-09-01 20:20:42 +02:00
#!/usr/bin/python
2017-09-06 19:56:45 +02:00
import os
2017-08-26 15:01:31 +02:00
import json
import glob
def main():
apps = []
for f in glob.glob("data/*"):
app = f.replace("data/","")
appdata = open(f).read().strip()
if appdata == "":
continue
data = {}
data["name"] = app
data["statuses"] = []
if len(appdata.split("\n")) != 2 or len(appdata) != 28:
print "Ignoring %s - bad/unavailable data" % app
continue
2017-08-26 15:01:31 +02:00
applevel = appdata.split("\n")[1][0]
appdata = appdata.split("\n")[0]
2017-08-29 00:24:31 +02:00
data["level"] = int(applevel)
2017-08-26 15:01:31 +02:00
2017-08-29 00:24:31 +02:00
statusescore = 0
2017-08-26 15:01:31 +02:00
for c in appdata:
if c == "0":
s = "danger"
2017-08-29 00:24:31 +02:00
statusescore -= 1
2017-08-26 15:01:31 +02:00
elif c == "1":
s = "success"
2017-08-29 00:24:31 +02:00
statusescore += 1
2017-08-26 15:01:31 +02:00
else:
s = "unknown"
data["statuses"].append(s)
2017-08-29 00:24:31 +02:00
data["statusescore"] = statusescore
2017-08-26 15:01:31 +02:00
2017-08-26 15:01:31 +02:00
apps.append(data)
apps.sort(key=lambda a: (a["level"], a["statusescore"], a["name"]), reverse=True)
2017-08-26 15:01:31 +02:00
2017-09-06 19:56:45 +02:00
for link in glob.glob("../www/integration/*.svg"):
os.unlink(link);
os.symlink("%s/badges/unknown.svg" % os.getcwd(),
"../www/integration/unknown.svg")
2017-09-06 19:56:45 +02:00
for app in apps:
os.symlink("%s/badges/level%s.svg" % (os.getcwd(), app["level"]),
2017-09-06 19:56:45 +02:00
"../www/integration/%s.svg" % app["name"])
with open("apps.json", "w") as f:
json.dump(apps, f)
2017-08-26 15:01:31 +02:00
main()