2Kc @s;dZddkZddkZddkZddkZddkZddkiZdZ dZ dZ dZ dZ dZd Zd Zd Zd efd YZdefdYZdefdYZdefdYZdefdYZdfdYZdfdYZdefdYZdefdYZdefdYZd fd!YZd"Ze d#joeei!d$GHei"ei!d$Z#d%Ge#GHxye#D]qZ$d&Ge$GHd'Ge%e$i&GHd(Ge$i'GHd)Ge$i(GHd*Ge$i)Gd+ei*e$i)GHd,Ge$i+GHd-Ge$i,GHqWndS(.s-Read from and write to cpio format archives. iNiqiqiqiqt070701t070707t070702iit CpioErrorcBseZdZRS(sBase exception.(t__name__t __module__t__doc__(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR;st ExtractErrorcBseZdZRS(s%General exception for extract errors.(RRR(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR>st ReadErrorcBseZdZRS(s&Exception for unreadble cpio archives.(RRR(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRAstCompressionErrorcBseZdZRS(s.Exception for unavailable compression methods.(RRR(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR Dst StreamErrorcBseZdZRS(s>Exception for unsupported operations on stream-like CpioFiles.(RRR(((s2/usr/lib/python2.6/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. cCsfhtid6titiBtiBd6|}ttdo|tiO}nti|||_dS(NtrtwtO_BINARY( tostO_RDONLYtO_WRONLYtO_CREATtO_TRUNCthasattrRtopentfd(tselftnametmode((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt__init__Ts cCsti|idS(N(RtcloseR(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR]scCsti|i|S(N(RtreadR(Rtsize((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR`scCsti|i|dS(N(RtwriteR(Rts((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRcs(RRRRRRR(((s2/usr/lib/python2.6/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. c Cs}t|_|djot||}t|_n|pd|_||_||_||_||_ d|_ d|_ t|_ |djosyddk }Wntj otdnX||_ |id|_|djo|iq|in|djokyddk}Wntj otd nX|djod|_|i|_qy|i|_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.6/vendor-packages/pkg/cpiofile.pyRqs>                cCs|ip|indS(N(R-R(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt__del__s cCs|iid|ii|ii |iid|_tidtt i }|i d||i i do|i d |_ n|i |i t dS(s>Initialize for writing with gzip compression. i isR1R,R%RR$(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRs    cCs|ii|ii |_d|_|iddjo tdn|iddjo tdnt|id}|id|d @o=t|idd t|id}|i |n|d @o<x9t o-|id}| p |t joPqqWn|d @o<x9t o-|id}| p |t joPq*q*Wn|d@o|i 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.6/vendor-packages/pkg/cpiofile.pyR2s2     ,   cCs|iS(s;Return the stream's file pointer position. (R,(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyttellsicCs{||idjoWt||i|i\}}x$t|D]}|i|iq@W|i|n td|iS(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.6/vendor-packages/pkg/cpiofile.pytseeks  cCs|djoSg}x7to/|i|i}|pPn|i|qWdi|}n|i|}|it|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.6/vendor-packages/pkg/cpiofile.pyRs cCs|idjo|i|St|i}|ig}x_||joQ|i|i}|pPn|ii|}|i||t|7}q<Wdi|}|||_|| S(s3Return size bytes from the stream. RER!( R(RKRFR4R*R6t decompressRWRX(RRtcRYR+((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRMs    cCst|i}|ig}xP||joB|ii|i}|pPn|i||t|7}qWdi|}|||_|| 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.6/vendor-packages/pkg/cpiofile.pyt__read's    N(RRRRR8R3RRARR2RPRVR&RRMRK(((s2/usr/lib/python2.6/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|i|_|i|_d|_t|_|i|_|i|_d|_d|_ dS(NR lR!( R)RRR'R-t offset_datatoffsetRR,t linebuffer(Rtcpiofiletcpioinfo((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR@s       cCs|io tdn|ii|i|i|i|i}|djo |}nt||}|i|7_|ii |S(Nsfile is closed( R-t ValueErrorR)RVR_R,RR&tminR(RRt bytesleftt bytestoread((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRJs    icCsF|djo ti}n|iid}|djot||}n|t|i8}xt|djof|djoY|it|d}|pPn|i|7_|t|8}|iid}qbW|djo|i}d|_|S|i| }|i|d|_x |ddjo|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.6/vendor-packages/pkg/cpiofile.pytreadlineVs0       cCs>g}x1to)|i}|pPn|i|q W|S(s:Return a list with all (following) lines. (R$RkRW(Rtresulttline((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt readlinests cCs|iS(s2Return the current file position. (R,(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRP~sicCsd|_|djo"tt|d|i|_n|djoJ|djot|i|d|_qt|i||i|_n7|djo)tt|i||id|_ndS(s0Seek to a position in the file. R!iiiN(R`RdtmaxRR,(RR,twhence((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRVs  "    cCs t|_dS(s'Close the file object. N(R$R-(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRsN( RRRRR&RRkRnRPRVR(((s2/usr/lib/python2.6/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.6/vendor-packages/pkg/cpiofile.pyRs$                 cCs d|ii|it|fS(Ns<%s %r at %#x>(t __class__RRtid(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt__repr__sc CsM|d|}|d tjo d}n|d tjo d}n|d tjo d}ntid|d d}|tjo d }nO|tjo d }n8|tjo d }n!|tjo d }n t d |d jo||i dt |7}tid|d \ }}} |_ |_ |_} } |_} |_||i | 7}|dd| d!|_d|_d| | d|_||i | d7}n|djo||i 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|_||i | 7}|dd| d!|_d| |_|id|iddd7_||i |id| 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.6/vendor-packages/pkg/cpiofile.pytfrombufsX             F   "  cCsti|iS(N(tstattS_ISREGR(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pytisregscCs&|iot|i|SdSdS(sUReturn a file-like object which can be read to extract the contents. N(RR]RaR&(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt extractfiles N( RRRR&RRt classmethodRRR(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRqs = tCpioFilecBs/eZdZeZdddddZedddddZedddZ eddddZ edddd Z eddd Z hd d 6d d6dd6dd6Z dZdZdZdZdZddZdZddZdZddZddZRS( sCThe CpioFile Class provides an interface to cpio archives. R cCs ||_t|djp |djo tdn||_hdd6dd6dd 6||_| o*| o"t|i|i}t|_nw|o|i}d |_ n|idjo t |d o|i|_nt |d o|i|_nt |_||_t|_ g|_t|_d |_|idjod|_|i|_n|idjoyd|_xmt oay|i}Wn$tj o|iid PnX|djo|iit dPq~q~Wn|idjo t |_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.6/vendor-packages/pkg/cpiofile.pyRsL    "             iic Cs| o| o tdnd|joz|idd\}}|pd}|pd}||ijot||i|}ntd|||||Sd|jo~|idd\}}|pd}|pd}|djo td n|||t|||||}t|_|S|djojxZ|iD]O}t||i|}y||d|SWqFttfj o qFqFXqFWtd n"|d jo|i |||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.6/vendor-packages/pkg/cpiofile.pyRXs@                 cCs=t|djp |djo tdn||||S(sLOpen uncompressed cpio archive name for reading or writing. iRsmode must be 'r', 'a' or 'w'(RFRc(RRRR)((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRs  i c CsFt|djp |djo tdnyddk}|iWn"ttfj otdnXtii |\}}tii |}|djo d}n||}|djot ||d }n|d jo t }ny+|i|||i||||} Wntj otd 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.6/vendor-packages/pkg/cpiofile.pytgzopens0            c Cst|djp |djo tdnyddk}Wntj otdnXtii|\}}tii|}|djo d}n||}|dj o td ny+|i |||i ||d |} Wnt j ot 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.6/vendor-packages/pkg/cpiofile.pytbz2opens(         c Cskt|djp |djo tdntii|\}}tii|}|djo d}n||}ydhdd6d d 6|hd d6d d 6||f}ti|id ti dti dti }|i } |d jo |i } nd} d} t ||| | | } |i ||| } Wntj otdnXt| _| 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.6/vendor-packages/pkg/cpiofile.pytp7zopens6             RRERR"RR#Rtp7zcCs1|i|}|djotd|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.6/vendor-packages/pkg/cpiofile.pyt getmembers cCs)|i|ip|in|iS(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.6/vendor-packages/pkg/cpiofile.pyt getmemberss  cCs|id|idj o|i}d|_|S|ii|ix}tou|iid}|pdSyti ||i|}Wn3t j o'}|idjo t dndSXPqJW|i|_|i|i |_ |ip|idjoX|i|i |i7_|i|idjo$|i|i|i|i7_q[n|idjodS|ii||S(Ntraiis$empty, unreadable or compressed files TRAILER!!!(i(RRR&R)RVR_R$RRqRRcRRR^RR(RRRRRW(RtmR+RbR((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR(s:      cCs\|idt|to |}n|i|}|io|i||SdSdS(NR (Rt isinstanceRqRRt fileobjectR&(RtmemberRb((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRQs   cCs2t|t\}}|o|d7}n|tS(Ni(RQR(RtcountRSRT((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt_block_scCsz|i}|djot|}n|i|}x;t|dddD]#}|||ijo ||SqOWdS(Nii(RR&RFtindexRRR(RRRbRtendRU((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRes  cCs:x*to"|i}|djoPqqWt|_dS(N(R$RR&R(RRb((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRqs    cCsV|iotd|iin|dj o$|i|jotd|indS(Ns %s is closedsbad operation for mode %r(R-RRRR&R(RR((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRxs cCs&|iot|iSt|SdS(N(RtiterRtCpioIter(R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyt__iter__~s cCskd}|ii|djo||ii|}n|ii|ii||i|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.6/vendor-packages/pkg/cpiofile.pytfind_next_archives cCs|i|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.6/vendor-packages/pkg/cpiofile.pytget_next_archives Ni((RRRR]RR&RRRRRRRRRRRRRRRRRRR(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyR s:GA"(  )      RcBs#eZdZdZdZRS(cCs||_d|_dS(Ni(RaR(RRa((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRs cCs|S(N((R((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRscCs|iip0|ii}|pt|i_tqpn4y|ii|i}Wntj o tnX|id7_|S(Ni(RaRRR$t StopIterationRRt IndexError(RRb((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRs   (RRRRR(((s2/usr/lib/python2.6/vendor-packages/pkg/cpiofile.pyRs  cCsft|it}|tttfjotStid|d dt t t t fjotSt S(NRii(RRtCMS_LENRRRR$R=RRRRRR'(RR((s2/usr/lib/python2.6/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.6/vendor-packages/pkg/cpiofile.pytsR     _q