Changeset 66:ea973f3a66c2 in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
01/05/09 18:31:06 (10 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Filter out bad lines everywhere.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh_mergelogs.py

    r65 r66  
    44 
    55def apachedate2utc(line): 
    6     try: 
    7         d = re_find_date.findall(line)[0] 
    8     except IndexError, exc: 
    9         return None 
     6    d = re_find_date.findall(line)[0] 
    107    temp = d.split() 
    118    utcdate = datetime.datetime(*(time.strptime(temp[0], "%d/%b/%Y:%H:%M:%S")[0:6])) # support ancient distributions with python < 2.5 
     
    1411    utcdate -= datetime.timedelta(hours=hrsoff, minutes=minsoff) 
    1512    return utcdate 
     13 
     14def reallines(iter, key=apachedate2utc): 
     15    for item in iter: 
     16        try: 
     17            keyitem = key(item) 
     18        except Exception: 
     19            sys.stderr.write("Skipping malformed line %s" % item) 
     20            sys.stderr.flush() 
     21        else: 
     22            yield item 
    1623 
    1724def mergesort(list_of_lists, key=apachedate2utc): 
     
    4249 
    4350 
    44 openedfiles = [] 
    45 for filename in sys.argv[1:]: 
    46     openedfiles.append(open(filename)) 
     51openedfiles = [reallines(open(filename)) for filename in sys.argv[1:]] 
    4752 
    4853for line, itr in mergesort(openedfiles, key=apachedate2utc):