ó
æNXc        
   @   s-  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z m	 Z	 d d l
 m Z m Z d d l m Z m Z d d l m Z m Z d d l m Z m Z d d l m Z d d	 l m Z d d
 l m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" e j# d k rde j$ j% d d ƒ Z' e' r[e j( j) e' d ƒ g Z* qpg  Z* n d d g Z* i d d 6d d 6d d 6d d 6d d 6Z+ e, d i i e j- d 6d 6d f d i i e j. d 6d 6d f d  i i e/ d! 6e/ d" 6d# 6d$ f ƒ Z0 d% e f d& „  ƒ  YZ1 d# e f d' „  ƒ  YZ2 d S((   s-  
An application for IPython.

All top-level applications should use the classes in this module for
handling configuration and creating configurables.

The job of an :class:`Application` is to create the master configuration
object and then create the configurable objects, passing the config to them.
iÿÿÿÿN(   t   Applicationt   catch_config_error(   t   ConfigFileNotFoundt   PyFileConfigLoader(   t   releaset   crashhandler(   t
   ProfileDirt   ProfileDirError(   t   get_ipython_dirt   get_ipython_package_dir(   t   ensure_dir_exists(   t	   py3compat(   t   Listt   Unicodet   Typet   Boolt   Dictt   Sett   Instancet	   Undefinedt   ntt   PROGRAMDATAt   ipythons   /usr/local/etc/ipythons   /etc/ipythons   ProfileDir.locations   profile-dirs   BaseIPythonApplication.profilet   profiles"   BaseIPythonApplication.ipython_dirs   ipython-dirs   Application.log_levels	   log-levels(   BaseIPythonApplication.extra_config_filet   configt   debugt	   log_levelR    s8   set log level to logging.DEBUG (maximize logging output)t   quiets;   set log level to logging.CRITICAL (minimize logging output)t   initt   copy_config_filest   auto_createt   BaseIPythonApplicationsš   Initialize profile with default config files.  This is equivalent
            to running `ipython profile create <profile>` prior to startup.
            t   ProfileAwareConfigLoaderc           B   s   e  Z d  Z d d d „ Z RS(   s>   A Python file config loader that is aware of IPython profiles.c         C   sb   | d  k	 rF y t j t ƒ  | ƒ } Wn t k
 r9 d  SX| j } n  t t |  ƒ j | d | ƒS(   Nt   path(	   t   NoneR   t   find_profile_dir_by_nameR   R   t   locationt   superR    t   load_subconfig(   t   selft   fnameR!   R   t   profile_dir(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyR&   E   s    N(   t   __name__t
   __module__t   __doc__R"   R&   (    (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyR    C   s   c           B   s$  e  Z e d  ƒ Z e d ƒ Z e e j ƒ Z e e ƒ Z	 e e
 ƒ Z e e g ƒ Z e Z e ƒ  Z e ƒ  Z d „  Z d „  Z e e j j e ƒ  d d d ƒ ƒ Z e e ƒ  ƒ Z d „  Z e d e d	 d
 ƒ Z d „  Z e d d e d	 d ƒZ  d „  Z! e d e d	 d ƒ Z" d „  Z# e$ Z% e& e d e ƒZ' d „  Z( e) e$ d e d	 d ƒZ* e) e$ d e d	 d ƒZ+ e e ƒ  ƒ Z, d „  Z- e) e$ d e d	 d ƒZ. e) e$ d e d	 d ƒZ/ e0 e1 j2 ƒ Z3 e4 d „  ƒ Z5 d „  Z6 d „  Z7 d „  Z8 e d „ Z9 d „  Z: d „  Z; d „  Z< e4 d  d „ ƒ Z> RS(!   u   ipythonu.   IPython: an enhanced interactive Python shell.c         C   s   |  j  j d d ƒ d S(   Nt   -t   _u
   _config.py(   t   namet   replace(   R'   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _config_file_name_defaultc   s    c         C   s#   | | k r |  j  j | ƒ n  d  S(   N(   t   config_file_specifiedt   add(   R'   R/   t   oldt   new(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _config_file_name_changede   s    u   configu   profileu   defaultc         C   s   t  j ƒ  g S(   N(   R   t   getcwd(   R'   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _config_file_paths_defaulto   s    R   t   helps€   Path to an extra config file to load.
    
    If specified, load this config file in addition to any other IPython config.
    c         C   sL   y |  j  j | ƒ Wn t k
 r' n X|  j j | ƒ |  j  j | ƒ d  S(   N(   t   config_filest   removet
   ValueErrorR2   R3   t   append(   R'   R/   R4   R5   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _extra_config_file_changedw   s    s   The IPython profile to use.c         C   s%   t  j j t ƒ  d d | ƒ |  _ d  S(   Nu   configu   profile(   t   osR!   t   joinR	   t   builtin_profile_dir(   R'   R/   R4   R5   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _profile_changedƒ   s    	s  
        The name of the IPython directory. This directory is used for logging
        configuration (through profiles), history storage, etc. The default
        is usually $HOME/.ipython. This option can also be specified through
        the environment variable IPYTHONDIR.
        c         C   s    t  ƒ  } |  j d | | ƒ | S(   Nt   ipython_dir(   R   t   _ipython_dir_changed(   R'   t   d(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _ipython_dir_default   s    	t
   allow_nonec         C   s   |  j  r d  S|  j ƒ  |  j S(   N(   t   _in_init_profile_dirt   init_profile_dirR)   (   R'   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _profile_dir_default—   s    	
s7   Whether to overwrite existing config files when copyings1   Whether to create profile dir if it doesn't existc         C   s
   |  j  g S(   N(   t   config_file_name(   R'   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   _config_files_default¥   s    s,  Whether to install the default config files into the profile dir.
        If a new profile is being created, and IPython contains config files for that
        profile, then they will be staged into the new directory.  Otherwise,
        default config files will be automatically generated.
        s¥   Create a massive crash report when IPython encounters what may be an
        internal error.  The default is to append a short message to the
        usual tracebackc         K   sQ   t  t |  ƒ j |   y t j ƒ  } Wn$ |  j j d ƒ |  j d ƒ n Xd  S(   Ns(   Current working directory doesn't exist.i   (   R%   R   t   __init__R   R7   t   logt   errort   exit(   R'   t   kwargst	   directory(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyRM   ·   s    c         C   s8   |  j  |  ƒ |  _ |  j t _ d „  } t j | ƒ d S(   s?   Create a crash handler, typically setting sys.excepthook to it.c           S   s   t  j t  _ d  S(   N(   t   syst   __excepthook__t
   excepthook(    (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   unset_crashhandlerÊ   s    N(   t   crash_handler_classt   crash_handlerRU   RS   t   atexitt   register(   R'   RV   (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   init_crash_handlerÆ   s    	c         C   s3   |  j  r |  j | | | ƒ St j | | | ƒ Sd S(   sÓ   this is sys.excepthook after init_crashhandler
        
        set self.verbose_crash=True to use our full crashhandler, instead of
        a regular traceback with a short message (crash_handler_lite)
        N(   t   verbose_crashRX   R   t   crash_handler_lite(   R'   t   etypet   evaluet   tb(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyRU   Î   s    	c         C   sv  | t  k	 rU t j t j j | ƒ t j ƒ  ƒ } | t j k rU t j j | ƒ qU n  t j t j j | ƒ t j ƒ  ƒ } t j j	 | ƒ t
 | ƒ t j j | d ƒ } t j j t ƒ  d d d ƒ } t j j | ƒ rþ t j j | ƒ rþ t j | | ƒ n  x] d D]U } t j j | | ƒ }	 y t
 |	 ƒ Wqt k
 rY}
 |  j j d |	 |
 ƒ qXqW|  j j d | ƒ d  S(	   Nt   READMEu   configu   profilet
   extensionst   nbextensionss   couldn't create path %s: %ss   IPYTHONDIR set to: %s(   s
   extensionsRc   (   R   R   t   cast_bytes_py2R?   R!   t   abspathRS   t   getfilesystemencodingR;   R=   R
   R@   R	   t   existst   shutilt   copyt   OSErrorRN   RO   R   (   R'   R/   R4   R5   t   str_oldt   str_patht   readmet
   readme_srcRE   R!   t   e(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyRD   Ú   s(    
%c         C   s]  |  j  j d |  j ƒ d } |  j  j d | ƒ y t j |  | d |  j ƒWn$ t k
 rs |  j  j d | ƒ n Xxâ |  j D]× } | s~ | | k r q~ n  |  j  j d |  j ƒ y t j |  | d |  j ƒWq~ t k
 r| |  j k rÿ |  j  j	 } n |  j  j } | d | ƒ q~ t
 k
 rT| s4‚  n  |  j  j	 d |  j d t ƒq~ Xq~ Wd	 S(
   sã   Load the config file.

        By default, errors in loading config are handled, and a warning
        printed on screen. For testing, the suppress_errors option is set
        to False, so errors will make tests fail.
        s"   Searching path %s for config filess   ipython_config.pys"   Attempting to load config file: %sR!   s   Config file %s not founds#   Config file not found, skipping: %ss   Error loading config file: %st   exc_infoN(   RN   R   t   config_file_pathsR    t   load_config_fileR   R:   RK   R2   t   warnt	   Exceptiont   True(   R'   t   suppress_errorst   base_configRK   t   msg(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyRr   ó   s@    c         C   sg  t  |  _ |  j d k	 r d Sd |  j k r+y" t j |  j |  j |  j ƒ } WnÁ t	 k
 r|  j
 su |  j d k ré y" t j |  j |  j |  j ƒ } Wn5 t	 k
 rÎ |  j j d |  j ƒ |  j d ƒ qX|  j j d | j ƒ q(|  j j d |  j ƒ |  j d ƒ q>X|  j j d | j ƒ n|  j j j } y t j | |  j ƒ } Wn  t	 k
 rõ|  j
 rÑy t j | |  j ƒ } Wn2 t	 k
 r¹|  j j d	 | ƒ |  j d ƒ qòX|  j j d
 | ƒ q
|  j j d | ƒ |  j d ƒ n X|  j j d | ƒ t j j | j ƒ } | j d ƒ r>| d |  _ n  | |  _ |  j j | j ƒ t |  _ d S(   s   initialize the profile dirNs   ProfileDir.locationt   defaults   Could not create profile: %ri   s   Created profile dir: %rs   Profile %r not found.s   Using existing profile dir: %rs&   Could not create profile directory: %rs   Creating new profile dir: %rs   Profile directory %r not found.t   profile_i   (   Ru   RH   R)   R"   R   R   R#   RC   R   R   R   t   create_profile_dir_by_nameRN   t   fatalRP   t   infoR$   R   t   find_profile_dirt   create_profile_dirR?   R!   t   basenamet
   startswithRq   R=   t   False(   R'   t   pR$   t   dir_name(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyRI   "  sJ    	""		c         C   s?  |  j  j t ƒ |  j } |  j r³ |  j } |  j } | r¦ t j j	 t j j
 | | ƒ ƒ r¦ |  j j d | | |  j j |  j f ƒ |  j j | d | d |  j ƒq;|  j ƒ  nˆ t j t j j
 | d ƒ ƒ } xg | D]_ } t j j | ƒ } |  j j | d | d t ƒrØ |  j j d | |  j |  j j f ƒ qØ qØ Wd S(   s8   [optionally] copy default config files into profile dir.s)   Staging %r from %s into %r [overwrite=%s]R!   t	   overwrites   *.pys"   Staging bundled %s from %s into %rN(   Rq   t   extendt   SYSTEM_CONFIG_DIRSRA   R   R   RK   R?   R!   Rg   R@   RN   Rs   R)   R$   R…   t   copy_config_filet   stage_default_config_filet   globR€   R‚   (   R'   R!   t   srct   cfgt   filest   fullpath(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   init_config_filesX  s     				'"c         C   s†   |  j  ƒ  } t j j |  j j |  j ƒ } |  j sF t j j | ƒ r‚ |  j	 j
 d | ƒ t | d ƒ  } | j | ƒ Wd QXn  d S(   sA   auto generate default config file, and stage it into the profile.s"   Generating default config file: %rt   wN(   t   generate_config_fileR?   R!   R@   R)   R$   RK   R…   Rg   RN   Rs   t   opent   write(   R'   t   sR(   t   f(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyR‰   v  s    c         C   sb   |  j  | ƒ |  j ƒ  |  j d  k	 r* d  S|  j } |  j ƒ  |  j ƒ  |  j ƒ  |  j | ƒ d  S(   N(	   t   parse_command_lineR[   t   subappR"   R   RI   R   Rr   t   update_config(   R'   t   argvt	   cl_config(    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt
   initialize  s    
	


N(?   R*   R+   R   R/   t   descriptionR   t   versionR   t   base_aliasest   aliasest
   base_flagst   flagsR   R   t   classesR    t   python_config_loader_classR   R2   RK   R1   R6   R?   R!   R@   R	   RA   Rq   R8   Ru   t   extra_config_fileR>   R   RB   RC   RF   R‚   RH   R   R)   RJ   R   R…   R   R:   RL   R   R\   R   R   t   CrashHandlerRW   R   RM   R[   RU   RD   Rr   RI   R   R‰   R"   R›   (    (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyR   Q   s`   				!																/	6			(3   R,   RY   RŠ   t   loggingR?   Rh   RS   t   traitlets.config.applicationR    R   t   traitlets.config.loaderR   R   t   IPython.coreR   R   t   IPython.core.profiledirR   R   t   IPython.pathsR   R	   t   IPython.utils.pathR
   t   IPython.utilsR   t	   traitletsR   R   R   R   R   R   R   R   R/   t   environt   getR"   t   programdataR!   R@   R‡   Rž   t   dictt   DEBUGt   CRITICALRu   R    R    R   (    (    (    sP   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/application.pyt   <module>
   sL   :		
		