ó ¡ôXc@sÔddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z dZdZdZdefd„ƒYZd efd „ƒYZdS( iÿÿÿÿN(topen_pipe_fileobjs(tImagePackMetadatat ImageMetadatasimage.xzs image-md.ymls pack-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   c Cstd|ƒì}|jjtƒ}tj|jj|ƒƒ}tj|ƒ|_ WdQX|jjt ƒ}tj|jj|ƒƒA}t j|ƒ|_ |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 contextlibtclosingt extractfileRt 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 d tƒƒ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-ctstdintstdouttwt dereferencetarcname(R s-c(/RRt from_fileRRRtostpathtisdirt ValueErrortformattjointget_nvraRRRRRRRttempfiletNamedTemporaryFilet subprocesstPopentPIPEtstarttTruet euca2oolstBUFSIZEtupdateR!twritetlentclosetwaittfinishtimage_sha256sumt image_sizeR Rttarfiletdump_to_fileobjtaddtnameR Rt IMAGE_ARCNAME(Rtimage_md_filenametimage_filenametdestdirt progressbarRt 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 cCs"tjd|jddƒ|_|S(NRBtmodetr(R?RRR(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__†scCs;tjtjd|jddƒƒ}t|ƒSWdQXdS(sW Return a file-like object that transparently yields the packed image. RBRRRSN(R RR?RRt_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 t classmethodRRQR:RTRXRZ(((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyR.s 1   RYcBs>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 ƒt j ddt j 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_fhR RCRRR'tforktsetpgrpR:R0R1R2R4t_PackedImageWrapper__xz_proctshutilt copyfileobjR!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'tkilltgetpgidtsignaltSIGTERMR`R:RfRg(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.pyRTÄscCs|jƒdS(N(R:(R RURVRW((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyRXÇsiÿÿÿÿcCs|jj|ƒS(N(R`R(R tsize((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyRÊs(R[R\t__doc__R R:RTRXR(((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyRY—s     (R RR'RdRlR0R?R.R5teuca2ools.bundle.utilRt(euca2ools.commands.euimage.pack.metadataRRRCRR tobjectRRY(((sH/usr/lib/python2.7/site-packages/euca2ools/commands/euimage/pack/pack.pyts         i