3
AAd]y
  ã               @   s<   d Z ddlZddlmZmZmZmZmZ G dd„ deƒZ	dS )zwSimple class to support file path objects that work well in the
context of persistent storage with the state_pickler.

é    N)ÚabspathÚnormpathÚdirnameÚcommonprefixÚjoinc               @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚFilePatha�  This class stores two paths to the file.  A relative path and
    an absolute one.  The absolute path is used by the end user.  When
    this object is pickled the state_pickler sets the relative path
    relative to the file that is being generated.  When unpickled, the
    stored relative path is used to set the absolute path correctly
    based on the path of the saved file.
    Ú c             C   s   | j |ƒ d S )N)Úset)ÚselfÚvalue© r   úz/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/apptools-4.4.0-py3.6.egg/apptools/persistence/file_path.pyÚ__init__   s    zFilePath.__init__c             C   s   | j S )N)Úabs_pth)r
   r   r   r   Ú__str__   s    zFilePath.__str__c             C   s
   | j jƒ S )N)r   Ú__repr__)r
   r   r   r   r      s    zFilePath.__repr__c             C   s   | j S )zGet the path.
        )r   )r
   r   r   r   Úget   s    zFilePath.getc             C   s$   || _ |rtt|ƒƒ| _nd| _dS )z$Sets the value of the path.
        r   N)Úrel_pthr   r   r   )r
   r   r   r   r   r	   $   s    zFilePath.setc             C   s˜   t |ƒ}| j}xL|jtjƒD ]<}|j|tj ƒrVt|ƒd }||d… }||d… }qP qW |jtjƒdtj  | }tjdk	rŽ|jtjdƒ || _	dS )zÝSets the path relative to `base_f_name`.  Note that
        `base_f_name` and self.rel_pth should be valid file names
        correct on the current os.  The set name is a file name that
        has a POSIX path.
        é   Nz..ú/)
r   r   ÚsplitÚosÚsepÚ
startswithÚlenÚcountÚreplacer   )r
   Úbase_f_nameZ_srcZ_dstÚpartÚlengthÚretr   r   r   Úset_relative-   s    
zFilePath.set_relativec             C   s:   t t|ƒƒ}t | jƒ}tt|ƒ|ƒ}tjj |ƒ}|| _dS )zxSets the absolute file name for the current relative file
        name with respect to the given `base_f_name`.
        N)r   r   r   r   r   r   Úpathr   )r
   r   Zrel_file_nameÚ	file_namer   r   r   Úset_absoluteL   s
    
zFilePath.set_absoluteN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r!   r$   r   r   r   r   r      s   
	r   )
r(   r   Úos.pathr   r   r   r   r   Úobjectr   r   r   r   r   Ú<module>   s   