Package prototype :: Package test :: Module replay_mail
[hide private]
[frames] | no frames]

Source Code for Module prototype.test.replay_mail

 1  #!/usr/bin/env python 
 2   
 3  import util 
 4  import request_handler 
 5   
 6  ######################################## 
 7  # 
 8  # WHOA!! not hooked up. bugs in main! 
 9  # 
10  ######################################## 
11   
12   
13  if __name__ == '__main__': 
14      mails = parse_debug_mail_log('smsDebug.log') 
15      for m in mails: 
16          response = request_handler.handle_mail(m.mail, True) 
17   
18 -def parse_debug_mail_log(mailfile):
19 """ 20 @returns: list of mail handling response objects extracted from mailfile 21 """ 22 mails = [] 23 24 # loop variables 25 filehandle = open(mailfile) 26 lines = filehandle.readlines() 27 28 # each iterating through while loop instantiates a complete Response 29 # object, which records all the logged messages and the entire 30 # incoming mail message for a particular request (denoted by the 31 # request_id) 32 i = 0; 33 print len(lines) 34 print lines[-1] 35 while i < len(lines): 36 print lines[i] 37 m = Response() 38 # first line 39 tokens = lines[i].split() 40 m.request_id = tokens[3] 41 m.sender = tokens[5] 42 m.isphone = tokens[7] 43 m.domain = tokens[9] 44 m.product_id = tokens[11] 45 m.receiver = tokens[13] 46 m.receiver_domain = tokens[15] 47 m.log_msgs = {} 48 m.mail = [] 49 # 50 i += 1 51 tokens = lines[i].split() 52 while tokens[3] == m.request_id and tokens[4] != '####initiateemail####': 53 print 'a '+lines[i] 54 if tokens[2] not in m.log_msgs: 55 m.log_msgs[tokens[2]] = {} 56 if tokens[4] not in m.log_msgs[tokens[2]]: 57 m.log_msgs[tokens[2]][tokens[4]] = 0 58 m.log_msgs[tokens[2]][tokens[4]] += 1 59 # get additional info 60 if tokens[4] == 'found_node_in_tam': 61 m.node_id = tokens[6] 62 m.node_label = tokens[8:] 63 i += 1 64 tokens = lines[i].split() 65 # read in mail 66 if tokens[4] == '####initiateemail####': 67 i += 1 68 tokens = lines[i].split() 69 while len(tokens) == 0 or (len(tokens) > 0 and tokens[0] != '####terminateemail####'): 70 m.mail.append(lines[i]) 71 i += 1 72 if i < len(lines): 73 tokens = lines[i].split() 74 else: 75 break 76 if len(tokens) > 0 and tokens[0] == '####terminateemail####': 77 print "email terminate "+''.join(tokens)+str(i) 78 else: 79 print "no terminate "+''.join(tokens)+str(i) 80 i += 1 81 # 82 mails.append(m) 83 84 filehandle.close() 85 return mails
86 87 """ dict of log messages. {'DEBUG':{'msg1':X, 'msg2':Y,}, 'INFO':{'msg1':Z,},} where X,Y,Z are num of occurences """ 88 log_msgs = None 89 90 #make a log_msgs class instead that keeps list of messages, sorts them, and then tests equality. 91