import re

fIn = "dump_comon_20101112" 
fOut = "dynamicAttri20101112.txt"

fdIn = open(fIn, 'r')
fdOut = open(fOut, 'w')
name = IP = oneminload = fiveminload = freemem = freecpu = gbfree = txrate = rxrate = '-1'
end = 0    #end of an entry 0 - no, 1 yes

for line in fdIn:
    if re.match('Name:', line):
        name = line[6:-1]
    elif re.match('RealIP:', line):
        IP = line[8:-1]
    elif re.match('Loads:', line):
        tmp = line[7:-1].split(' ')
        oneminload = tmp[0]
        fiveminload = tmp[1]
    elif re.match('MemPress:', line):
        freemem = line[10:-1]
    elif re.match('Burp:', line):
        freecpu = line[6:-1]
    elif re.match('TxRate:', line):
        txrate = line[8:-1]
    elif re.match('RxRate:', line):
        rxrate = line[8:-1]
    elif re.match('DfDot:', line):
        tmp = line[7:-1].split(' ')
        if len(tmp) > 1:
            gbfree = tmp[1]
    elif re.match('\n', line) and end == 0:
        end = 1
    elif re.match('\n', line) and end == 1:
        out = name + '\t' + IP + '\t' + oneminload + '\t' + fiveminload + '\t' + freecpu + '\t' + freemem + '\t' + gbfree + '\t' + txrate + '\t' + rxrate + '\n'
        fdOut.write(out)
        name = IP = oneminload = fiveminload = freemem = freecpu = gbfree = txrate = rxrate = '-1'
        end = 0

fdIn.close()
fdOut.close()
