-
Notifications
You must be signed in to change notification settings - Fork 2
/
logParser.py
96 lines (76 loc) · 2.44 KB
/
logParser.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
logPath = "./QonsistentSaberColors.log"
savePath = "./QonsistentSaberColorsParsed.log"
class SceneObject:
def __init__(self, name, depth) -> None:
self.name = name
self.children = []
self.depth = depth
def childCount(self):
return len(self.children)
def hasChild(self, child):
for ownedChild in self.children:
if child.name == ownedChild.name:
return True
return False
def getObjectByName(self, name):
for obj in self.children:
if name == obj.name:
return obj
return None
def addChildByName(self, name):
newChild = SceneObject(name, self.depth + 1)
self.children.append(newChild)
return newChild
def __str__(self) -> str:
#_str = self.name
idx = self.name.rfind("(")
_str = self.name[:idx]
for obj in self.children:
if obj.childCount() > 0:
_str += "\n"
_str += "| " * obj.depth
else:
_str += "\n" + "| " * (obj.depth-1) + "|___"
_str += str(obj)
return _str
class SceneRoot:
def __init__(self) -> None:
self.objects = []
def addObject(self, obj):
self.objects.append(obj)
def getObjectByName(self, name):
for obj in self.objects:
if name == obj.name:
return obj
return None
def __str__(self) -> str:
_str = ""
for obj in self.objects:
_str += "" + str(obj) + "\n\n"
return _str
scene = SceneRoot()
with open(logPath) as file:
line_i = 0
for row in file:
row = row.strip()
if row == "": continue
row = row.split(" -> ")
row.reverse() # Ensures that "row[0]" is ALWAYS ROOT OBJECT
# Checking if root object exists. Adding if does not.
rootObj = scene.getObjectByName(row[0])
if rootObj == None:
rootObj = SceneObject(row[0], 0)
scene.addObject(rootObj)
nextObj: SceneObject = rootObj
for i in range(1, len(row)):
childObj = nextObj.getObjectByName(row[i])
if childObj == None:
nextObj = nextObj.addChildByName(row[i])
else:
nextObj = childObj
#line_i += 1
#if line_i == 100: break
f = open(savePath, "w")
f.write(str(scene))
f.close()
#print(str(scene))