ó i'dWc@sVdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZmZmZmZdd lmZde fd„ƒYZdefd„ƒYZdefd„ƒYZdS(s> Transfer CPIO checkpoint. Sub-class of the checkpoint class. iÿÿÿÿN(t file_size(tAbstractCheckpoint(t InstallEngine(tArgs(tCPIOSpec(t Destination(tDir(tSoftware(tSource(tACTIONtCONTENTSt CPIO_ARGStSIZE(t ProgressMont AbstractCPIOcBs×eZdZejZdZdZdZdZ d„Z e d„Z d„Z d„Zed „Zd „Zejd „ƒZd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s%Subclass for transfer CPIO checkpoints /usr/bin/cpios-pdumi iècCswtt|ƒj|ƒtƒ|_d|_d|_d|_d|_ t |_ t |_ t |_ d|_d|_dS(Ni(tsuperRt__init__tlistt_transfer_listtNonet_doctdsttsrct distro_sizetFalset give_progresstdry_runt _cancel_eventt cpio_processtpmon(tselftname((scpio.pyR=s         c Csª|rZy|jdtƒWqZtk rV|jrPtjj|jƒ rP|jS‚qZXn|jƒd}x|j D]}|j t ƒdkrt|j t ƒ}|dk rÐ|jjd|ƒ|t|ƒ7}qy|}|j tƒ}t|dƒi}yN|tttg|jƒD]$}tjj|j|jƒƒ^qƒƒ}Wntk rXnXWdQX|jjd||ƒqtqtW|rœ|jƒtƒ|_ n|d}|S( s*Compute the size of the transfer specifiedtgenerate_file_listitinstallsPrecalculated size: %s bytestrNs$Size calculated at runtime: %d bytesi(t _parse_inputRt ValueErrorRtostpathtexistst DEFAULT_SIZEt_validate_inputRtgetR R RtloggertdebugtintR topentsumtmapRt readlinestjointrstriptOSErrort_cleanup_tmp_filesR( Rtneed_parse_inputtsizettransfert pre_calc_sizetold_sizet file_listt filehandletf((scpio.pytget_size[sB       ?     cCsU|jƒ|_|jjd|jƒtt|jƒ|j|jƒ}t|_ |S(saReturns an estimate of the time this checkpoint will take given the DOC input sDistro size: %d KB( R>RR+R,R-tfloatR(tDEFAULT_PROG_ESTtTrueR(Rtprogress_estimate((scpio.pytget_progress_estimates   cCs&t|_|jr"|jjƒndS(sCancel the transfer in progressN(RARRtkill(R((scpio.pytcancel¬s  cCs}|jjd|jƒ|jr6|jjddƒn||_z,|jƒ|jƒ|jƒ|j ƒWd|j ƒXdS(s…Execute method for the CPIO checkpoint module. Will read the input parameters and perform the specified transfer. s=== Executing %s Checkpoint ===sBeginning CPIO transferiN( R+tinfoRRtreport_progressRR#R)tcheck_cancel_eventt _transfert_cleanup(RR((scpio.pytexecute²s     cCs|jr|jƒndS(s‘Check the _cancel_event attribute to see if a cancel_event has been requested. If it has, cleanup what has been done already N(RRJ(R((scpio.pyRHÉs cCs t‚dS(s;This method is required to be implemented by all subclassesN(tNotImplementedError(R((scpio.pyR#ÐscCs˜y€xy|jD]n}|jtƒdkr |jtƒ}|dk r{tjj|ƒr{|jj d|ƒtj |ƒq{q q WWnt k r“nXdS(s/Remove the tmp files we created from the systemR!sRemoving temp content file: %sN( RR*R R RR%R&R'R+R,tunlinkR4(RR8t content_file((scpio.pyR5Õs   cCs<|jr.t|j_|jjƒd|_n|jƒdS(s.Method to perform any necessary cleanup neededN(RRAtdonetwaitRR5(R((scpio.pyRJãs     cCs<|jjdƒ|jdkr8|jƒtdƒ‚ndS(s'Method to validate the local attributessValidating CPIO inputs"CPIO destination must be specifiedN(R+R,RRR5R$(R((scpio.pyR)ìs cCs|jjdƒ|r÷t|tƒr)|St|tƒr tjtjtjg}||kr˜t j t j j |j |ƒt jƒ r˜|jjdƒdSt j j|ƒsÅt j j |j |ƒ}nt j |t jƒsítd|ƒ‚n|Sq n|jjdƒdSdS(sªCheck that the contents passed in are a valid list of files or a file containing a list of files. If it is a file make sure it is readable. sValidating CPIO contentss)CPIO Transfer: no default file list foundsMCPIO Transfer file list specified either doesn't exist or is not readable, %ss%CPIO Transfer: No contents list foundN(R+R,t isinstanceRtstrtCPIOtDEF_INSTALL_LISTtDEF_UNINSTALL_LISTtDEF_MEDIA_TRANSFORMR%taccessR&R2RtR_OKRtisabsR$(Rtcontentstcpio_install_types((scpio.pytvalidate_contentsôs*     c Csg}t|dƒž}x”|jƒD]†}|jƒ}y;tjtjj|j|ƒƒ}|j|j |fƒWq%t k rª}|j j d|ƒ|j j |ƒq%Xq%WWdQX|j dtjdƒƒt|dƒ;}x1ttjdƒ|ƒD]}|j|dƒqùWWdQXdS( s_Sort the entries in the file by inode. Place the sorted results in the file R"s!CPIO transfer error processing %sNtkeyitais (R.R1R3R%tlstatR&R2Rtappendtst_inoR4R+R,tsorttoperatort itemgetterR0twrite( Rtinfiletoutfilet tmp_flistR<tfnametst1tmsgtentry((scpio.pyt sort_by_inodes ! cCs|jjdƒtj|ƒ}d|kr;|jdƒn|jjd|ƒtj|ƒ}|j|j|jƒdjdƒƒx‘tj |ƒD]€\}}}|j ƒg}xÆ|D]¾} tj j || ƒ} tj j |j|jƒdjdƒ| ƒ} tj| ƒ}|j| ƒytj| ƒ}Wn!t k rT|j| ƒq¹nX|j|jkr¹|j| ƒq¹q¹Wx|D]} |j| ƒq‚Wxw|D]o} |j ƒtj j || ƒ}tj j |j|jƒdjdƒ| ƒ}tj|ƒ}|j|ƒq Wq“WdS(s Method to build a list of files to be transferred from the specified source. All files in the directory tree rooted at src are included. Input: src: src of the tree to walk output_file : file to place the sorted file list into. s%CPIO Transfer: building the file lists./sbuilding file list %sit/N(R+R,R%tstatR`R_t partitionRtlstriptwalkRHR&R2R4tst_devtremove(RRtflisttst2Rjtroottdirstfilestrmlisttdir_namet dir_full_pathtdir_rel_to_srct dir_removeRtfile_full_pathtfile_rel_to_src((scpio.pytbuild_file_list.s@ &   %       %c Cs |jjd|ƒtjƒ}zØtj|jƒ|dkrj|jdƒ}|jg||jg}n|j||jg}|jjd|ƒ|j sötj ƒ}t j |dt dt|dƒd|d tƒ}||_|jƒd |_nWd tj|ƒXd S( s»Method to transfer the files listed in file_list to the indicated destination. The transfer uses the cpio utility with the arguments specified in cpio_args. sTransferring files in %ss-pdumt sThe command executing is %stshelltstdinR"tstderrt close_fdsN(R+R,R%tgetcwdtchdirRtsplitRSRRttmpfilet subprocesstPopenRR.RARRPR(RR;t cpio_argstcwdtcmdterr_filet cpio_proc((scpio.pyttransfer_filelistzs$      cCs3|jjd|ƒtj||j|jgƒdS(s!Run the executable file specifieds Running %sN(R+R,R‹t check_callRR(Rt file_name((scpio.pyt run_exec_file›scCsµ|jdkr”|j|jƒ}|dkr1dSt|tƒrt|ƒ}xz|D]r}tjj|j |j ƒƒ}tjj |ƒrStjj |ƒ rS|j |j|ƒƒ|j||ƒqSqSWtjƒ\}}x"|D]}tj||dƒqâWtj|ƒ|}ntjƒ\}} tj|ƒy!|j|| ƒtj|ƒWn$tk r|tj| ƒ|} nX|jjd| ƒ| S|jdkr4|j|jƒ} |jjdƒt| tƒr-tjj| ƒr-g} t| dƒ,} g| jƒD]} | j ƒ^q } WdQX| S| Sn}|jdkrc|jjd ƒ|j|jƒStjtjtj g}x'|D]}|j|ƒ}|r‚|Sq‚Wt!d ƒ‚dS( s|Parse the information in the transfer node to determine the action to perform and the source of the data R!s s File List: %st uninstallsUninstalling dataR"Nt transformsUsing media transforms0CPIO Transfer unable to determine desired action("tactionR\RZRRQRR%R&R2RR3tisdirtislinktpoptindexRttempfiletmkstempRetcloseRmRMR4R+R,RRtisfileR.R1RSRTRURVt Exception(Rttranstfl_datatbflisttitemt directoryt file_descttmp_fileR”t sorted_filetuninstall_datatuninstall_listt file_handletlinet cpio_def_listt def_transferRZ((scpio.pytparse_transfer_node sb          (  cCs‰tjj|jƒs4|js4tj|jƒq4n|jr˜|j|jkrg|j dt ƒ|_nt d|j ƒ|_ |j j|j|jƒnx¼|jD]±}|jtƒd krß|j jd|jtƒƒq¢n|jtƒdkr|js¢|j|jtƒƒq¢q¢n|jtƒdkrl|j jd|jƒ|j|jtƒ|jtƒƒq¢|jtƒdkr¢|j jdƒ|jsSx³|jtƒD]Ÿ}t|d ƒrät|jƒrä|jd t ƒqªntjj|j|jƒƒ}y3tjj|ƒr'tj |ƒn tj!|ƒWqªt"k rHqªXqªWqSq¢q¢W|j r…t#|j _$|j j%ƒd |_ nd S( s5Method to transfer from the source to the destinationR6R+s&Skipping %s action, it has no contentsR—R!sTransferring files to %sR–s(Removing specified files and directoriestdestroyRN(&R%R&R'RRtmakedirsRRR(R>RR R+Rt startmonitorRR*R RR,R R•RFR’R thasattrtcallableR±R2R3R™tshutiltrmtreeRMR4RARORP(RR¢R¥Rl((scpio.pyRIãsN         (t__name__t __module__t__doc__tabctABCMetat __metaclass__RSt DEF_CPIO_ARGSR@R(RRAR>RCRERRKRHtabstractmethodR#R5RJR)R\RmRR’R•R°RI(((scpio.pyR3s.   B       $  L !  Ct TransferCPIOcBs)eZdZdZd„Zed„ZRS(s2CPIO transfer class which takes input from the DOCt,cCsƒtt|ƒj|ƒtƒ|_tjƒj|_|jj d|j dt ƒ|_ t |j ƒdkrtd|j ƒ‚ndS(NRt class_typeis>Only one value for Software node can be specified with name %s(RRÀRRRRt get_instancetdata_object_cacheRtget_descendantsRRt soft_listtlenR$(RR((scpio.pyR)s  c Cs%|jjdƒ|jd}|jtjtƒ}|jj|djtj tƒdj ƒ|_ |jt j t ƒ}|jj|djtj tƒdj ƒ|_tjj|jƒsÏtd|jƒ‚ntj|jtjƒsütd|jƒ‚n|jdtƒ}x|D]}tƒ}|jdtjdtƒ}|rªt|ƒdkrp|jƒtdƒ‚q·y|djd |ts*      "ÿóT