łň
Î)
Hc           @   sÍ   d  Z  d d k Z d   Z d   Z e d j o e e i  d j p e  GHe i d  n e i d Z y e	 e d  Z
 Wn* e j
 o d GHe  GHe i d  n Xe e
  Z e GHe
 i   n d S(	   sţ   
USAGE:

apache_log_parser_split.py some_log_file

This script takes one command line argument: the name of a log file
to parse.  It then parses the log file and generates a report which 
associates remote hosts with number of bytes transferred to them.
i˙˙˙˙Nc         C   s7   |  i    } h  | d d <| d d <| d d <S(   sâ   return a dictionary of the pertinent pieces of an apache combined log file

    Currently, the only fields we are interested in are remote host and bytes sent,
    but we are putting status in there just for good measure.
    i    t   remote_hosti   t   statusi	   t
   bytes_sent(   t   split(   t   linet
   split_line(    (    sP   /Users/ngift/Documents/writing/current/pragmatic/code/apache_log_parser_split.pyt   dictify_logline   s    c         C   sq   h  } xd |  D]\ } t  |  } y t | d  } Wn t j
 o
 q n X| i | d g   i |  q W| S(   s  return a dictionary of format remote_host=>[list of bytes sent]
    
    This function takes a file object, iterates through all the lines in the file,
    and generates a report of the number of bytes transferred to each remote host
    for each hit on the webserver.
    R   R    (   R   t   intt
   ValueErrort
   setdefaultt   append(   t   logfilet   report_dictR   t	   line_dictR   (    (    sP   /Users/ngift/Documents/writing/current/pragmatic/code/apache_log_parser_split.pyt   generate_log_report   s     !t   __main__i   t   rs&   You must specify a valid file to parse(   t   __doc__t   sysR   R   t   __name__t   lent   argvt   exitt   infile_namet   opent   infilet   IOErrort
   log_reportt   close(    (    (    sP   /Users/ngift/Documents/writing/current/pragmatic/code/apache_log_parser_split.pys   <module>
   s"   		
