U
    <Æg  ã                   @   s8   d dl T d dlmZmZ d dlmZ G dd„ deƒZdS )é    )Ú*)ÚBaseDataDriverÚMapper)ÚRDiskc                   @   s¾   e Zd Zdddœd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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ ZdS )/ÚRDiskDataDriverN)Ú	ds_configÚnamec                O   s   || _ |d | _|| _d S )NÚuri)Úconfigr	   r   )Úselfr   r   Ú_argsÚ_kwargs© r   ú$./modules/rdisk/data_driver/rdisk.pyÚ__init__   s    
zRDiskDataDriver.__init__.c                 C   s<   d }|dkr d }t jr t jjj}t|| jtj ¡ || j	dS )N.)Úloginr
   )
ÚgZcurrent_userr   Úvaluer   r	   ZAPPZrsa_public_keyZ
export_keyr
   )r   Zaccess_tokenr   r   r   r   Úget_rd    s    
    ÿzRDiskDataDriver.get_rdc                 O   sº   |  dd¡}|  ¡ }|r"|d }n$|  d¡rB|d }|d d }nt‚t|tjjƒrZ|j}|jj	||d}|srd S |  d¡}	t
ƒ j||	|d}
d	D ]"}||	kr’t|
|ƒj|	| d
 q’|
S )NÚmkdirFr   Úfilteré   )r   Úfull_fields_load)r   Úmodel©ÚparentÚparentsÚchildren©Úfields)Úgetr   ÚNotImplementedErrorÚ
isinstanceZcmfr   ZCmfTyper   ÚrootÚfind_child_by_idr   Zobject_to_cmfÚgetattrÚload)r   r   ÚargsÚkwargsr   ÚrdZ_idÚ_filterÚobjÚfflZmobjÚ
field_namer   r   r   r    3   s&    


zRDiskDataDriver.getc                 O   sH   |   ¡ }|jj}|j |¡}| |jj|jj¡}|j|j_	|j
|j
_	d S ©N)r   Ú	parent_idr   r#   r$   Z	add_childr   Úis_dirÚidÚ_valueÚperm_str)r   Úinstancer'   r(   r)   r/   Zparent_fr+   r   r   r   ÚcreateT   s    
zRDiskDataDriver.createc                 O   s$   |   ¡ }|j |jj¡}| ¡  |S r.   )r   r#   r$   r1   r   Údelete©r   r4   r'   r(   r)   r+   r   r   r   r6   `   s    zRDiskDataDriver.deletec                 O   s&   |   ¡ }|j |jj¡}|jj|_|S r.   )r   r#   r$   r1   r   r3   r7   r   r   r   Úupdatef   s    
zRDiskDataDriver.updatec                 O   sÌ   |   ¡ }|d }|stdƒ‚|d d dkrÄ|d d }|j |¡}| d¡}|jsXg S tƒ j|j||d}	i }
dD ]}||krt|| |
|< qt|
rÀ|	D ](}|
 ¡ D ]\}}t	||ƒj
|d	 q¢q–|	S t‚d S )
Nr   uE   Ð£ÐºÐ°Ð¶Ð¸Ñ‚Ðµ filter, Ð½Ð°Ð¿Ñ€Ð¸Ð¼ÐµÑ€ ['parent_id', '==', '/Trash']r   r/   r   r   )r   r   r   )r   Ú	Exceptionr#   r$   r    r   r   Zlist_to_cmfÚitemsr%   r&   r!   )r   r   r'   r(   r)   r*   r/   Zrfr,   Zobj_listZload_fieldsr-   r+   Z	field_fflr   r   r   Úlistl   s*    
zRDiskDataDriver.listc                 O   s   |   ¡ }| ||¡}|jS r.   )r   Úcreate_rfile_from_templater1   )r   ÚdirnameÚfilenamer'   r(   r)   Úresr   r   r   r<   „   s    z*RDiskDataDriver.create_rfile_from_templatec                 O   s&   |   ¡ }|j |jj¡}| |¡ d S r.   )r   r#   r$   r1   r   Úrename)r   r4   Z	target_idr'   r(   r)   r+   r   r   r   r@   ‰   s    zRDiskDataDriver.renamec                 C   s   d S r.   r   ©r   r   r   r   ÚcommitŽ   s    zRDiskDataDriver.commitc                 C   s   d S r.   r   rA   r   r   r   Úrollback‘   s    zRDiskDataDriver.rollbackc                 C   s   d S r.   r   rA   r   r   r   Úbefore_request”   s    zRDiskDataDriver.before_requestc                 C   s   d S r.   r   )r   Ú	cmf_modelr   r   r   Údp_model—   s    zRDiskDataDriver.dp_modelc                 C   s   d S r.   r   )r   Zsa_modelr   r   r   rE   š   s    zRDiskDataDriver.cmf_modelc                 C   s   d S r.   r   )r   Zdp_instancer   r   r   Úis_instance   s    zRDiskDataDriver.is_instancec                 C   s   d S r.   r   )r   Zmodels_r   r   r   Úmake_models    s    zRDiskDataDriver.make_modelsc                 O   s   dS )u,   Ð’ÐµÑ€Ð½Ñ‘Ð¼ ÐºÐ°ÑÑ‚Ð¾Ð¼Ð½Ñ‹Ð¹ Ð·Ð°Ð¿Ñ€Ð¾ÑNr   )r   r'   r(   r   r   r   Úquery_deprecated£   s    z RDiskDataDriver.query_deprecatedc                 C   s   |   d ¡}|jjddd d S )NT)r0   Úexist_ok)r   r#   r5   )r   r)   r   r   r   Úinit_db¦   s    
zRDiskDataDriver.init_dbc                 C   s   |   ¡ j |¡}| |¡ d S r.   )r   r#   r$   Úwrite)r   r1   Údatar+   r   r   r   rL   ª   s    zRDiskDataDriver.writec                 O   sB   |   ¡ }|j |¡}|s2| |¡}|jdddd |j||Ž d S )NFT)r0   rJ   r   )r   r#   r$   Z	get_rfiler5   Ústream_write)r   r1   r'   r(   r)   r+   r   r   r   rN   ®   s    
zRDiskDataDriver.stream_writec                 C   s   |   ¡ }|j |¡}|jS r.   )r   r#   r$   Útmp_readonly_path)r   r1   r)   r+   r   r   r   rO   ¶   s    z!RDiskDataDriver.tmp_readonly_path).)Ú__name__Ú
__module__Ú__qualname__r   r   r    r5   r6   r8   r;   r<   r@   rB   rC   rD   rF   rE   rG   rH   rI   rK   rL   rN   rO   r   r   r   r   r      s*   
!r   N)Zcmf.includeZcmf.data_providers.baser   r   Úrdiskr   r   r   r   r   r   Ú<module>   s   