56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
|
from mpLinkCharacteristics import MpLinkCharacteristics
|
||
|
|
||
|
|
||
|
class MpParamTopo:
|
||
|
def __init__(self, paramFile):
|
||
|
self.paramDic = {}
|
||
|
self.linkCharacteristics = []
|
||
|
print("Create the param Object")
|
||
|
self.loadParamFile(paramFile)
|
||
|
self.loadLinkCharacteristics()
|
||
|
|
||
|
def loadParamFile(self, paramFile):
|
||
|
f = open(paramFile)
|
||
|
i = 0
|
||
|
for l in f:
|
||
|
i = i + 1
|
||
|
if l.startswith("#"):
|
||
|
continue
|
||
|
|
||
|
tab = l.split(":")
|
||
|
if len(tab) == 2:
|
||
|
self.paramDic[tab[0]] = tab[1][:-1]
|
||
|
else:
|
||
|
print("Ignored Line " + str(i))
|
||
|
print(l),
|
||
|
print("In file " + paramFile)
|
||
|
f.close()
|
||
|
|
||
|
def loadLinkCharacteristics(self):
|
||
|
i = 0
|
||
|
for k in self.paramDic:
|
||
|
if k.startswith("path"):
|
||
|
tab = self.paramDic[k].split(",")
|
||
|
if len(tab) == 3:
|
||
|
i = i + 1
|
||
|
path = MpLinkCharacteristics(i,tab[0],
|
||
|
tab[1], tab[2])
|
||
|
self.linkCharacteristics.append(path)
|
||
|
else:
|
||
|
print("Ignored path :")
|
||
|
print(self.paramDic[k])
|
||
|
|
||
|
def getParam(self, key):
|
||
|
if key in self.paramDic:
|
||
|
return self.paramDic[key]
|
||
|
else:
|
||
|
raise Exception("Param not found " + key)
|
||
|
|
||
|
def __str__(self):
|
||
|
s = self.paramDic.__str__()
|
||
|
s = s + "\n"
|
||
|
for p in self.linkCharacteristics[:-1]:
|
||
|
s = s + p.__str__() + "\n"
|
||
|
s = s + self.linkCharacteristics[-1].__str__()
|
||
|
return s
|