Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyc
�
��Xc@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
dZdZdZdefd��YZd	efd
��YZdS(i����N(topen_pipe_fileobjs(tImagePackMetadatat
ImageMetadatasimage.xzsimage-md.ymlspack-md.ymlt	ImagePackcBs\eZdd�Zed��Zeddd��Zd�Zd�Zd�Z	d�Z
RS(	cCs(d|_d|_||_d|_dS(N(tNonetpack_mdtimage_mdtfilenamet_ImagePack__tarball(tselfR((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyt__init__/s			cCstd|���}|jjt�}tj|jj|���}tj|�|_	WdQX|jjt
�}tj|jj|���A}tj|�|_|j
d�tj|j��j�}WdQX||j	jkr�td|j	j|��nWdQX|S(NRisHimage metadata appears to be corrupt (expected SHA256: {0}, actual: {1})(RRt	getmembertPACK_MD_ARCNAMEt
contextlibtclosingtextractfileRtfrom_fileobjRtIMAGE_MD_ARCNAMERRtseekthashlibtsha256treadt	hexdigesttimage_md_sha256sumtRuntimeError(tclsRtpacktmembertmd_fileR((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pytopen5s 
!	tcCs}t�}tj|�|_t�|_|dkr^tjj|�r^t	dj
|���ntjj|dj
|jj���|_
t|��.}tj|j��}|j�|j_WdQXtj���}tj�}d}	t|d���}
tjd
dtjd	|�}|r(|j�nxitr�|
jtj�}|sMPn|j|�|jj|�|	t |�7}	|r+|j|	�q+q+W|jj!�|j"�WdQX|r�|j#�n|j�|j_$|	|j_%t&j't(j|j
d
dt���k}
tj��-}|jj)|�|
j*|j+dt,�WdQX|
j*|dt-�|
j*|j+dt.�WdQXWdQX|S(NRs"{0}" is not a directorys{0}.euimageitrbtxzs-ctstdintstdouttwtdereferencetarcname(R s-c(/RRt	from_fileRRRtostpathtisdirt
ValueErrortformattjointget_nvraRRRRRRRttempfiletNamedTemporaryFilet
subprocesstPopentPIPEtstarttTruet	euca2oolstBUFSIZEtupdateR!twritetlentclosetwaittfinishtimage_sha256sumt
image_sizeR
Rttarfiletdump_to_fileobjtaddtnameRRt
IMAGE_ARCNAME(Rtimage_md_filenametimage_filenametdestdirtprogressbarRt
image_md_filetdigesttcompressed_imaget
bytes_readtoriginal_imagetxz_proctchunkttarballtpack_md_file((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pytbuildIsR		
	


"cCs&|jr|jj�nd|_dS(N(RR:R(R	((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyR:|s	cCs1|jst�tjd|jdd�|_|S(NRBtmodetr(RtAssertionErrorR?RR(R	((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyt	__enter__�scCs|j�dS(N(R:(R	ttype_tvaluettbk((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyt__exit__�scCsJ|jst�tjtjd|jdd���}t|�SWdQXdS(sW
        Return a file-like object that transparently yields the packed image.
        RBRRRSN(RRTR
RR?Rt_PackedImageWrapper(R	RO((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyt
open_image�s$N(t__name__t
__module__RR
tclassmethodRRQR:RURYR[(((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyR.s1			RZcBs>eZdZd�Zd�Zd�Zd�Zdd�ZRS(si
    A file-like object that transparently unpacks and decompresses the
    image from an image pack
    cCs�d|_d|_|jt�}|j|�}t�\}}tj�|_|jdkr�tj	�|j
�tjddtj
d|dt�|_|j
�tj||jj�|jjj
�|jj�tjtj�n	||_dS(	s�
        This method takes a tarfile.TarFile object and spawns *two* new
        processes: an xz process for decompression and an additional
        python process that simply feeds data from the TarFile to it.
        The latter is necessary because the file-like object we get from
        TarFile.extractfile cannot be passed to a subprocess directly.

        For that reason, one is also free to close the tarball after
        this object is created.
        iR s-dR!R"t	close_fdsN(sxzs-d(Rt_PackedImageWrapper__subp_pidt_PackedImageWrapper__read_fhRRCRRR'tforktsetpgrpR:R0R1R2R4t_PackedImageWrapper__xz_proctshutiltcopyfileobjR!R;t_exittEX_OK(R	RORRJtpipe_rtpipe_w((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyR
�s$		



cCsM|jr9tjtj|j�tj�|jj�ntjtj	�dS(N(
R`R'tkilltgetpgidtsignaltSIGTERMRaR:RgRh(R	((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyR:�s	 cCs|S(N((R	((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyRU�scCs|j�dS(N(R:(R	RVRWRX((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyRY�si����cCs|jj|�S(N(RaR(R	tsize((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyR�s(R\R]t__doc__R
R:RURYR(((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyRZ�s				(R
RR'ReRmR0R?R.R5teuca2ools.bundle.utilRt(euca2ools.commands.euimage.pack.metadataRRRCRRtobjectRRZ(((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyt<module>si