Viewing 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
Back to Directory File Manager