o a~bM>@stdZddlZddlZddlZddlZddlZz$ddlmZm Z m Z m Z m Z m Z mZmZmZmZmZmZddlmZWneyIesGddZYnwddlmZmZmZddlmZdd lmZd Zd Z gd Z!d Z"gdZ#dZ$dZ%dZ&dZ'GdddeZ(Gddde)Z*Gddde*Z+Gddde*Z,GdddeZ-e.dkre-ej/ddZ0e0j12Z2e3e24ddSdS) zX Representation of Debian binary package (.deb) files Debfile Classes =============== N) AnyBinaryIODictIOIteratorListOptionalTextTypeVarUnionoverload TYPE_CHECKING)LiteralcCdSN)frr0/usr/lib/python3/dist-packages/debian/debfile.py4sr)ArFileArErrorArMember) Changelog)Deb822zdata.tarz control.tar)gzbz2xzlzmazstz debian-binary)preinstpostinstprermpostrmconfigcontrolzusr/share/doc/%s/changelog.gzz$usr/share/doc/%s/changelog.Debian.gzmd5sumsc@ eZdZdS)DebErrorN__name__ __module__ __qualname__rrrrr'Hsr'c@seZdZdZddZddZeddZdd Ze dd d Z e dd d Z ddd Z e dddZ e dddZ dddZ ddZ ddZ ddZddZd S)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') ). cCs||_d|_dSr)_DebPart__member _DebPart__tgz)selfmemberrrr__init__^s zDebPart.__init__c sfdd}jdur^jj}tj|ddd}|tvs'|tks'|tkrX|dkr2|ddg}nj}z t j |dd _WjSt j t j fyW}zt d |d}~wwt d |jS) 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 szddl}ddlddl}|j||j|jdfddd}Wnttfy2}ztd|d}~ww|j d}|j dkrItd|j | |S)NrFcsjjSr)signalSIGPIPESIG_DFLrr2rrrxsz9DebPart.tgz.._custom_decompress..)stdinstdoutuniversal_newlines preexec_fnz%sz!command has failed with code '%s') subprocessr2ioPopenPIPEOSError ValueErrorr' communicater-read returncodeBytesIO) command_listr:r;procedatar/r5r_custom_decompressls(     z'DebPart.tgz.._custom_decompressNrunzstdz--stdoutzr:*)fileobjmodez#tarfile has returned an error: '%s'z"part '%s' has unexpected extension)r.r-nameospathsplitext PART_EXTS DATA_PART CTRL_PARTtarfileopen ReadErrorCompressionErrorr')r/rIrN extensionbufferrFrrHrtgzcs"   z DebPart.tgzcCs4|dr |dd}|S|dr|dd}|S)zw try (not so hard) to obtain a member file name in a form relative to the .tar.gz root and with no heading '.' ./N/rJ) startswith)fnamerrr__normalize_members   zDebPart.__normalize_membercCs"t|}|}d||vS)z.Check if this part contains a given file name.r\)r,_DebPart__normalize_memberr[getnames)r/r`namesrrrhas_files   zDebPart.has_fileNcCrrrr/r`encodingerrorsrrrget_filezDebPart.get_filecCrrrrfrrrrirjcCsHt|}|d|}|durtd|dur"tj|||dS|S)zReturn 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. r\NzFile not found inside packagergrh)r,rbr[ extractfiler'r; TextIOWrapper)r/r`rgrhfobjrrrris cCrrrrfrrr get_contentzDebPart.get_contentcCrrrrfrrrrorpcCs,|j|||d}d}|r|}||S)zReturn the string content of a given file, or None (e.g. for directories). If encoding is given, then the content will be a Unicode object; otherwise, it will contain binary data. rkN)rirAclose)r/r`rgrhrcontentrrrros  cCst|Sr)iterr[rcrHrrr__iter__szDebPart.__iter__cC ||Sr)rer/r`rrr __contains__ zDebPart.__contains__cCrur)rorvrrr __getitem__rxzDebPart.__getitem__cCs|jdSr)r-rqrHrrrrqsz DebPart.closeNNr)r)r*r+__doc__r1r[ staticmethodrbrer rirortrwryrqrrrrr,Ls45          r,c@r&)DebDataNr(rrrrr}sr}c@sBeZdZddZddZed ddZed ddZd d dZdS) DebControlcCs6i}tD]}||r||}|dur|||<q|S)zo Return a dictionary of maintainer scripts (postinst, prerm, ...) mapping script names to script text. N) MAINT_SCRIPTSrero)r/scriptsr`rGrrrrs  zDebControl.scriptscCst|tS)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') )rro CONTROL_FILErHrrr debcontrolszDebControl.debcontrolNcCrrrr/rgrhrrrr%rjzDebControl.md5sumscCrrrrrrrr%$rjc Cs|ts tdt|jt||d}i}d}|durd}|D]}||dd\}}t|tr:| ||<q!|||<q!| |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 sumsrkz Ns rJ) reMD5_FILEr'ri readlinesrstripsplit isinstancebytesdecoderq) r/rgrhmd5_filesumsnewlinelinemd5r`rrrr%)s    rzr)r)r*r+rrr r%rrrrr~s  r~c@seZdZdZdddZddZedd Zed d Zed d Z ddZ ddZ e dddZ e d ddZ dddZ ddZddZddZddZdS)!DebFileaRepresentation of a .deb file (a Debian binary package) DebFile objects have the following (read-only) properties: - version debian .deb file format version (not related with the contained package version), 2.0 at the time of writing for all .deb packages in the Debian archive - data DebPart object corresponding to the data.tar.gz (or other compressed or uncompressed tar) archive contained in the .deb file - control DebPart object corresponding to the control.tar.gz (or other compressed tar) archive contained in the .deb file Nrcst||||t|fdd}tvrtdti|_t||t |jt <t ||t |jt <d|_ |t}| |_|dS)NcsjfddtD}ttfvr|t|}|s#td|t|dkr/td|t|dS)Ncsg|]}d|fqS)z%s.%sr).0extbasenamerr bszBDebFile.__init__..compressed_part_name..z9missing required part in given .deb (expected one of: %s)rJz>too many parts in given .deb (was looking for only one of: %s)r) rRrSrTappend intersectionsetr'lenlist)r candidatesparts actual_namesrrcompressed_part_name`s"    z.DebFile.__init__..compressed_part_namez4missing required part in given .deb (expected: '%s'))rr1rrc INFO_PARTr'_DebFile__partsr~ getmemberrTr}rS_DebFile__pkgnamerAstrip_DebFile__versionrq)r/filenamerMrLrrrrrr1[s(      zDebFile.__init__cCs|d|_dS)Npackage)rrrHrrr__updatePkgNameszDebFile.__updatePkgNamecCs|jSr)rrHrrrversionszDebFile.versioncC |jtSr)rrSrHrrrrG z DebFile.datacCrr)rrTrHrrrr$rzDebFile.controlcC |jS)z See .control.debcontrol() )r$rrHrrrrrzDebFile.debcontrolcCr)z See .control.scripts() )r$rrHrrrrrzDebFile.scriptscCrrrrrrrr%rjzDebFile.md5sumscCrrrrrrrr%rjcCs|jj||dS)z See .control.md5sums() rk)r$r%rrrrr%scCsl|jdur |t|jt|jfD] }|j|r3tj|j|d}| }| t |SqdS)z Return a Changelog object for the changelog.Debian.gz of the present .deb package. Return None if no changelog can be found. N)rL) r_DebFile__updatePkgNameCHANGELOG_DEBIANCHANGELOG_NATIVErGregzipGzipFilerirArqr)r/r`r raw_changelogrrr changelogs   zDebFile.changelogcCs|j|jdSr)r$rqrGrHrrrrqs z DebFile.closecCs|SrrrHrrr __enter__szDebFile.__enter__cCs |dSr)rq)r/exc_typeexc_valexc_tbrrr__exit__s zDebFile.__exit__)NrNrzr)r)r*r+r{r1rpropertyrrGr$rrr r%rrqrrrrrrrKs* (       r__main__rJ)r)5r{rr;rUsysos.pathrOtypingrrrrrrrr r r r r typing_extensionsr ImportError debian.arfilerrrdebian.changelogr debian.deb822rrSrTrRrrrrrrr'objectr,r}r~rr)argvdebr$r[printrrrrrsL8   5F