Ñò i'dWc@sVdZddkZddkZddkZddkZddkZddkZddklZddk l Z ddk l Z ddklZddklZddklZdd klZdd klZdd klZdd klZlZlZlZdd klZde 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×eZdZeiZdZdZdZdZ d„Z e d„Z d„Z d„Zed „Zd „Zeid „ƒZd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s%Subclass for transfer CPIO checkpoints /usr/bin/cpios-pdumi iècCswtt|ƒi|ƒ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((s ../cpio.pyR=s         c CsÕ|oZy|idtƒWqatj o3|iotii|iƒ o|iS‚qaXn|iƒd}x2|i D]'}|i t ƒdjo |i t ƒ}|dj o'|iid|ƒ|t|ƒ7}q¢|}|i tƒ}t|dƒiiƒ}zy|~}yV|tttg} |iƒD]%} | tii|i| iƒƒq5~ ƒƒ}Wntj onXWdQX|iid||ƒq{q{W|o|iƒ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 topent__exit__t __enter__tsumtmapRt readlinestjointrstriptOSErrort_cleanup_tmp_filesR( Rtneed_parse_inputtsizettransfert pre_calc_sizetold_sizet file_listt_[1]t filehandlet_[2]tf((s ../cpio.pytget_size[sD !     & C    cCsU|iƒ|_|iid|iƒtt|iƒ|i|iƒ}t|_ |S(saReturns an estimate of the time this checkpoint will take given the DOC input sDistro size: %d KB( RBRR+R,R-tfloatR(tDEFAULT_PROG_ESTtTrueR(Rtprogress_estimate((s ../cpio.pytget_progress_estimates   cCs(t|_|io|iiƒndS(sCancel the transfer in progressN(RERRtkill(R((s ../cpio.pytcancel¬s  cCs|iid|iƒ|io|iiddƒn||_z,|iƒ|iƒ|iƒ|i ƒWd|i ƒ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((s ../cpio.pytexecute²s     cCs|io|iƒ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(RRN(R((s ../cpio.pyRLÉs cCs t‚dS(s;This method is required to be implemented by all subclassesN(tNotImplementedError(R((s ../cpio.pyR#ÐscCsŸy…x~|iD]s}|itƒdjoW|itƒ}|dj o7tii|ƒo$|ii d|ƒti |ƒq€q q WWnt j onXdS(s/Remove the tmp files we created from the systemR!sRemoving temp content file: %sN( RR*R R RR%R&R'R+R,tunlinkR6(RR:t content_file((s ../cpio.pyR7Õs   cCs>|io&t|i_|iiƒd|_n|iƒdS(s.Method to perform any necessary cleanup neededN(RREtdonetwaitRR7(R((s ../cpio.pyRNãs     cCs>|iidƒ|idjo|iƒtdƒ‚ndS(s'Method to validate the local attributessValidating CPIO inputs"CPIO destination must be specifiedN(R+R,RRR7R$(R((s ../cpio.pyR)ìs cCs|iidƒ|oít|tƒo|St|tƒoÄtititig}||jo>t i t i i |i |ƒt iƒ o|iidƒdSt i i|ƒpt i i |i |ƒ}nt i |t iƒptd|ƒ‚n|Sqn|iidƒ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&R4RtR_OKRtisabsR$(Rtcontentstcpio_install_types((s ../cpio.pytvalidate_contentsôs*   c CsHg}t|dƒiiƒ}z¦|~}x–|iƒD]ˆ}|iƒ}y;titii|i |ƒƒ}|i |i |fƒWq9t j o,}|i id|ƒ|i i|ƒq9Xq9WWdQX|idtidƒƒt|dƒiiƒ} zA| ~ }x1ttidƒ|ƒD]} |i| 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.R/R0R3R5R%tlstatR&R4Rtappendtst_inoR6R+R,tsorttoperatort itemgetterR2twrite( Rtinfiletoutfilet tmp_flistR>R?tfnametst1tmsgR@tentry((s ../cpio.pyt sort_by_inodes"&  ! &c Cs!|iidƒti|ƒ}d|jo|idƒn|iid|ƒti|ƒ}|i|i|iƒdidƒƒx•ti |ƒD]„\}}}|i ƒg}xÊ|D]Â} ti i || ƒ} ti i |i|iƒdidƒ| ƒ} ti| ƒ}|i| ƒyti| ƒ}Wn#t j o|i| ƒq»nX|i|ijo|i| ƒq»q»Wx|D]} |i| ƒqˆWxw|D]o} |i ƒti i || ƒ}ti i |i|iƒdidƒ| ƒ}ti|ƒ}|i|ƒ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%tstatRdRct partitionRtlstriptwalkRLR&R4R6tst_devtremove(RRtflisttst2Rntroottdirstfilestrmlisttdir_namet dir_full_pathtdir_rel_to_srct dir_removeRtfile_full_pathtfile_rel_to_src((s ../cpio.pytbuild_file_list.sH &  %    %c Cs|iid|ƒtiƒ}zÜti|iƒ|djo-|idƒ}|ig||ig}n|i||ig}|iid|ƒ|i p\ti ƒ}t i |dt dt|dƒd|d tƒ}||_|iƒd |_nWd ti|ƒ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%tgetcwdtchdirRtsplitRWRRttmpfilet subprocesstPopenRR.RERRTR(RR=t cpio_argstcwdtcmdterr_filet cpio_proc((s ../cpio.pyttransfer_filelistzs$      cCs3|iid|ƒti||i|igƒdS(s!Run the executable file specifieds Running %sN(R+R,Rt check_callRR(Rt file_name((s ../cpio.pyt run_exec_file›sc Cså|idjo|i|iƒ}|djodSt|tƒoÚt|ƒ}x}|D]u}tii|i |i ƒƒ}tii |ƒo>tii |ƒ o*|i |i|ƒƒ|i||ƒqWqWWtiƒ\}}x"|D]}ti||dƒqéWti|ƒ|}ntiƒ\}} ti|ƒy!|i|| ƒti|ƒWn&tj oti| ƒ|} nX|iid| ƒ| S|idjo±|i|iƒ} |iidƒt| tƒowtii| ƒodg} t| dƒiiƒ} z:| ~ } g}| iƒD]}||i ƒq1~} WdQX| S| Sn‚|idjo!|iid ƒ|i|iƒSti ti!ti"g}x)|D]!}|i|ƒ}|o|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`R^RRURR%R&R4RR5tisdirtislinktpoptindexR…ttempfiletmkstempRitcloseRqRQR6R+R,RVtisfileR.R/R0R3RWRXRYRZt Exception(Rttranstfl_datatbflisttitemt directoryt file_descttmp_fileR˜t sorted_filetuninstall_datatuninstall_listR>t file_handleR@tlinet cpio_def_listt def_transferR^((s ../cpio.pytparse_transfer_node sh       &,  cCs¦tii|iƒp"|ipti|iƒq8n|io^|i|ijo|i dt ƒ|_nt d|i ƒ|_ |i i|i|iƒnxÏ|iD]Ä}|itƒd jo#|i id|itƒƒqªn|itƒdjo+|ip|i|itƒƒqªqªn|itƒdjo<|i id|iƒ|i|itƒ|itƒƒqª|itƒdjoÜ|i idƒ|ip¾x»|itƒD]¦}t|d ƒo't|iƒo|id t ƒq¼ntii|i|iƒƒ}y5tii|ƒoti |ƒnti!|ƒWq¼t"j oq¼Xq¼WqnqªqªW|i o&t#|i _$|i i%ƒd |_ nd S( s5Method to transfer from the source to the destinationR8R+s&Skipping %s action, it has no contentsR›R!sTransferring files to %sRšs(Removing specified files and directoriestdestroyRN(&R%R&R'RRtmakedirsRRR(RBRR R+Rt startmonitorRR*R RR,R R™RJR–R thasattrtcallableRµR4R5RtshutiltrmtreeRQR6RERSRT(RR¦R©Rp((s ../cpio.pyRMãsR          (t__name__t __module__t__doc__tabctABCMetat __metaclass__RWt DEF_CPIO_ARGSRDR(RRERBRGRIRRORLtabstractmethodR#R7RNR)R`RqR…R–R™R´RM(((s ../cpio.pyR3s.   B       $  L !  Ct TransferCPIOcBs)eZdZdZd„Zed„ZRS(s2CPIO transfer class which takes input from the DOCt,cCs…tt|ƒi|ƒtƒ|_tiƒi|_|ii d|i dt ƒ|_ t |i ƒdjotd|i ƒ‚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((s ../cpio.pyR)s  c Cs2|iidƒ|id}|ititƒ}|ii|diti tƒdi ƒ|_ |it i t ƒ}|ii|diti tƒdi ƒ|_tii|iƒptd|iƒ‚nti|itiƒptd|iƒ‚n|idtƒ}x|D]}tƒ}|idtidtƒ}|ojt|ƒdjo|iƒtdƒ‚qÁy|did |ts*      "ÿóT