
    Je                         d Z ddlmZ ddlZddlmZ ddlZddlm	Z	 ddl
mZ ddlmZmZmZmZmZ  G d d      Z G d	 d
e      Zy)z
Projects Plugin API.
    )OrderedDictN_)get_project_config_folder)ProjectMultiConfigPROJECT_NAME_MAPPROJECT_DEFAULTSPROJECT_CONF_VERSION	WORKSPACEc                       e Zd ZdZdZddZedfdZefdZd Z	d Z
ed        Zed	        Zed
        Zd Zd Zd Zy)BaseProjectTypez
    Spyder base project.

    This base class must not be used directly, but inherited from. It does not
    assume that python is specific to this project.
    Nc                    || _         || _        g | _        g | _        t	        j
                  |t               d      }	 | j                  |      | _        | j                  d      }|s| j                  d| j                         y y # t        j                  $ r. t        j                  |       | j                  |      | _        Y qw xY w)Nconfigproject_type)plugin	root_pathopen_project_filesopen_non_project_filesospjoinr   create_configr   configparserErrorshutilrmtree
get_option
set_optionID)selfr   parent_pluginpathact_names        =/usr/lib/python3/dist-packages/spyder/plugins/projects/api.py__init__zBaseProjectType.__init__$   s    #""$&(# xx	#<#>I
	3,,T2DK ??>2OONDGG4  !! 	3MM$,,T2DK	3s   B >CCc                 >    | j                   j                  |||      S )z!Get project configuration option.)sectionoptiondefault)r   get)r   r'   r&   r(   s       r#   r   zBaseProjectType.get_option=   s    {{wvwOO    c                 @    | j                   j                  |||       y)z!Set project configuration option.)r&   r'   valueN)r   set)r   r'   r,   r&   s       r#   r   zBaseProjectType.set_optionA   s    eDr*   c                 F   g }|D ]J  }t        j                  |      s	 t        j                  || j                        }|j	                  |       L t        t        j                  |            }| j                  d|       y# t
        $ r |j	                  |       Y w xY w)z*Set a list of files opened by the project.recent_filesN)
r   isfilerelpathr   append
ValueErrorlistr   fromkeysr   )r   r/   processed_recent_filesrecent_filerelative_recent_filefiless         r#   set_recent_filesz BaseProjectType.set_recent_filesE   s    !#' 	?Kzz+&?+.;;#T^^,5(*112FG	? [))*@AB.	 " ?*11+>?s   1BB B c                    | j                  ddg       }|r.| j                  j                  dd       | j                  |       n| j                  dg       }|D cg c]9  }t	        j
                  |      r|nt	        j                  | j                  |      ; }}|dd D ])  }t	        j                  |      r|j                  |       + t        t        j                  |            S c c}w )z-Return a list of files opened by the project.r/   main)r(   N)r   r   remove_optionr:   r   isabsr   r   r0   remover4   r   r5   )r   r/   r7   s      r#   get_recent_filesz BaseProjectType.get_recent_filesT   s     ~vrBKK%%fn=!!,/??>2?FL ,89' (+yy'= XXdnnkBC 9 9 (? 	1K::k*##K0	1 K((6779s   >C*c           
      @    t        t        | t        dt        ddd      S )z*Create the project's configuration object.TF)r!   defaultsloadversionbackupraw_moderemove_obsolete)r   r   r	   r
   )r!   s    r#   r   zBaseProjectType.create_configi   s)     "%(!	
 		
r*   c                      t        d      )z;
        Provide a human readable version of NAME.
        z#Must implement a `get_name` method!)NotImplementedError r*   r#   get_namezBaseProjectType.get_namey   s    
 ""GHHr*   c                      y)a  
        Validate the project's name.

        Returns
        -------
        tuple
            The first item (bool) indicates if the name was validated
            successfully, and the second item (str) indicates the error
            message, if any.
        T rJ   )r!   names     r#   validate_namezBaseProjectType.validate_name   s     r*   c                      y)a0  
        Create a project and do any additional setup for this project type.

        Returns
        -------
        tuple
            The first item (bool) indicates if the project was created
            successfully, and the second item (str) indicates the error
            message, if any.
        )Fz4A ProjectType must define a `create_project` method!rJ   r   s    r#   create_projectzBaseProjectType.create_project   s     Mr*   c                      y)a-  
        Open a project and do any additional setup for this project type.

        Returns
        -------
        tuple
            The first item (bool) indicates if the project was opened
            successfully, and the second item (str) indicates the error
            message, if any.
        )Fz3A ProjectType must define an `open_project` method!rJ   rR   s    r#   open_projectzBaseProjectType.open_project        Lr*   c                      y)a.  
        Close a project and do any additional setup for this project type.

        Returns
        -------
        tuple
            The first item (bool) indicates if the project was closed
            successfully, and the second item (str) indicates the error
            message, if any.
        )Fz3A ProjectType must define a `close_project` method!rJ   rR   s    r#   close_projectzBaseProjectType.close_project   rV   r*   )N)__name__
__module____qualname____doc__r   r$   r   r   r   r:   r@   staticmethodr   rK   rP   rS   rU   rX   rJ   r*   r#   r   r      s     
B52 *3D P 1: E/8* 
 
 I I  MLLr*   r   c                   2    e Zd ZdZed        Zd Zd Zd Zy)EmptyProjectzempty-project-typec                      t        d      S )NzEmpty projectr   rJ   r*   r#   rK   zEmptyProject.get_name   s    !!r*   c                      yNrM   rJ   rR   s    r#   rS   zEmptyProject.create_project       r*   c                      yrb   rJ   rR   s    r#   rU   zEmptyProject.open_project   rc   r*   c                      yrb   rJ   rR   s    r#   rX   zEmptyProject.close_project   rc   r*   N)	rY   rZ   r[   r   r]   rK   rS   rU   rX   rJ   r*   r#   r_   r_      s(    	B" "r*   r_   )r\   collectionsr   r   os.pathr!   r   r   spyder.api.translationsr   spyder.config.baser   $spyder.plugins.projects.utils.configr   r   r	   r
   r   r   r_   rJ   r*   r#   <module>rk      sE   
 $    & 8= =XL XLv? r*   