2Kc@s9dZddlZddlZddlZddlZddlZddljZdZ dZ dZ dZ dZ dZd Zd Zd Zd efd YZdefdYZdefdYZdefdYZdefdYZdfdYZdfdYZdefdYZdefdYZdefdYZd fd!YZd"Ze d#kr5eej!d$GHej"ej!d$Z#d%Ge#GHxye#D]qZ$d&Ge$GHd'Ge%e$j&GHd(Ge$j'GHd)Ge$j(GHd*Ge$j)Gd+ej*e$j)GHd,Ge$j+GHd-Ge$j,GHqWndS(.s-Read from and write to cpio format archives. iNiqiqiqiqt070701t070707t070702iit CpioErrorcBseZdZRS(sBase exception.(t__name__t __module__t__doc__(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR;st ExtractErrorcBseZdZRS(s%General exception for extract errors.(RRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR>st ReadErrorcBseZdZRS(s&Exception for unreadble cpio archives.(RRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRAstCompressionErrorcBseZdZRS(s.Exception for unavailable compression methods.(RRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR Dst StreamErrorcBseZdZRS(s>Exception for unsupported operations on stream-like CpioFiles.(RRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR Gst _LowLevelFilecBs2eZdZdZdZdZdZRS(sLow-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. cCsditjd6tjtjBtjBd6|}ttdrK|tjO}ntj|||_dS(NtrtwtO_BINARY( tostO_RDONLYtO_WRONLYtO_CREATtO_TRUNCthasattrRtopentfd(tselftnametmode((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt__init__Ts cCstj|jdS(N(RtcloseR(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR]scCstj|j|S(N(RtreadR(Rtsize((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR`scCstj|j|dS(N(RtwriteR(Rts((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRcs(RRRRRRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR Ns   t_StreamcBseZdZdZdZdZdZdZdZdZ dZ d d Z dd Z d Zd ZRS(sClass that serves as an adapter between CpioFile and a stream-like object. The stream-like object only needs to have a read() or write() method and is accessed blockwise. Use of gzip or bzip2 compression is possible. A stream-like object could be for example: sys.stdin, sys.stdout, a socket, a tape device etc. _Stream is intended to be used only internally. cCsnt|_|dkr0t||}t|_n|p9d|_||_||_||_||_ d|_ d|_ t|_ |dkryddl }Wntk rtdnX||_ |jd|_|dkr|jq|jn|dkrjyddl}Wntk r0td nX|dkrXd|_|j|_qj|j|_ndS( s,Construct a _Stream object. tltgziNszlib module is not availableR tbz2sbz2 module is not available(tTruet _extfileobjtNoneR tFalseRRttypetfileobjtbufsizetbuftpostclosedtzlibt ImportErrorR tcrc32tcrct _init_read_gzt_init_write_gzR#tdbuftBZ2Decompressortcmpt BZ2Compressor(RRRR(R)R*R.R#((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRqs>                      cCs|js|jndS(N(R-R(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt__del__s cCs|jjd|jj|jj |jjd|_tjdtt j }|j d||j j dr|j d |_ n|j |j t dS(s>Initialize for writing with gzip compression. i isR1R,R%RR$(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs   cCsm|jj|jj |_d|_|jddkrFtdn|jddkrgtdnt|jd}|jd|d @rt|jdd t|jd}|j |n|d @rx3t r |jd}| s|t krPqqWn|d @rOx3t rK|jd}| sD|t krPqqWn|d@ri|j dnd S(sBInitialize for reading a gzip compressed fileobj. R!issnot a gzip fileissunsupported compression methodiiiiiN( R.t decompressobjR;R6R4t _Stream__readRR tordRR$RCt_read(RtflagtxlenR((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR2s.     ,       cCs|jS(s;Return the stream's file pointer position. (R,(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyttellsicCsy||jdkrit||j|j\}}x$t|D]}|j|jq?W|j|n td|jS(seSet the stream's file pointer to pos. Negative seeking is forbidden. is seeking backwards is not allowed(R,tdivmodR*txrangeRR (RR,tblockst remainderti((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytseeks cCs|dkrZg}x3trG|j|j}|s7Pn|j|qWdj|}n|j|}|jt|7_|S(sReturn the next size number of bytes from the stream. If size is not defined, return all bytes of the stream up to EOF. R!N(R&R$RMR*tappendtjoinR,RF(RRttR+((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs  cCs|jdkr|j|St|j}|jg}x[||kr|j|j}|sbPn|jj|}|j||t|7}q:Wdj|}|||_|| S(s3Return size bytes from the stream. RER!( R(RKRFR4R*R6t decompressRWRX(RRtcRYR+((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRMs    cCst|j}|jg}xL||kri|jj|j}|sIPn|j||t|7}qWdj|}|||_|| S(sReturn size bytes from stream. If internal buffer is empty, read another block from the stream. R!(RFR+R)RR*RWRX(RRR[RYR+((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt__read's   N(RRRRR8R3RRARR2RPRVR&RRMRK(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR fs  (      t ExFileObjectcBsVeZdZdZd dZddZdZdZddZ d Z RS( sjFile-like object for reading an archive member. Is returned by CpioFile.extractfile(). cCsX|j|_|j|_d|_t|_|j|_|j|_d|_d|_ dS(NR lR!( R)RRR'R-t offset_datatoffsetRR,t linebuffer(Rtcpiofiletcpioinfo((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR@s       cCs|jrtdn|jj|j|j|j|j}|dkrT|}nt||}|j|7_|jj |S(Nsfile is closed( R-t ValueErrorR)RVR_R,RR&tminR(RRt bytesleftt bytestoread((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRJs    icCs9|dkrtj}n|jjd}|dkrHt||}n|t|j8}xo|dkr|dkr|jt|d}|sPn|j|7_|t|8}|jjd}q^W|dkr|j}d|_|S|j| }|j|d|_x|ddkr0|d }qW|dS(sRead a line with approx. size. If size is negative, read a whole line. readline() and read() must not be mixed up (!). is idiR!is (tsystmaxintR`tfindRdRFR(RRtnlR+R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytreadlineVs,       cCs:g}x-tr5|j}|s%Pn|j|q W|S(s:Return a list with all (following) lines. (R$RkRW(Rtresulttline((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt readlinests  cCs|jS(s2Return the current file position. (R,(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRP~sicCsd|_|dkr6tt|d|j|_n|dkr|dkrjt|j|d|_qt|j||j|_n4|dkrtt|j||jd|_ndS(s0Seek to a position in the file. R!iiiN(R`RdtmaxRR,(RR,twhence((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRVs  !   cCs t|_dS(s'Close the file object. N(R$R-(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRsN( RRRRR&RRkRnRPRVR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR];s   tCpioInfocBsJeZdZdddZdZeddZdZdZ RS(sInformational class which holds the details about an archive member given by a cpio header block. CpioInfo objects are returned by CpioFile.getmember(), CpioFile.getmembers() and CpioFile.getcpioinfo() and are usually created internally. R!cCs||_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ ||_d|_d|_d|_dS( sfConstruct a CpioInfo object. name is the optional name of the member. iit0R!tusertgroupiN(RRtuidtgidRtmtimetchksumR(tlinknametunametgnametdevmajortdevminortprefixRaR_R^tpadding(RRRa((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs$                 cCs d|jj|jt|fS(Ns<%s %r at %#x>(t __class__RRtid(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt__repr__sc Cs;|d|}|d tkr(d}n|d tkrAd}n|d tkrZd}nwtjd|d d}|tkrd }nH|tkrd }n3|tkrd }n|tkrd }n t d |d kr||j dt |7}tjd|d \ }}} |_ |_ |_} } |_} |_||j | 7}|dd| d!|_d|_d| | d|_||j | d7}n|dkr.||j dt |7}t|dd!d|_ t|dd!d|_ t|dd!d|_t|dd!d|_t|dd!d|_t|dd!d|_t|dd!d|_t|dd!d} t|dd!d|_||j | 7}|dd| d!|_d| |_|jd|jddd7_||j |jd| 7}d|_n t d|S( sConstruct a CpioInfo object from a buffer. The buffer should be at least 6 octets long to determine the type of archive. The rest of the data will be read in on demand. RaitCMS_ASCtCMS_CHRtCMS_CRCthiitCMN_ASCtCMN_BINtCMN_BBStCMN_CRCsinvalid cpio headeris =hhHHHHhhihiiiniiiii&i.i6i>iFiNi^ifisunsupported cpio header(RRRR=tunpackRRRRRcRRFRRuRvRwRRRthdrsizetintR|R}Rx( tclsR+R)RaRbthdrtypetbtmagictdevtinodetnlinktrdevtnamesize((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytfrombufsX             F   "  cCstj|jS(N(tstattS_ISREGR(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytisregscCs$|jrt|j|SdSdS(sUReturn a file-like object which can be read to extract the contents. N(RR]RaR&(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt extractfiles N( RRRR&RRt classmethodRRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRqs = tCpioFilecBs/eZdZeZdddddZedddddZedddZ eddddZ edddd Z eddd Z id d 6d d6dd6dd6Z dZdZdZdZdZddZdZddZdZddZddZRS( sCThe CpioFile Class provides an interface to cpio archives. R cCs||_t|dks'|dkr3tdn||_idd6dd6dd 6||_| r| rt|j|j}t|_no|r|j}d |_ n|jdkrt |d r|j|_nt |d r|j|_nt |_||_t|_ g|_t|_d |_|jdkrSd|_|j|_n|jdkrd|_xft ry|j}Wn"tk r|jjd PnX|dkrn|jjt dPqnqnWn|jdkrt |_ndS(sOpen an (uncompressed) cpio archive `name'. `mode' is either 'r' to read from an existing archive, 'a' to append data to an existing file or 'w' to create a new file overwriting an existing one. `mode' defaults to 'r'. If `fileobj' is given, it is used for reading or writing data. If it can be determined, `mode' is overridden by `fileobj's mode. `fileobj' is not closed, when CpioFile is closed. itrawsmode must be 'r', 'a' or 'w'trbR sr+btatwbR iRRltawN(RRFRct_modeRtfileR'R%R)R,R&RR$R-tmemberst_loadedR_t firstmembertnextRRVt BLOCKSIZE(RRRR)tcfobjRb((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRsJ   "               iic Cs| r| rtdnd|kr|jdd\}}|pGd}|pSd}||jkr~t||j|}n td|||||Sd|kr |jdd\}}|pd}|pd}|dkrtd n|||t|||||}t|_|S|dkrxX|jD]M}t||j|}y||d|SWq6ttfk rq6q6Xq6Wtd n|d kr|j |||Std d S(sOpen a cpio archive for reading, writing or appending. Return an appropriate CpioFile class. mode: 'r' open for reading with transparent compression 'r:' open for reading exclusively uncompressed 'r:gz' open for reading with gzip compression 'r:bz2' open for reading with bzip2 compression 'a' or 'a:' open for appending 'w' or 'w:' open for writing without compression 'w:gz' open for writing with gzip compression 'w:bz2' open for writing with bzip2 compression 'r|' open an uncompressed stream of cpio blocks for reading 'r|gz' open a gzip compressed stream of cpio blocks 'r|bz2' open a bzip2 compressed stream of cpio blocks 'w|' open an uncompressed stream for writing 'w|gz' open a gzip compressed stream for writing 'w|bz2' open a bzip2 compressed stream for writing snothing to opent:iR REsunknown compression type %rt|trwsmode must be 'r' or 'w's%file could not be opened successfullyRsundiscernible modeN( Rctsplitt OPEN_METHtgetattrR R R'R%Rtcpioopen( RRRR)R*tfilemodetcomptypetfuncRY((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRXs>                cCs:t|dks|dkr*tdn||||S(sLOpen uncompressed cpio archive name for reading or writing. iRsmode must be 'r', 'a' or 'w'(RFRc(RRRR)((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs i c Cs9t|dks|dkr*tdnyddl}|jWn ttfk rctdnXtjj |\}}tjj |}|dkrd}n||}|dkrt ||d }n|d krt }ny+|j|||j||||} Wntk r+td nXt| _| S( syOpen gzip compressed cpio archive name for reading or writing. Appending is not allowed. iRsmode must be 'r' or 'w'iNsgzip module is not availables.gzR!RR snot a gzip file(RFRctgziptGzipFileR/tAttributeErrorR RtpathtsplitexttbasenameR&RttarnameRtIOErrorRR'R%( RRRR)t compresslevelRtpretexttcpionameRY((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytgzopens0              c Cs t|dks|dkr*tdnyddl}Wntk rVtdnXtjj|\}}tjj|}|dkrd}n||}|dk rtd ny+|j |||j ||d |} Wnt k rt d nXt| _| S( szOpen bzip2 compressed cpio archive name for reading or writing. Appending is not allowed. iRsmode must be 'r' or 'w'.iNsbz2 module is not availables.bz2R!s$no support for external file objectsRsnot a bzip2 file(RFRcR#R/R RRRRR&RtBZ2FileRRR'R%( RRRR)RR#RRRRY((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytbz2opens(            cCsbt|dks|dkr*tdntjj|\}}tjj|}|dkrid}n||}ydidd6d d 6|id d6d d 6||f}tj|jd tj dtj dtj }|j } |d kr|j } nd} d} t ||| | | } |j ||| } Wntk rTtdnXt| _| S(sOpen 7z compressed cpio archive name for reading, writing. Appending is not allowed iRsmode must be 'r' or 'w'.s.7zR!s 7z %s -%s %steR RR tsotsitstdintstdouttstderrREiisread/write via 7z failedi((RFRcRRRRt subprocesstPopenRtPIPERRR RRRR'R%(RRRR)RRRtcmdtptpobjRR*tobjRY((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytp7zopens6              RRERR"RR#Rtp7zcCs/|j|}|dkr+td|n|S(sReturn a CpioInfo object for member `name'. If `name' can not be found in the archive, KeyError is raised. If a member occurs more than once in the archive, its last occurence is assumed to be the most up-to-date version. sfilename %r not foundN(t _getmemberR&tKeyError(RRRb((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt getmembers cCs'|j|js |jn|jS(sReturn the members of the archive as a list of CpioInfo objects. The list has the same order as the members in the archive. (t_checkRt_loadR(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt getmemberss   cCss|jd|jdk r2|j}d|_|S|jj|jxutr|jjd}|sjdSytj ||j|}Wn/t k r}|jdkrt dndSXPqHW|j|_|j|j |_ |js|jdkrL|j|j |j7_|j|jdkrL|j|j|j|j7_qLn|jdkr_dS|jj||S(Ntraiis$empty, unreadable or compressed files TRAILER!!!(i(RRR&R)RVR_R$RRqRRcRRR^RR(RRRRRW(RtmR+RbR((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR(s8       cCsX|jdt|tr%|}n|j|}|jrP|j||SdSdS(NR (Rt isinstanceRqRRt fileobjectR&(RtmemberRb((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRQs   cCs0t|t\}}|r(|d7}n|tS(Ni(RQR(RtcountRSRT((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt_block_s cCsv|j}|dkr't|}n|j|}x9t|dddD]!}|||jkrM||SqMWdS(Nii(RR&RFtindexRRR(RRRbRtendRU((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRes  cCs6x&tr(|j}|dkrPqqWt|_dS(N(R$RR&R(RRb((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRqs    cCsQ|jrtd|jjn|dk rM|j|krMtd|jndS(Ns %s is closedsbad operation for mode %r(R-RRRR&R(RR((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRxs cCs$|jrt|jSt|SdS(N(RtiterRtCpioIter(R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt__iter__~s  cCsid}|jj|dkr9||jj|}n|jj|jj||j|7_dS(s Find the next cpio archive glommed on to the end of the current one. Some applications, like Solaris package datastreams, concatenate multiple cpio archives together, separated by a bit of padding. This routine puts all the file pointers in position to start reading from the next archive, which can be done by creating a new CpioFile object given the original one as an argument (after this routine is called). iN(R)RPRVR_(RRtbytes((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytfind_next_archives cCs|j|td|S(sReturn the next cpio archive glommed on to the end of the current one. Return the CpioFile object based on the repositioning done by find_next_archive(). R(RR(RR((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytget_next_archives Ni((RRRR]RR&RRRRRRRRRRRRRRRRRRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyR s:GA"(  )      RcBs#eZdZdZdZRS(cCs||_d|_dS(Ni(RaR(RRa((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs cCs|S(N((R((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRscCs}|jjs9|jj}|sjt|j_tqjn1y|jj|j}Wntk ritnX|jd7_|S(Ni(RaRRR$t StopIterationRRt IndexError(RRb((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs     (RRRRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyRs  cCsbt|jt}|tttfkr.tStjd|d dt t t t fkr^tSt S(NRii(RRtCMS_LENRRRR$R=RRRRRR'(RR((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pyt is_cpiofilest__main__is cpiofile is:s cpioinfo is:s mode:s uid:s gid:s mtime:s(%s)s size:s name:(-RRgRRR@R=tpkg.pkgsubprocesst pkgsubprocessRRRRRRRRRRt ExceptionRRRR R R R tobjectR]RqRRRRtargvRtcftcitoctRRuRvRwtctimeRR(((s2/usr/lib/python2.7/vendor-packages/pkg/cpiofile.pytsP     _q