3
AAd]î
  ã               @   sb   d 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
 ejeƒZG dd„ de
ƒZdd	„ ZdS )
a   Attach relevant project files.

FIXME: there are no public project plugins for Envisage 3, yet. In any case,
this stuff should not be hard-coded, but extensible via extension points. The
code remains here because we can reuse the zip utility code in that extensible
rewrite.
é    N)ÚEncoders)ÚMIMEBase)ÚAnyÚ	HasTraitsc                   sH   e Zd Zeƒ Zeƒ Z‡ fdd„Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
‡  ZS )ÚAttachmentsc                s&   |j ƒ }||d< tt| ƒjf |Ž d S )NÚmessage)ÚcopyÚsuperr   Ú__init__)Úselfr   Útraits)Ú	__class__© ú}/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/apptools-4.4.0-py3.6.egg/apptools/logger/agent/attachments.pyr
      s    zAttachments.__init__c             C   s2   | j d kr
| j jdƒ}|d k	r.|j}| j|ƒ d S )Nzenvisage.project.IWorkspace)ÚapplicationÚget_serviceÚpathÚ_attach_directory)r   Z	workspaceÚdirr   r   r   Úpackage_workspace!   s    

zAttachments.package_workspacec             C   s2   | j d kr
| j jdƒ}|d k	r.|j}| j|ƒ d S )Nz$envisage.single_project.ModelService)r   r   Úlocationr   )r   Zsingle_projectr   r   r   r   Úpackage_single_project+   s
    
z"Attachments.package_single_projectc             C   s   | j ƒ  | jƒ  d S )N)r   r   )r   r   r   r   Úpackage_any_relevant_files4   s    z&Attachments.package_any_relevant_filesc             C   s¤   t jj|ƒ}dd l}ddlm} d}|jddƒ\}}t||ƒ}|ƒ }	|j|	dƒ}
t	|
||ƒ |
j
ƒ  |j|	jƒ ƒ tj|ƒ |jddd	d
� | jj|ƒ |	j
ƒ  d S )Nr   )ÚStringIOzapplication/octet-streamú/é   ÚwzContent-DispositionÚ
attachmentzproject.zip)Úfilename)Úosr   ÚbasenameÚzipfileÚior   Úsplitr   ÚZipFileÚ_append_to_zip_archiveÚcloseÚset_payloadÚgetvaluer   Úencode_base64Ú
add_headerr   Úattach)r   r   Úrelpathr!   r   ÚctypeÚmaintypeÚsubtypeÚmsgZfile_objectÚzipr   r   r   r   9   s    

zAttachments._attach_directory)Ú__name__Ú
__module__Ú__qualname__r   r   r   r
   r   r   r   r   Ú__classcell__r   r   )r   r   r      s   
	r   c             C   sˆ   x‚t j|ƒD ]t}t jj||ƒ}t jj|ƒrTt jj||ƒ}| j||ƒ tjd| ƒ q|dkrt jj||ƒ}t| |t jj||ƒƒ qW dS )z: Add all files in and below directory dir into zip archivezadding %s to error reportz.svnN)	r   Úlistdirr   ÚjoinÚisfileÚwriteÚloggerÚdebugr%   )r1   r   r,   r   r   ÚnameÚsubdirr   r   r   r%   T   s    r%   )Ú__doc__ÚloggingÚos.pathr   Úemailr   Zemail.MIMEBaser   Z
traits.apir   r   Ú	getLoggerr2   r:   r   r%   r   r   r   r   Ú<module>   s   
@