-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGentooWorldDash.py
77 lines (70 loc) · 2.68 KB
/
GentooWorldDash.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
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
from flask import Flask
from flask import render_template
import json
from configparser import ConfigParser,ExtendedInterpolation
from UtilFunctions import get_script_path
app = Flask(__name__)
@app.route('/')
def hello_world():
parsedpretend = parse_pretend()
return render_template('pretendresults.html', title="", ebuilds=parsedpretend)
@app.route('/world/json')
def json_world_data():
parsedpretend = parse_pretend()
return json.dumps(parsedpretend)
def parse_pretend():
output = []
with open(worldpretendcache) as file:
data = file.readlines()
for line in data:
parsedline = {}
parsedline["buildtype"] = "ebuild"
packageflags = []
packagecompflags = {}
parsedline["packagename"] = ""
parsedline["previousversion"] = ""
parsedline["size"] = ""
if line.startswith("["):
flagsplit = line.split(" ] ")
flags = flagsplit[0].lstrip("[")
remainingline = flagsplit[1]
if flags.startswith("ebuild"):
buildtype = "ebuild"
flags = flags.lstrip("ebuild")
elif flags.startswith("blocks"):
buildtype = "blocker"
flags = flags.lstrip("blocks")
flags = flags.strip()
for flag in flags:
packageflags.append(flag)
quotebreak = remainingline.split("\"")
quotebreak[1::2] = (string.replace(" ", "|") for string in quotebreak[1::2])
remainingline = "\"".join(quotebreak)
lineparts = remainingline.split()
sizefound = False
for part in lineparts:
if parsedline["packagename"] == "":
parsedline["packagename"] = part
elif part.startswith("["):
parsedline["previousversion"] = part
elif '=' in part:
flagpieces = part.split('=')
packagecompflags[flagpieces[0]] = flagpieces[1].replace("|", " ").strip("\"")
elif part.isnumeric():
sizefound = True
parsedline["size"] = part
elif sizefound:
parsedline["size"] += " " + part
parsedline["buildflags"] = packageflags
parsedline["useflags"] = packagecompflags
output.append(parsedline)
return output
basepath = get_script_path()
configFile = basepath + '/config/defaults.ini'
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(configFile)
worldpretendcache = ""
if 'GentooWorldDash' in config:
worldpretendcache = config['GentooWorldDash']['CacheFile']
if __name__ == '__main__':
app.run()