Current File : //usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pyo
�
��Xc@s�ddlZddlZddlZddlZddlZddlZddlmZed�Z	ed�Z
dd�Zed�Z
ed�Zed�ZdS(	i����N(t
close_all_fdsc
Cs)g}tjjj�\}}tjdtd|||fdi|d6�}	|	j�|j|	j	�|j
�|j
�tjjj�\}
}tjdt�\}}
tjdt
di|d6d|||
f�}|j�|j|j	�|j
�|j
�|
j
�y4tjddgd|
d	tjd
tdd�}WnAtk
r�tjd
dgd|
d	tjd
tdd�}nX|
j
�|j|j	�tjddddd|d|gd|jd	|d
tdd�}|jj
�|j|j	�x!|D]}tjjj|�qW|S(Nttargettargstkwargstdebugtduplextpigzs-ctstdintstdoutt	close_fdstbufsizei����tgziptopenssltencs-es-aes-128-cbcs-Ks-iv(t	euca2oolstbundletutiltopen_pipe_fileobjstmultiprocessingtProcesst_create_tarball_from_streamtstarttappendtpidtclosetPipetFalset_calc_sha1_for_pipet
subprocesstPopentPIPEtTruetOSErrorRtwaitpid_in_thread(tinfiletoutfiletenc_keytenc_ivttarinfoRtpidst	tar_out_rt	tar_out_wttar_ptdigest_out_rtdigest_out_wtdigest_result_rtdigest_result_wtdigest_pRRR((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pytcreate_bundle_pipeline$sL


	









c
Csg}tjddddd|d|gd|dtjd	td
d�}|j|j�|j�y:tjdd
dgd|jdtjd	td
d�}WnGtk
r�tjdd
dgd|jdtjd	td
d�}nX|j|j�|jj�t	j
jj�\}}	t
jdt�\}
}t
jdtdi|d6d|j|	|f�}|j�|j|j�|jj�|	j�|j�t
jdtd||fdi|d6�}
|
j�|j�|j|
j�x!|D]}t	j
jj|�q�W|
S(s�
    Create a pipeline to perform the unbundle operation on infile input.
    The resulting unbundled image will be written to 'outfile'.

    :param outfile: file  obj to write unbundled image to
    :param enc_key: the encryption key used to bundle the image
    :param enc_iv: the encyrption initialization vector used in the bundle
    :returns multiprocess pipe to read sha1 digest of written image
    RR
s-ds-aes-128-cbcs-Ks-ivRRR	R
i����Rs-cRRRRRR(RRRRRRRRR RRRRRRRRRRt_extract_from_tarball_streamR!(R"R#R$R%RR'RRR+R,R-R.R/R*R((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pytcreate_unbundle_pipelineZsH





	



	


cCs�d}|r|j�nzmxf|js�|jtj�}|r�|j|�|j�|t|�7}|r�|j|�q�qPqWWd|r�|j	�n|j
�X|S(s�
    Synchronously copy data from infile to outfile, updating a progress bar
    with the total number of bytes copied along the way if one was provided,
    and return the number of bytes copied.

    This method must be run on the main thread.

    :param infile: file obj to read input from
    :param outfile: file obj to write output to
    :param progressbar: progressbar object to update with i/o information
    :param maxbytes: Int maximum number of bytes to write
    iN(RtclosedtreadRtBUFSIZEtwritetflushtlentupdatetfinishR(R"R#tprogressbart
bytes_writtentchunk((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pytcopy_with_progressbar�s"



	
cCs�t|||g�tj�}z�ydxJtrq|jtj�}|rm|j|�|j|�|j	�q(Pq(W|j
|j��Wntk
r�|s�dS�nXWd|j
�|j
�|j
�XdS(s�
    Read data from infile and write it to outfile, calculating a running SHA1
    digest along the way.  When infile hits end-of-file, send the digest in
    hex form to result_mpconn and exit.
    :param infile: file obj providing input for digest
    :param outfile: file obj destination for writing output
    :param digest_out_pipe_w: fileobj to write digest to
    :param debug: boolean used in exception handling
    N(Rthashlibtsha1RR4RR5R9R6R7tsendt	hexdigesttIOErrorR(R"R#tdigest_out_pipe_wRtdigestR=((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pyR�s&
	





cCs�td||g�tjddd|dtj�}z<y|j|d|�Wntk
rn|shdS�nXWd|j�|j�|j�XdS(Nt
except_fdstmodesw|tfileobjR
(RttarfiletopenRR5taddfileRCR(R"R#R&Rttarball((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pyR�s


cCs�t||g�tjddd|�}zNy)t|�}tj|j|�|�Wntk
rt|sndS�nXWd|j�|j�|j�XdS(s�
    Perform tar extract on infile and write to outfile
    :param infile: file obj providing input for tar
    :param outfile: file obj destination for tar output
    :param debug: boolean used in exception handling
    RGsr|RHN(	RRIRJtnexttshutiltcopyfileobjtextractfileRCR(R"R#RRLR&((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pyR1�s


(R?RRNRRIteuca2ools.bundle.utilRRRR0R2tNoneR>RRR1(((s?/usr/lib/python2.7/site-packages/euca2ools/bundle/pipes/core.pyt<module>s5<#!