|
|
'''
|
|
|
Created on May 2, 2013
|
|
|
|
|
|
@author: Jose Antonio Sal y Rosas Celi
|
|
|
@contact: jose.salyrosas@jro.igp.gob.pe
|
|
|
'''
|
|
|
|
|
|
class readABSFile(object):
|
|
|
|
|
|
__scriptName = "readABSFile.py"
|
|
|
|
|
|
def __init__(self, filename):
|
|
|
self.fileName = filename
|
|
|
self.content = ""
|
|
|
self.exp_name = ""
|
|
|
self.number_patterns = 0
|
|
|
self.patterns = {}
|
|
|
|
|
|
def readFile(self):
|
|
|
f = open(self.fileName, 'r')
|
|
|
self.content = f.readlines()
|
|
|
f.close()
|
|
|
|
|
|
def getMetadata(self):
|
|
|
self.readFile()
|
|
|
|
|
|
newLine = self.content[0].replace("'","")
|
|
|
pos = newLine.find("=")
|
|
|
self.exp_name = newLine[pos+1:].strip()
|
|
|
|
|
|
pos = self.content[2].find("=")
|
|
|
self.number_patterns = int(self.content[2][pos+1:].strip())
|
|
|
|
|
|
self.patterns = self.getPatterns(self.content[3:])
|
|
|
|
|
|
return self.exp_name, self.number_patterns, self.patterns
|
|
|
|
|
|
def getPatterns(self, content):
|
|
|
lsPattern = []
|
|
|
patterns = self.getValueofPattern(content)
|
|
|
for element in patterns:
|
|
|
if element != "":
|
|
|
strValue = element.replace("=","/")
|
|
|
pattern = strValue.split("/")
|
|
|
dicPattern = {"number" : pattern[0], "up" : pattern[1], "down" : pattern[2]}
|
|
|
lsPattern.append(dicPattern)
|
|
|
|
|
|
return lsPattern
|
|
|
|
|
|
def getValueofPattern(self, content):
|
|
|
strValue = "".join(element.replace("\n","+").strip() for element in content)
|
|
|
strValue = strValue.replace("\r","+")
|
|
|
strValue = strValue.replace("$","")
|
|
|
strValue = strValue.replace("]]+++[[","]]/[[")
|
|
|
strValue = strValue.replace("]]++[[","]]/[[")
|
|
|
strValue = strValue.replace("]]+[[","]]/[[")
|
|
|
strValue = strValue.replace("],++[","],[")
|
|
|
strValue = strValue.replace("],+[","],[")
|
|
|
strValue = strValue.replace("]]+++","]]|")
|
|
|
strValue = strValue.replace("]]++","]]|")
|
|
|
strValue = strValue.replace("]]+","]]|")
|
|
|
strValue = strValue.replace(" =++[[","=[[")
|
|
|
strValue = strValue.replace("=++[[","=[[")
|
|
|
strValue = strValue.replace(" =+[[","=[[")
|
|
|
strValue = strValue.replace("=+[[","=[[")
|
|
|
strValue = strValue.replace("+","").strip()
|
|
|
#print strValue
|
|
|
lsPatterns = strValue.split("|")
|
|
|
|
|
|
return lsPatterns
|