Format: application/x-python-code
⬇ Download File (7.7 KB)
   1  o
   2  
   3  ��h!�@s�dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
   4  mZmZddl
   5  mZmZmZdd	lmZGd
   6  d�de�ZGdd
   7  �d
   8  e�ZdS)z3An object for managing IPython profile directories.�N)�Path)�LoggingConfigurable�)�get_ipython_package_dir)�expand_path�ensure_dir_exists)�Unicode�Bool�observe)�Optionalc@seZdZdS)�ProfileDirErrorN)�__name__�
   9  __module__�__qualname__�rr�Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/profiledir.pyrsrc@sHeZdZdZed�Zed�Zed�Zed�Zed�Z	ed�Z
  10  ed�Zed�Zed�Z
  11  ed�Zeddd	�jd
  12  d�Zed�Zed
  13  �dd��Zd0dedeedefdd�Zed�d0dd��Zed�d0dd��Zed�d0dd��Zed�d0d d!��Zd"d#�Zd1d$ededefd%d&�Z e!d0d'd(��Z"e!d2d*d+��Z#e!d2d,d-��Z$e!d0d.d/��Z%dS)3�
  14  ProfileDira@An object to manage the profile directory and its resources.
  15  
  16      The profile directory is used by all IPython applications, to manage
  17      configuration, logging and security.
  18  
  19      This object knows how to find, create and manage these directories. This
  20      should be used by any code that wants to handle profiles.
  21      �security�logZstartup�pidZstatic�zaSet the profile location directly. This overrides the logic used by the
  22          `profile` option.)�helpT)�configF�locationcCs�|jrtd��d|_|d}t|�tj�||j�|_tj�||j�|_	tj�||j
  23  �|_tj�||j�|_
  24  tj�||j�|_|��dS)Nz+Cannot set profile location more than once.T�new)�_location_isset�RuntimeErrorr�os�path�join�security_dir_name�security_dir�log_dir_name�log_dir�startup_dir_name�startup_dir�pid_dir_name�pid_dir�static_dir_name�
  25  static_dir�
  26  check_dirs)�self�changerrrr�_location_changed:szProfileDir._location_changedNr�mode�returnc
  27  Cs�tj�|�r-|r+t�|�j|kr+z	t�||�WdSty*|j�d|�YdSwdSz|r9t�	||�WdSt�	|�WdStyZ}z|j
  28  t
  29  jkrUWYd}~dS�d}~ww)a�ensure a directory exists at a given path
  30  
  31          This is a version of os.mkdir, with the following differences:
  32  
  33          - returns whether the directory has been created or not.
  34          - ignores EEXIST, protecting against race conditions where
  35            the dir may have been created in between the check and
  36            the creation
  37          - sets permissions if requested and the dir already exists
  38  
  39          Parameters
  40          ----------
  41          path: str
  42              path of the dir to create
  43          mode: int
  44              see `mode` of `os.mkdir`
  45  
  46          Returns
  47          -------
  48          bool:
  49              returns True if it created the directory, False otherwise
  50          zCould not set permissions on %sFNT)rr�exists�stat�st_mode�chmod�OSErrorr�warning�mkdir�errno�EEXIST)r+rr.�errr�_mkdirJs2���	����zProfileDir._mkdirr#cCs|�|j�dS�N)r:r#�r+r,rrr�
  51  check_log_diryszProfileDir.check_log_dirr%cCsr|�|j�r7tj�|jd�}tj�t�ddd�}tj�|�r.tj�|�s,t�||�dSdS|j	�
  52  d|�dSdS)NZREADME�core�profileZREADME_STARTUPzLCould not copy README_STARTUP to startup dir. Source file %s does not exist.)r:r%rrrrr0�shutil�copyrr5)r+r,Zreadme�srcrrr�check_startup_dir}s
  53  ����zProfileDir.check_startup_dirr!cC�|�|jd�dS�Ni�A)r:r!r<rrr�check_security_dir��zProfileDir.check_security_dirr'cCrDrE)r:r'r<rrr�
  54  check_pid_dir�rGzProfileDir.check_pid_dircCs$|��|��|��|��dSr;)rFr=rHrC)r+rrrr*�szProfileDir.check_dirs�config_filecCsfttj�|j|��}|��r|sdS|dur tj�t�ddd�}t|t�s'J�||}t�	||�dS)z�Copy a default config file into the active profile directory.
  55  
  56          Default configuration files are kept in :mod:`IPython.core.profile`.
  57          This function moves these from that location to the working profile
  58          directory.
  59          FNr>r?�defaultT)
  60  rrrrrr0r�
  61  isinstancer@rA)r+rIr�	overwrite�dstrBrrr�copy_config_file�szProfileDir.copy_config_filecCs|||d�S)z�Create a new profile directory given a full path.
  62  
  63          Parameters
  64          ----------
  65          profile_dir : str
  66              The full path to the profile directory.  If it does exist, it will
  67              be used.  If not, it will be created.
  68          �rrr��cls�profile_dirrrrr�create_profile_dir�s
  69  zProfileDir.create_profile_dirrJcCs6tj�|�std|��tj�|d|�}|||d�S)a?Create a profile dir by profile name and path.
  70  
  71          Parameters
  72          ----------
  73          path : unicode
  74              The path (directory) to put the profile directory in.
  75          name : unicode
  76              The name of the profile.  The name of the profile directory will
  77              be "profile_<profile>".
  78          zDirectory not found: %s�profile_rO)rr�isdirrr)rQr�namerrRrrr�create_profile_dir_by_name�sz%ProfileDir.create_profile_dir_by_namecCsNd|}|g}|D]}tj�||�}tj�|�r |||d�Sq	td|��)afFind an existing profile dir by profile name, return its ProfileDir.
  79  
  80          This searches through a sequence of paths for a profile dir.  If it
  81          is not found, a :class:`ProfileDirError` exception will be raised.
  82  
  83          The search path algorithm is:
  84          1. ``os.getcwd()`` # removed for security reason.
  85          2. ``ipython_dir``
  86  
  87          Parameters
  88          ----------
  89          ipython_dir : unicode or str
  90              The IPython directory to use.
  91          name : unicode or str
  92              The name of the profile.  The name of the profile directory
  93              will be "profile_<profile>".
  94          rTrOz(Profile directory not found in paths: %s)rrrrUr)rQZipython_dirrVr�dirname�paths�prRrrr�find_profile_dir_by_name�s�z#ProfileDir.find_profile_dir_by_namecCs,t|�}tj�|�std|��|||d�S)z�Find/create a profile dir and return its ProfileDir.
  95  
  96          This will create the profile directory if it doesn't exist.
  97  
  98          Parameters
  99          ----------
 100          profile_dir : unicode or str
 101              The path of the profile directory.
 102          zProfile directory not found: %srO)rrrrUrrPrrr�find_profile_dir�szProfileDir.find_profile_dirr;)F)rJN)&r
 103  rr�__doc__rr r"r$r&r(r!r#r%r'r)�tagrr	rr
 104  r-�strr�int�boolr:r=rCrFrHr*rrN�classmethodrSrWr[r\rrrrrsN	��
 105  /r)r]rr@r7�pathlibrZtraitlets.config.configurablerrYrZ
 106  utils.pathrrZ	traitletsrr	r
 107  �typingr�	Exceptionrrrrrr�<module>s