CfcKdZddlZddlZddlZddlZddlZddlmZ ddl m Z m Z m Z m Z mZmZmZmZmZmZmZmZddlmZddlmZmZmZdd lmZdd lm Z d Z!d Z"gd Z#dZ$gdZ%dZ&dZ'dZ(dZ)GddeZ*Gdde+Z,Gdde,Z-Gdde,Z.GddeZ/e0dk(rHe/ejbd Z2e2jfjiZ4e5e4jmdyy#e$r dZesdZYwxYw)!zX Representation of Debian binary package (.deb) files Debfile Classes =============== N)Path) AnyBinaryIODictIOIteratorListOptionalTextTypeVarUnionoverload TYPE_CHECKING)LiteralFcyN)fs 0/usr/lib/python3/dist-packages/debian/debfile.pyr9s)ArFileArErrorArMember) Changelog)Deb822zdata.tarz control.tar)gzbz2xzlzmazstz debian-binary)preinstpostinstprermpostrmconfigcontrolzusr/share/doc/%s/changelog.gzz$usr/share/doc/%s/changelog.Debian.gzmd5sumsc eZdZy)DebErrorN__name__ __module__ __qualname__rrrr*r*Msrr*ceZdZdZdZdZedZdZddZ e ddZ e dd Z dd Z e dd Z e dd Z dd Z dZ dZdZdZy)DebParta'Part' of a .deb binary package. A .deb package is considered as made of 2 parts: a 'data' part (corresponding to the possibly compressed 'data.tar' archive embedded in a .deb) and a 'control' part (the 'control.tar.gz' archive). Each of them is represented by an instance of this class. Each archive should be a compressed tar archive although an uncompressed data.tar is permitted; supported compression formats are: .tar.gz, .tar.bz2, .tar.xz . When referring to file members of the underlying .tar.gz archive, file names can be specified in one of 3 formats "file", "./file", "/file". In all cases the file is considered relative to the root of the archive. For the control part the preferred mechanism is the first one (as in deb.control.get_content('control') ); for the data part the preferred mechanism is the third one (as in deb.data.get_file('/etc/vim/vimrc') ). c ||_d|_yr)_DebPart__member _DebPart__tgz)selfmembers r__init__zDebPart.__init__cs  rcfd}jjj}tjj |ddd}|t vs|tk(s |tk(rE|dk(r |ddg}n j} tj|d_jStd |zjS#tjtjf$r}td |zd}~wwxYw) zReturn a TarFile object corresponding to this part of a .deb package. Despite the name, this method gives access to various kind of compressed tar archives, not only gzipped ones. c ddl}ddl|j||j|jdfd}|jjjd}|jdk7r+t d dj|d |jdtj|S#tt f$r&}t ddj|d|dd}~wwxYw) NrFcPjjjSr)signalSIGPIPESIG_DFL)r:srrz9DebPart.tgz.._custom_decompress..}sMM&..&..Ar)stdinstdoutuniversal_newlines preexec_fnzerror while running command ' z' as subprocess: ''z command 'z' has failed with code ') subprocessr:PopenPIPEOSError ValueErrorr*join communicater2read returncodeioBytesIO) command_listrCprocedatar:r4s @r_custom_decompressz'DebPart.tgz.._custom_decompressqs <!"'' $//*//', B (##DMM$6$6$89!O%/:0FGF!]]FN!(f5!IDJ zzCdJKKzz  ))7+C+CDN"#H1#LMMNsC#C=*C88C=ct|jdd}|jdr|S|jdrd|zSd|zS)zw try (not so hard) to obtain a member file name in a form that is stored in the .tar.gz, i.e. starting with ./ \/z./.)strreplace startswith)fnames r__normalize_memberzDebPart.__normalize_membersOE ""4-   D !L   C ; e|rcj g}|jdddD]}|j|tjj dj |}t j|}|jj|}|js|jjdr(|jjd}|j}|j|d< t jtjj S#t$rYywxYw)z walk the path following symlinks returns: resolved_path, info if the path is not found even after following symlinks within the archive, then None is returned. rgrSN)splitappendrXrYnormpathrHr0_DebPart__normalize_memberrd getmemberissymlinknamerkKeyError)r4rYresolved_path_partspathpartcurrpathtinfos r__resolve_symlinkszDebPart.__resolve_symlinkss "$  JJsOAB/ A#**8477++CHH5H,IJ"55h? ,,X6;;=~~005.3nn.B.B3.G+#(>>38..+B/% A0))"''*:*:8*DEE   sBD&AD&& D21D2ctj|}|jj}||vry|r|j |}|duS||vS)zmCheck if this part contains a given file name. Symlinks within the archive can be followed. TN)r0rsrdgetnames_DebPart__resolve_symlinks)r4rlfollow_symlinksnames fname_reals rhas_filezDebPart.has_filesZ **51 ##% E> 007JT) )~rNcyrrr4rlencodingerrorsrs rget_filezDebPart.get_file rcyrrrs rrzDebPart.get_filerrc2tj|}|r |j|}| td|} |j j |}| td|tj|||S|S#t $r tdwxYw)aReturn a file object corresponding to a given file name. If encoding is given, then the file object will return Unicode data; otherwise, it will return binary data. If follow_symlinks is True, then symlinks within the archive will be followed. zFile not found inside packagerr) r0rsrr*rd extractfilerwrL TextIOWrapper)r4rlrrrrfobjs rrzDebPart.get_files**51 007J!>??E <88:))%0D <:; ;  ##D8FK K  <:; ; t|jtS)z Return the debian/control as a Deb822 (a Debian-specific dict-like class) object. For a string representation of debian/control try .get_content('control') )rr CONTROL_FILErs r debcontrolzDebControl.debcontrolgsd&&|455rNcyrrr4rrs rr(zDebControl.md5sumsqrrcyrrrs rr(zDebControl.md5sumsvrrcx|jtstdtz|jt||}i}d}|d}|j D]O}|j |j dd\}}t|tr|j||<K|||<Q|j|S)a Return a dictionary mapping filenames (of the data part) to md5sums. Fails if the control part does not contain a 'md5sum' file. Keys of the returned dictionary are the left-hand side values of lines in the md5sums member of control.tar.gz, usually file names relative to the file system root (without heading '/' or './'). The returned keys are Unicode objects if an encoding is specified, otherwise binary. The returned values are always Unicode.z('%s' file not found, can't list MD5 sumsrz Ns rS) rMD5_FILEr*r readlinesrstriprp isinstancebytesdecoder) r4rrmd5_filesumsnewlinelinemd5rls rr(zDebControl.md5sums{s}}X&:XEG G==HV=L  G&&( "DW-33D!too many parts in given .deb (was looking for only one of: %s)r) r[r\r]rq intersectionsetr*lenlist)basenameext candidatesparts actual_namess rcompressed_part_namez.DebFile.__init__..compressed_part_names?HIXs3IJIIy11!!(+ --c*o>E-/9:;;5zA~9;EFGG;q> !JsB z4missing required part in given .deb (expected: '%s'))rr6rr~ INFO_PARTr*_DebFile__partsrrtr]rr\_DebFile__pkgnamerJstrip_DebFile__versionr)r4filenamerVrUrrrs @rr6zDebFile.__init__shg64==?+  "& L ($&/01 1 ",T^^  +.-#. Y")$..  ++-#. Y NN9 %)  rc4|jd|_y)Npackage)rrrs r__updatePkgNamezDebFile.__updatePkgNames*95rc|jSr)rrs rversionzDebFile.versions~~rc(|jtSr)rr\rs rrQz DebFile.data||I&&rc(|jtSr)rr]rs rr'zDebFile.controlrrc6|jjS)z See .control.debcontrol() )r'rrs rrzDebFile.debcontrols||&&((rc6|jjS)z See .control.scripts() )r'rrs rrzDebFile.scriptss||##%%rcyrrrs rr(zDebFile.md5sumsrrcyrrrs rr(zDebFile.md5sumsrrc<|jj||S)z See .control.md5sums() r)r'r(rs rr(zDebFile.md5sumss||##Xf#EErcz|j|jt|jzt|jzfD][} |jj |d}tj|5}|j}dddtcSy#t $rYjwxYw#1swY'xYw)z Return a Changelog object for the changelog.Debian.gz of the present .deb package. Return None if no changelog can be found. NT)r)rU) r_DebFile__updatePkgNameCHANGELOG_DEBIANCHANGELOG_NATIVErQrr*gzipGzipFilerJr)r4rlfhr raw_changelogs r changelogzDebFile.changelogs >> !  "&7&79 ,E YY''t'Dr* *b "  *]+ + ,   * *sB":B1" B.-B.1B: cl|jj|jjyr)r'rrQrs rrz DebFile.closes   rc|Srrrs r __enter__zDebFile.__enter__s rc$|jyr)r)r4exc_typeexc_valexc_tbs r__exit__zDebFile.__exit__!s  r)NrNrr)r,r-r.rr6rpropertyrrQr'rrrr(rrrrrrrrrs &P6'''' ) &     F * rr__main__rS)r)7rrrLr^sysos.pathrXpathlibrtypingrrrrrr r r r r rrtyping_extensionsr ImportError debian.arfilerrrdebian.changelogr debian.deb822rr\r]r[rrrrrrr*objectr0rrrr,argvdebr'rdprintrtrrrrs$.  "    43&    .  D  29  w ~f~B g CCLFfFR z 388A; 'C ++// C #-- "#i"M ""s"C11 D?D