Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pyo
�
��Xc@s�ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
ddlZddlmZddlmZmZmZdd	lmZd
ee
efd��YZdS(i����N(tArg(tBaseCommand(t
ArgumentError(tFileTransferProgressBarMixintRegionConfigurableMixin(t	Euca2ools(tBundleManifest(t
close_all_fdstopen_pipe_fileobjstwaitpid_in_thread(tUnbundleStreamtUnbundlecBs�eZdZeZedddedddedd�ed	d
dddd
dd�edddddd
dd�edddddd�gZd�Z	d�Z
d�Zd�ZRS(s�Recreate an image from its bundled parts

The key used to unbundle the image must match a certificate that was used to bundle it.s-ms
--manifestttypetmetavartFILEtrequiredthelps%the bundle's manifest file (required)s-ss--sourcetDIRtdefaultt.sYdirectory containing the bundled image parts (default:
                current directory)s-ds
--destinationsOwhere to place the unbundled image (default: current
                directory)s-ks--privatekeys�file containing
                the private key to decrypt the bundle with.  This must match
                a certificate used when bundling the image.cCsdtj|�|j�|jjd�s�|jjd�}|jjd�r]||jd<q�dtjkr�tj	d�|jd<q�|r�||jd<q�t
d��ntjjtjj
|jd��|jd<tjj|jd�st
dj|jd���ntjj|jd�sFt
dj|jd���n|jjd|jd�tjj|jjd	d
��s�t
dj|jd	���ntjj|jjd	d
��s�t
dj|jd	���ntjj|jjd
d
��s t
dj|jd
���ntjj|jjd
d
��s`t
dj|jd
���ndS(Nt
privatekeysprivate-keyt
userregiontEC2_PRIVATE_KEYs.missing private key; please supply one with -ks%private key file '{0}' does not exists$private key file '{0}' is not a filesprivate key: %stsourceRs4argument -s/--source: directory '{0}' does not exists.argument -s/--source: '{0}' is not a directorytdestinations9argument -d/--destination: directory '{0}' does not exists3argument -d/--destination: '{0}' is not a directory(Rt	configuretupdate_config_viewtargstgettconfigtget_user_optiontostenvirontgetenvRtpatht
expandusert
expandvarstexiststformattisfiletlogtdebugtisdir(tselftconfig_privatekey((sF/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pyR?sB

		!	!	!	!	c	
Cstd|g�x|jD]�}|jjd|j�tj�}t|j���}xJtr�|j	t
j�}|r�|j|�|j
|�|j�qWPqWWt|j�d�}t|jd�}||kr|jjd||�tdj|j||���nWdQXqWdS(Nt
except_fdssopening part '%s' for readingisGrejecting unbundle due to part SHA1 mismatch (expected: %x, actual: %x)sLbundle part '{0}' appears to be corrupt (expected SHA1: {1:x}, actual: {2:x}(Rtimage_partsR(R)tfilenamethashlibtsha1topentTruetreadt	euca2oolstBUFSIZEtupdatetwritetflushtintt	hexdigestterrortRuntimeErrorR&(	R+tmanifesttoutfiletparttdigestt	part_filetchunkt
actual_digesttexpected_digest((sF/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pyt__read_bundle_partshs(	



c
Cs�tj|jdd|jd�}x�|jD]x}tjj|jd|j�}x|jd�rq|d}qUWtjj	|�r�||_q-t
dj|���q-Wt�\}}t
jd|jd	||f�}|j�|j�t|j�tjj|jd
|j�}t|d��e}tj|d|d|d
|jd|jd|jd|jd|jjdt��}	|	j�WdQX|S(NR>tprivkey_filenameRRs./isdbundle part '{0}' does not exist; you may need to use -s to specify where to find the bundle's partsttargetRRtwtdesttenc_keytenc_ivt
image_sizetsha1_digestt
show_progress(Rtread_from_fileobjRR.RR"tjoinR/t
startswithR%R=R&RtmultiprocessingtProcesst_Unbundle__read_bundle_partststarttcloseR	tpidt
image_nameR2R
t
from_otherRKRLRMtimage_digestRtFalsetmain(
R+R>R@t	part_pathtpart_reader_out_rtpart_reader_out_wtpart_readertimage_filenametimagetunbundlestream((sF/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pyR]�s:		


		cCs
dG|GHdS(NtWrote((R+Rb((sF/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pytprint_result�s(
t__name__t
__module__tDESCRIPTIONRtSUITERR2R3tARGSRRUR]Rf(((sF/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pyR,s	)		%(R0RSRtrequestbuilderRtrequestbuilder.commandRtrequestbuilder.exceptionsRtrequestbuilder.mixinsRRteuca2ools.commandsRteuca2ools.bundle.pipesR5teuca2ools.bundle.manifestRteuca2ools.bundle.utilRRR	t(euca2ools.commands.bundle.unbundlestreamR
R(((sF/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/unbundle.pyt<module>s