ó
æNXc           @   s¶   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   s3   An object for managing IPython profile directories.iÿÿÿÿN(   t   LoggingConfigurable(   t   get_ipython_package_dir(   t   expand_patht   ensure_dir_exists(   t	   py3compat(   t   Unicodet   Boolt   ProfileDirErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR      s   t
   ProfileDirc           B   sv  e  Z d  Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z	 e d ƒ Z
 e d ƒ Z e d ƒ Z e d ƒ Z e d d e d d	 ƒZ e e ƒ Z d
 „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e d „ Z  e! d d „ ƒ Z" e! d d d „ ƒ Z# e! d d d „ ƒ Z$ e! d d „ ƒ Z% RS(   s@  An object to manage the profile directory and its resources.

    The profile directory is used by all IPython applications, to manage
    configuration, logging and security.

    This object knows how to find, create and manage these directories. This
    should be used by any code that wants to handle profiles.
    t   securityt   logt   startupt   pidt   staticu    t   configt   helpsa   Set the profile location directly. This overrides the logic used by the
        `profile` option.c         C   sÀ   |  j  r t d ƒ ‚ n  t |  _  t | ƒ t j j | |  j ƒ |  _ t j j | |  j	 ƒ |  _
 t j j | |  j ƒ |  _ t j j | |  j ƒ |  _ t j j | |  j ƒ |  _ |  j ƒ  d  S(   Ns+   Cannot set profile location more than once.(   t   _location_issett   RuntimeErrort   TrueR   t   ost   patht   joint   security_dir_namet   security_dirt   log_dir_namet   log_dirt   startup_dir_namet   startup_dirt   pid_dir_namet   pid_dirt   static_dir_namet
   static_dirt
   check_dirs(   t   selft   namet   oldt   new(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _location_changed9   s    		
c         C   s   |  j  ƒ  d  S(   N(   t   check_log_dir(   R#   R$   R%   R&   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _log_dir_changedG   s    c         C   sÏ   t  j j | ƒ rr | rn t  j | ƒ j | k rn y t  j | | ƒ Wqn t k
 rj |  j j d | ƒ qn Xn  t	 Sy* | rŽ t  j
 | | ƒ n t  j
 | ƒ Wn, t k
 rÊ } | j t j k rÄ t	 S‚  n Xt S(   s  ensure a directory exists at a given path

        This is a version of os.mkdir, with the following differences:

        - returns True if it created the directory, False otherwise
        - ignores EEXIST, protecting against race conditions where
          the dir may have been created in between the check and
          the creation
        - sets permissions if requested and the dir already exists
        s   Could not set permissions on %s(   R   R   t   existst   statt   st_modet   chmodt   OSErrorR   t   warnt   Falset   mkdirt   errnot   EEXISTR   (   R#   R   t   modet   e(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _mkdirJ   s$    	c         C   s   |  j  |  j ƒ d  S(   N(   R6   R   (   R#   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR(   l   s    c         C   s   |  j  ƒ  d  S(   N(   t   check_startup_dir(   R#   R$   R%   R&   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _startup_dir_changedo   s    c         C   sª   |  j  |  j ƒ t j j |  j d ƒ } t j j t ƒ  d d d ƒ } t j j | ƒ sn |  j j d | ƒ n  t j j | ƒ r¦ t j j | ƒ r¦ t	 j
 | | ƒ n  d  S(   Nt   READMEu   coreu   profileu   README_STARTUPsL   Could not copy README_STARTUP to startup dir. Source file %s does not exist.(   R6   R   R   R   R   R   R*   R   R/   t   shutilt   copy(   R#   t   readmet   src(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR7   r   s    %c         C   s   |  j  ƒ  d  S(   N(   t   check_security_dir(   R#   R$   R%   R&   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _security_dir_changed~   s    c         C   s   |  j  |  j d ƒ d  S(   NiÀA  (   R6   R   (   R#   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR>      s    c         C   s   |  j  ƒ  d  S(   N(   t   check_pid_dir(   R#   R$   R%   R&   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _pid_dir_changed„   s    c         C   s   |  j  |  j d ƒ d  S(   NiÀA  (   R6   R   (   R#   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR@   ‡   s    c         C   s   |  j  ƒ  d  S(   N(   R7   (   R#   R$   R%   R&   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   _static_dir_changedŠ   s    c         C   s,   |  j  ƒ  |  j ƒ  |  j ƒ  |  j ƒ  d  S(   N(   R>   R(   R@   R7   (   R#   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR"      s    


c         C   s‹   t  j j |  j | ƒ } t  j j | ƒ r5 | r5 t S| d k rb t  j j t ƒ  d d d ƒ } n  t  j j | | ƒ } t j	 | | ƒ t
 S(   só   Copy a default config file into the active profile directory.

        Default configuration files are kept in :mod:`IPython.core.profile`.
        This function moves these from that location to the working profile
        directory.
        u   coreu   profileu   defaultN(   R   R   R   t   locationt   isfileR0   t   NoneR   R:   R;   R   (   R#   t   config_fileR   t	   overwritet   dstR=   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   copy_config_file“   s    !c         C   s   |  d | d | ƒ S(   sü   Create a new profile directory given a full path.

        Parameters
        ----------
        profile_dir : str
            The full path to the profile directory.  If it does exist, it will
            be used.  If not, it will be created.
        RC   R   (    (   t   clst   profile_dirR   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   create_profile_dir£   s    
u   defaultc         C   sQ   t  j j | ƒ s% t d | ƒ ‚ n  t  j j | d | ƒ } |  d | d | ƒ S(   s?  Create a profile dir by profile name and path.

        Parameters
        ----------
        path : unicode
            The path (directory) to put the profile directory in.
        name : unicode
            The name of the profile.  The name of the profile directory will
            be "profile_<profile>".
        s   Directory not found: %su   profile_RC   R   (   R   R   t   isdirR   R   (   RJ   R   R$   R   RK   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   create_profile_dir_by_name¯   s    c         C   s{   d | } t  j ƒ  | g } xX | D]@ } t j j | | ƒ } t j j | ƒ r# |  d | d | ƒ Sq# Wt d | ƒ ‚ d S(   sN  Find an existing profile dir by profile name, return its ProfileDir.

        This searches through a sequence of paths for a profile dir.  If it
        is not found, a :class:`ProfileDirError` exception will be raised.

        The search path algorithm is:
        1. ``py3compat.getcwd()``
        2. ``ipython_dir``

        Parameters
        ----------
        ipython_dir : unicode or str
            The IPython directory to use.
        name : unicode or str
            The name of the profile.  The name of the profile directory
            will be "profile_<profile>".
        u   profile_RC   R   s(   Profile directory not found in paths: %sN(   R   t   getcwdR   R   R   RM   R   (   RJ   t   ipython_dirR$   R   t   dirnamet   pathst   pRK   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   find_profile_dir_by_nameÀ   s    
c         C   sD   t  | ƒ } t j j | ƒ s1 t d | ƒ ‚ n  |  d | d | ƒ S(   sý   Find/create a profile dir and return its ProfileDir.

        This will create the profile directory if it doesn't exist.

        Parameters
        ----------
        profile_dir : unicode or str
            The path of the profile directory.
        s   Profile directory not found: %sRC   R   (   R   R   R   RM   R   (   RJ   RK   R   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   find_profile_dirÜ   s    N(&   R   R	   t   __doc__R   R   R   R   R   R    R   R   R   R   R!   R   RC   R   R0   R   R'   R)   RE   R6   R(   R8   R7   R?   R>   RA   R@   RB   R"   RI   t   classmethodRL   RN   RT   RU   (    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyR
      sF   			"									(   RV   R   R:   R2   t   traitlets.config.configurableR    t   IPython.pathsR   t   IPython.utils.pathR   R   t   IPython.utilsR   t	   traitletsR   R   t	   ExceptionR   R
   (    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/profiledir.pyt   <module>   s   