import numpy as np

file = 'ntwk_und1_main.edl'

with open('/u/ld/joaoprod/edmDisplays/display/lcls/'+file) as f:
    content = f.readlines()


content = [x.strip() for x in content]


relatedDisplay = False
n=0

list=[]
row = ['','', '', '', '','']

for i in range(len(content)):
    l = content[i]

    if l == "object relatedDisplayClass":

        if relatedDisplay == False:
            row = [file,'', '', '', '','']
            relatedDisplay = True




    if relatedDisplay and l.find('buttonLabel')==0:
        print l.split('"')[1].strip()
        row[2] = l.split('"')[1].strip()



    if relatedDisplay and l.find('displayFileName')==0:
        print content[i+1].split('"')[1]
        row[3] = content[i+1].split('"')[1]

    if relatedDisplay and l.find('symbols')==0:
        print content[i+1].split('"')[1]
        row[4] = content[i+1].split('"')[1]

        row[5] = row[2].replace('...','')+':STATSUMY'

        for macro in row[4].split(','):
            if (macro.find('crat=') == 0 or macro.find('acsw=') == 0) and macro.split('=')[1].find("CPU")!=0 and row[2].find('VIOC')!=0 and  row[2].find('ACSW')!=0 and  row[2].find('CRAT')!=0:
                row[5] = row[5] +" " + macro.split('=')[1]+":STATSUMY"



    if l == "endObjectProperties" and relatedDisplay:
        list.append(row)
        n += 1
        relatedDisplay = False

for l in list:
    print l

thefile = open(file+'_mine.txt', 'w')

for item in list:
    for c in item:
        thefile.write("%s\t" % c)
    thefile.write("\n")