ó
æNXc           @   sz   d  Z  d d l Z d d l Z d d l m Z m Z m Z d d l m Z d d l	 m
 Z
 e d e f d „  ƒ  Yƒ Z d S(   s=   Implementation of magic functions for IPython's own logging.
iÿÿÿÿN(   t   Magicst   magics_classt
   line_magic(   t   warn(   t   str_to_unicodet   LoggingMagicsc           B   sh   e  Z d  Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z RS(   s(   Magics related to all logging machinery.t    c         C   s$  |  j  | d ƒ \ } } d | k } d | k } d | k } |  j j } | r} y | j ƒ  \ } }	 Wq | } d }	 q Xn | j } | j }	 |  j j }
 | r¶ t j j	 | ƒ } n  | |  j _ d } y  | j
 | | |	 | | | ƒ Wn+ |
 |  j _ t d t j ƒ  d ƒ nX| r(t | _ n  | r@|  j j j } n |  j j j } | rØ| j } |  j j j } x t d t | ƒ d ƒ D]J } | | | j ƒ  d	 ƒ | | k r‡| t t | | ƒ ƒ d
 ƒ q‡q‡Wn' | j d	 j | d ƒ ƒ | j d	 ƒ | rt | _ n  d GH| j ƒ  d S(   s‘  Start logging anywhere in a session.

        %logstart [-o|-r|-t] [log_name [log_mode]]

        If no name is given, it defaults to a file named 'ipython_log.py' in your
        current directory, in 'rotate' mode (see below).

        '%logstart name' saves to file 'name' in 'backup' mode.  It saves your
        history up to that point and then continues logging.

        %logstart takes a second optional parameter: logging mode. This can be one
        of (note that the modes are given unquoted):

        append
            Keep logging at the end of any existing file.

        backup
            Rename any existing file to name~ and start name.

        global
            Append to  a single logfile in your home directory.

        over
            Overwrite any existing log.

        rotate
            Create rotating logs: name.1~, name.2~, etc.

        Options:

          -o
            log also IPython's output. In this mode, all commands which
            generate an Out[NN] prompt are recorded to the logfile, right after
            their corresponding input line. The output lines are always
            prepended with a '#[Out]# ' marker, so that the log remains valid
            Python code.

          Since this marker is always the same, filtering only the output from
          a log is very easy, using for example a simple awk call::

            awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py

          -r
            log 'raw' input.  Normally, IPython's logs contain the processed
            input, so that user lines are logged in their final form, converted
            into valid Python.  For example, %Exit is logged as
            _ip.magic("Exit").  If the -r flag is given, all input is logged
            exactly as typed, with no transformations applied.

          -t
            put timestamps before each input line logged (these are put in
            comments).
        t   ortt   ot   rt   tt   backupu   # IPython log file

s   Couldn't start log: %si   u   
t   outputsG   Activating auto-logging. Current session state plus future input saved.N(   t   parse_optionst   shellt   loggert   splitt   logfnamet   logmodet   logfilet   ost   patht
   expandusert   logstartR   t   syst   exc_infot   Falset	   timestampt   history_managert   input_hist_rawt   input_hist_parsedt	   log_writet   output_histt   ranget   lent   rstripR   t   reprt   joint   Truet   logstate(   t   selft   parameter_st   optst   part
   log_outputt   log_raw_inputR   R   R   R   t   old_logfilet   logheadt
   input_histR   R    t   n(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyR       sT    8			 'c         C   s   |  j  j j ƒ  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   R   t   logstop(   R(   R)   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyR2   ™   s    c         C   s   |  j  j j d ƒ d S(   sL   Temporarily stop logging.

        You must have previously started logging.i    N(   R   R   t
   switch_log(   R(   R)   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyt   logoff¢   s    c         C   s   |  j  j j d ƒ d S(   s  Restart logging.

        This function is for restarting logging which you've temporarily
        stopped with %logoff. For starting logging for the first time, you
        must use the %logstart function, which allows you to specify an
        optional log filename.i   N(   R   R   R3   (   R(   R)   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyt   logon©   s    	c         C   s   |  j  j j ƒ  d S(   s'   Print the status of the logging system.N(   R   R   R'   (   R(   R)   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyR'   ´   s    (	   t   __name__t
   __module__t   __doc__R   R   R2   R4   R5   R'   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyR      s   x
(   R8   R   R   t   IPython.core.magicR    R   R   t   IPython.utils.warnR   t   IPython.utils.py3compatR   R   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/logging.pyt   <module>   s   