Ñò
ÎÑAHc           @   sy   d  Z  d d k l Z d e i d e i d Z e i Z d d k Z d d k Z d d k	 Z	 d e
 f d „  ƒ  YZ d S(	   sc   
Logger class for IPython's logging facilities.

$Id: Logger.py 2875 2007-11-26 08:37:39Z fperez $
iÿÿÿÿ(   t   Releases   %s <%s>
%s <%s>t   Jankot   FernandoNt   Loggerc           B   s•   e  Z d  Z d d d d „ Z d „  Z d „  Z e e e ƒ Z d d d e	 e	 e	 d „ Z
 d „  Z d	 „  Z d d
 „ Z d d „ Z d „  Z e Z RS(   s9   A Logfile class with different policies for file creations
   Logger.logt    t   overc         C   ss   d \ |  _  |  _ |  _ |  _ | |  _ | |  _ | |  _ | |  _ d  |  _	 t
 |  _ t
 |  _ t
 |  _ t
 |  _ d  S(   NR   (   R   R   R   R   (   t   _i00t   _it   _iit   _iiit   shellt   logfnamet   logheadt   logmodet   Nonet   logfilet   Falset   log_raw_inputt
   log_outputt	   timestampt
   log_active(   t   selfR
   R   R   R   (    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt   __init__$   s    								c         C   s+   | d j o t  d | ‚ n | |  _ d  S(   Nt   appendt   backupt   globalR   t   rotates   invalid log mode %s given(   s   appends   backups   globalR   s   rotate(   t
   ValueErrort   _logmode(   R   t   mode(    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt	   _set_mode>   s    c         C   s   |  i  S(   N(   R   (   R   (    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt	   _get_modeC   s    c         C   s  |  i  d j	 o t d |  i ƒ ‚ n t |  _ | d j	 o | |  _ n | d j	 o | |  _ n | d j	 o | |  _ n | |  _ | |  _	 | |  _
 t i i } |  i } | d j o t |  i d ƒ |  _  n| d j ok | |  i ƒ oB |  i d } | | ƒ o t i | ƒ n t i |  i | ƒ n t |  i d ƒ |  _  nŽ| d j o: t i i |  i i |  i ƒ |  _ t |  i d ƒ |  _  nG| d j o= | |  i ƒ o t i |  i ƒ n t |  i d ƒ |  _  ný | d	 j oï | |  i ƒ oÆ | |  i d
 ƒ o” t i |  i d ƒ }	 |	 i ƒ  |	 i ƒ  xg |	 D][ }
 t i i |
 ƒ \ } } t | d d !ƒ d } t i |
 | d | i d ƒ d ƒ q?Wn t i |  i |  i d
 ƒ n t |  i d ƒ |  _  n | d j o |  i  i |  i ƒ n |  i  i ƒ  d S(   so   Generate a new log-file with a default header.

        Raises RuntimeError if the log has already been starteds   Log file is already active: %sR   t   aR   t   ~t   wR   R   R   s   .001~s   .*~i   iÿÿÿÿt   .i   N(   R   R   t   RuntimeErrorR   t   TrueR   R   R   R   R   R   t   ost   patht   isfilet   opent   removet   renamet   joinR
   t   home_dirt   globt   sortt   reverset   splitextt   intt   zfillt   writet   flush(   R   R   R   R   R   R   R   R(   t   backup_lognamet   oldt   ft   roott   extt   num(    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt   logstartH   s^    	   				!

 .c         C   s¯   | t  t d d g j o t d | ‚ n h d d 6d d 6d t  6d t 6} |  i d	 j o	 d GHnH |  i | j o d G| | GHn' d G| | GH|  i |  _ |  i |  _ d	 S(
   s4   Switch logging on/off. val should be ONLY a boolean.i    i   s7   Call switch_log ONLY with a boolean argument, not with:t   OFFt   ONsÿ   
Logging hasn't been started yet (use logstart for that).

%logon/%logoff are for temporarily starting and stopping logging for a logfile
which already exists. But you must first start the logging process with
%logstart (optionally giving a logfile name).s   Logging is alreadys   Switching loggingN(   R   R%   R   R   R   R   t   log_active_out(   R   t   valt   label(    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt
   switch_logŠ   s    "	c         C   sy   |  i  d
 j o	 d GHn] |  i o d p d } d G|  i GHd G|  i GHd G|  i GHd G|  i GHd G|  i GHd	 G| GHd
 S(   s(   Print a status message about the logger.s   Logging has not been activated.t   actives   temporarily suspendeds   Filename       :s   Mode           :s   Output logging :s   Raw input log  :s   Timestamping   :s   State          :N(   R   R   R   R   R   R   R   R   (   R   t   state(    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt   logstate£   s    	c   
      C   sã  y |  i  i d } Wn d G|  i  i i ƒ  GHd SX|  i  i } | i o? | i d t | ƒ j o% | i d g | i t | ƒ ƒ n | oL | oE |  i |  _	 |  i
 |  _ |  i |  _
 | d |  _ | i |  i ƒ n h |  i
 d 6|  i d 6|  i	 d 6} |  i  i i o“ |  i  i i } t | ƒ d } | | j o | } |  i  i _ n d	 | }	 | o. d
 |  i  i |	 | f |  _ |  i | | <n |  i | |	 <n |  i  i i | ƒ |  i o |  i | ƒ n |  i | ƒ d S(   sÁ  Write the line to a log and create input cache variables _i*.

        Inputs:

        - line_ori: unmodified input line from the user.  This is not
        necessarily valid Python.

        - line_mod: possibly modified input, such as the transformations made
        by input prefilters or input handlers of various kinds.  This should
        always be valid Python.

        - continuation: if True, indicates this is part of multi-line input.t   _ihs   userns:Ni   s   
R   R   R	   s   _i%ss   %s%s
(   R
   t   user_nst   keyst   outputcachet   do_full_cachet   prompt_countt   lent   extendR   R	   R   R   R   t   updateR   t	   log_write(
   R   t   line_orit   line_modt   continuationt
   input_histt	   out_cachet   to_maint   in_numt   last_numt   new_i(    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt   log°   s<    
%$

t   inputc         C   sÛ   |  i  oÍ | oÆ |  i i } | d j o< |  i o  | t i d t i ƒ  ƒ ƒ n | d | ƒ na | d j oS |  i oI d i g  } | i	 d ƒ D] } | d | q— ~ ƒ } | d | ƒ n |  i i
 ƒ  n d S(   s%   Write data to the log file, if activeRZ   s   # %a, %d %b %Y %H:%M:%S
s   %s
t   outputs   
s
   #[Out]# %sN(   R   R   R4   R   t   timet   strftimet	   localtimeR   R,   t   splitR5   (   R   t   datat   kindR4   t   _[1]t   st   odata(    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyRO   ñ   s    
*c         C   s#   |  i  i ƒ  d |  _  t |  _ d S(   s×   Fully stop logging and close log file.

        In order to start logging again, a new logstart() call needs to be
        made, possibly (though not necessarily) with a new filename, mode and
        other options.N(   R   t   closeR   R   R   (   R   (    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt   logstop  s    	N(   t   __name__t
   __module__t   __doc__R   R   R   t   propertyR   R   R   R<   RB   RE   RY   RO   Rf   t	   close_log(    (    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyR   !   s   			A		A	(   Ri   t   IPythonR    t   authorst
   __author__t   licenset   __license__R.   R&   R\   t   objectR   (    (    (    sF   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Logger.pyt   <module>   s   	