4Ad2ddlZddlZddlZddlZ ddlZddlmZmZnA#e$r9Z ej dkrne e ej dYdZ [ ndZ [ wwxYwddl Z ddlZddlZddlZddlZddlZddlZddlmZddlmZdZdgZd d d d d Zgd ZeD]7Zedeeefz8[ddl m!Z!ddl"m#Z#dZ$gdZ%dddddddddd Z&e'de(e&)DZ*ej+Z,dZ-gdZ.d Z/dVd!Z0d"Z1dWd$Z2d%Z3dWd&Z4dXd(Z5d)Z6d*Z7d+Z8dYd-Z9dZd/Z:iZ;dXd0Z<Gd1d2e=Z>d3Z?d4Z@d5ZAd6ZBdXd7ZCdXd8ZDd9ZEd[d;ZFdXd<ZGgd=ZHd>ZId?ZJd@ZKdAZLdBZMd,d,dCddd,d,d,d,eNddd'dfdDZOGdEdFe j ZPejQRdGZSdHeSfZTdIZUdJZVdKZWdLZXdMZYdNZZdOZ[ej fdPZ\dQZ]dRZ^dSZ_dTZ`dUZadS)\N)TempFilecleanup_temp_fileWindows)open_url)MUA)PackageSourceVersionSeverityFileTags Justificationz Followup-ForOwnerUserUsertags ForwardedControl X-Debbugs-Ccrz4Offer simple prompts, bypassing technical questions.zOffer more extensive prompts, including asking about things that a moderately sophisticated user would be expected to know about Debian.zRLike standard, but assumes you know a bit more about Debian, including "incoming".zBypass most handholding measures and preliminary triage routines. This mode should not be used by people unfamiliar with Debian's policies and operating procedures.)novicestandardadvancedexpertz MODE_%s=%d)debbugs) AVAILABLE_UISafDear Maintainer, *** Reporter, please consider answering these questions, where appropriate *** * What led up to the situation? * What exactly did you do (or not do) that was effective (or ineffective)? * What was the outcome of this action? * What outcome did you expect instead? *** End of the template - remove these template lines ***)/z/usrz /usr/sharez/varz /usr/X11R6z/usr/manz/usr/doc/usr/binoldoldoldoldstableoldoldoldstable oldoldstable oldstablestabletestingz next-testingunstable experimental) jessiestretchbusterbullseyebookwormtrixieforkysidr%cg|] \}}||f Sr/).0codenamesuites 1/usr/lib/python3/dist-packages/reportbug/utils.py r4bs!]]]_Xux(]]]ctj|}|d}t dt |dzD]}d|d|}|tvr)tj|rtj |}tj|\}}tj tj||}tjj|g||dz}t|cS|S)a Return the real path of file `filename` This is similar to ``os.path.realpath()``. The difference is that symlinks to a small set of basic directories are not resolved and just kept in the path if present. This function is a helper function called only by :func:`search_path_for()`. Parameters ---------- filename : string name of a file, may include relative or absolute path Returns ------- str the real path of the given file rrrN) ospathabspathsplitrangelenjoinfhs_directoriesislinkreadlinknormpathrealpath)filenamebitsi componentresolveddirfilenewpaths r3rCrCgs*wx((H >>#  D 1c$ii!m $ $ % %HHT!A#Y''  ' '  7>>) $ $ %{9--H'-- 22KS$w'' S((C(CDDHglXJabb$9:GG$$ $ $ $  % Or5) /usr/sbinrz/sbinz/binz/usr/X11R6/binz /usr/gamesctj|\}}|rt|Stjdtjd}tD]}||vr|||D]R}tj ||}tj |rt|cSSdS)a Searches for a file in PATH and common application directories Given the filename of an executable, this function tries to locate the file in common application directories (/usr/sbin, /usr/bin/, /sbin, /bin, /usr/X11R6/bin, /usr/games) and in any additional directories included in PATH. :func:`realpath()` is called on the result (if found). This function is a helper function called only by :func:`find_package_for()`. Parameters ---------- filename : string name of a file, may include relative or absolute path Returns ------- str or None the real path of the given file; None if the file was not found PATH:N) r8r9r;rCenvirongetdefpathpathdirsappendr>exists)rDdfr9fullnames r3search_path_forrYs0 7== " "DAq"!!! :>>&"* - - 3 3C 8 8D  D== KKNNN &&7<<1%% 7>>( # # &H%% % % % & 4r5cd}|tjdtjd|fD]}|rn|S)a Determine which editor program to use Parameters ---------- specified_editor : str Specified editor for reportbug, to be used in preference to other settings. Returns ------- str Command to invoke for selected editor program. z/usr/bin/sensible-editorVISUALEDITOR)r8rPrQ)specified_editordebian_default_editoreditors r3 which_editorr`s^7#:>>(++:>>(++(*   E  Mr5c2tjdd|}|S)a8 Escape globbing pattern characters with backslash This function is a helper function used only by :func:`query_dpkg_for()`. Parameters ---------- filename : str filename, possibly using a globbing pattern Returns ------- str escaped filename (pattern) z ([*?\[\]])z\\\1)resub)rDs r3 glob_escaperds"vmWh77H Or5Tctj|}|r7tjdrtjd|z}nd}tjd|z}||fS)ap Search for a file in a debian binary package This is done by opening a pipe to capture the output of ``dlocate`` or ``dpkg``. This function is a helper function used only by :func:`query_dpkg_for()`. Parameters ---------- searchfile : str the file to look for use_dlocate : bool try to search using dlocate (which is fast, but may not be available) or always use dpkg (always available, but slow) Returns ------- (pipe, bool) Tuple with the pipe and a bool, the latter indicating whether dlocate was used (True) or not (False) z/usr/bin/dlocatez$COLUMNS=79 dlocate -S %s 2>/dev/nullFz'COLUMNS=79 dpkg --search %s 2>/dev/null)shlexquoter8r9rUpopen) searchfile use_dlocateargpipes r3 search_pipermso0 +j ! !CIrw~~&899Ix>DEE xACGHH + r5cd}t|trd|vrd}tj||tjjdS)a Capture the output of a program Since reportbug needs to be able to run in misconfigured locales, we need to specify an error handler whenever some external input is processed. This wrapper function avoids having to specify this separately for each program invocation. Parameters ---------- cmd : str or tuple The command to execute including any options and arguments Returns ------- str The output (stdout) of the command F T)shellstdoutbackslashreplaceerrors) isinstancestr subprocessrunPIPErqdecode)cmd use_shells r3get_command_outputr} sV&I#ss  >#Yz G G G N U U]o U p ppr5c tj}n$#t$rtjdYnwxYwt |}t ||\}}i}|D]}|}d|vr|dd\}} | } |d} | D](}||vr||| "| g||<)| |s|rt|d\}}|s.| dr|d d }t|S||fS) av Search for a file in a debian binary package This is done using ``dlocate`` or ``dpkg``. This function is a helper function used only by :func:`find_package_for()`. Parameters ---------- filename : str the file to look for use_dlocate : bool try to search using dlocate (which is fast, but may not be available) or always use dpkg (always available, but slow) Returns ------- (str, dict) Tuple with the original filename input parameter and a dictionary with matching packages as keys and lists of corresponding files as values. rz diversion by: r, F)rj)r/usr/librLN) r8getcwdOSErrorchdirrdrmstripr;rTclosequery_dpkg_for startswith) rDrj_searchfilenamerl dlocate_usedpackageslinepackager9packlists r3rr#s0 IKK    **N&~{CCT<H + +zz|| T ! ! **T1--$zz||==&& + +G(""!((....%)F!!  +  JJLLL B B$X5AAA 8 (++,QRR(ABB<h''' X s 77FcRi}|drEtjd}||}d||d<||fS|ddkrt |\}}|r||fSt |}|r|s|dfSt |p|S)av Find the package(s) containing this file Parameters ---------- filename : str The name of the file including any path components pathonly : bool If no path component is part of the file name, specify if the file should be looked for in the ``PATH`` (directories with executables) only or if the entire dpkg database should be searched. Returns ------- (str, dict) Tuple with file name (possibly modified from input parameter filename) and a dictionary with matching packages as keys and lists of corresponding files as values. z/var/lib/dpkg/info/z/var/lib/dpkg/info/(.+)\.[^.]+rrrN)rrbcompilematchgrouprrY)rDpathonlyr dpkg_infomfnpkglist newfilenames r3find_package_forr`s*H011$J@AA OOH % %!(##{c$X.. G  w; !(++K  $ +1 2 22r5cd} t|d}n#t$rYdSwxYw|5|D]}|dd}|s2 |d\}}||kr"|ccdddS#t$r"t d|zYddddSwxYw ddddS#1swxYwYdS) a Lookup email alias of user `username` Checks if there is an email alias for the user `username` configured for outgoing mail (in '/etc/email-addresses') and returns that alias. This is a helper function for :func:`get_user_id()`. Parameters ---------- username : str the username to look up Returns ------- str or None an email address (or None if not found) z/etc/email-addressesrrrsN#rrOzInvalid entry in %s)openrrr; ValueErrorprint)usernamerDfprnamealiass r3find_rewrittenrs(&H (#5 6 6 6 tt    D::<<%%c**1-D  "jjoo e::<<8++ ;;==((        ,   +h6777t                            sH $$5C/AB2"C/1C/2CC/CC//C36C3cnd|vrdS|ddkrdS|d\}}|ds|drdSd|vrdS|ds|drdS|dvrdS|drdSdS)a7 Simple check for email validity Performs some simple checks on whether the given string looks like an email address. Parameters ---------- addr : str string to check Returns ------- bool True if the string looks like an email address, otherwise False @Fr.) localhostz example.comz example.netz example.org)z.examplez.invalidz .localhostz.testz .example.comz .example.netz .example.orgT)countr;rendswith)addr localpart domainparts r3check_email_addrrs" $u zz#!u JJsOOIzC  I$6$6s$;$;u *uS!!Z%8%8%=%=uOOOuLMMu 4r5cNtj|gdS)a Extract email address from a string Email addresses are often accompanied by a name: ``My Name `` or ``my@address.info (My Name)``. This function tries to separate the two parts and returns a (name, address) tuple. Parameters ---------- addr : str an email address (possibly including a name component) Returns ------- (str, str) Tuple containing the name (if found, otherwise empty string) and the plain email address r)emailutils getaddresses)rs r3get_email_addrrs!& ; # #TH - -a 00r5rc<tt||S)a" Get the user's email address and name If name and email address are not given, try to obtain the missing info for the current user and return the result. Parameters ---------- emailaddr : str an email address (possibly including a name component) realname : str Real name (will be ignored if the `emailaddr` string contains a name component) Returns ------- (str, str) Tuple containing the name (if found, otherwise empty string) and the plain email address )r get_user_id) emailaddrrealnames r3 get_emailrs* +i:: ; ;;r5utf-8c(tj}tj|}tjd|p=tjdptjd}|pt |dp|d}d|vr{ tdd5}| }dddn #1swxYwYn##t$rtj }YnwxYw|dz|z}d |vsd |vrt|\}}|stjd p=tjd ptjd }|sP|dddd}|d|d}|s|St"j||fS)a Find email address of the current user This is similar to :func:`get_email()`, but returns a single string instead of a (name, address) tuple. Parameters ---------- emailaddr : str address, if already known, possibly including a name component. Note that if the 'REPORTBUGEMAIL' environment variable is set, its value will overwrite this parameter. realname : str real name, if already known. charset : str not used Returns ------- str email address string, including a name component if available (RFC2047-encoded if the name contains non-ASCII characters) REPORTBUGEMAILDEBEMAILEMAILrrz /etc/mailnamerN<( DEBFULLNAMEDEBNAMENAMEr,r&)r8getuidpwdgetpwuidrPrQrrreadlinerrsocketgetfqdnrr;replace capitalizerr formataddr)rrcharsetuidinfomf domainnames r3rrs20 )++C <  D 0)<<,JNN:..,JNN7++?^DG44?QI ) *os++ 3r[[]]0022  3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 * * *))JJJ *Oj0  i3)++,Y77) CJNN=11.RZ^^I5N5N.z~~f--  CAw}}S!,,Q/H''T!W-?-?-A-ABBH  ; ! !8Y"7 8 88s6*C9:'C-! C9-C11C94C15C99DDc|s|tvr t|Stjd}tjd}tjd}tjd}tjd}tjd}tjd}tjd} tjd } tjd } tjd } tjd } tjd }tjd}dx}x}x}x}}dx}x}x}x}x}}g}g}g}g}g}d} d}!d}" tj}#n$#t $rtjdYnwxYwtj|}$|r|tvrtd|$z}%nQd}%nN td|$z d}$n#t$rYnwxYwtd|$z}%|% tj D]}&|&}&|&s|!r$|&ddkr||&nd}!| r)|&dddkrd} n|tjd|&z }||&r|& dd\}'}| |&r|& dd\}'}||&r|& dd\}'}||&r|& dd\}'}(| |&r|& dd\}'}X| |&r|& dd\}'}| |&r|s|& dd\}'}d}!||&rO|& dd\}'}(d|( dD}(||( ||&rO|& dd\}'}(d |( dD}(||(||&rO|& dd\}'}(d!|( dD}(||(||&rd} | |&r|& dd\}'}1||&r5|& dd\}'}| d}{||&r|& dd\}'}d})|r| d}"|"d"v})d}*|rt'j|}*n~|rz|t&jvrWt&j|d#}t&j|d$d%t&j|d&f}*n|}nd}||t1|t1|t1|||)|||*|||tj ||"t1||f}+|s |+t|<|+S)'a Get information on a binary package, including status Parameters ---------- package : str the name of the package avail : bool if True, also look up the detailed package information if the package is not installed (with apt rather than dpkg) Returns ------- (..., ...) A tuple with 17 components. The components are: 0. package version string or None 1. available package name or None 2. dependencies as a tuple containing lists, each list representing alternative dependencies 3. recommended packages as a tuple containing lists, each list representing alternative recommends 4. conffiles as a tuple containing (filename_str, md5sum_str) tuples 5. maintainer name and email address string 6. bool indicating whether the package is installed 7. origin (content of "Origin:" package header if available) 8. vendor of the package if available 9. reportinfo 10. priority string 11. package short description string (summary) 12. source name if a source header is available 13. full package description string (without summary line) 14. package state string 15. suggested packages as a tuple containing lists, each list representing alternative suggests 16. archive section of the package z Version: z Package: z Priority: z(Pre-)?Depends: z Recommends: z Suggests: z Conffiles:z Maintainer: zStatus: zOrigin: zBugs: zDescription(?:-[a-zA-Z]+)?: zSource: z Section: NFrrz,LC_ALL=C.UTF-8 apt-cache show %s 2>/dev/nullz4dpkg-query -W -f='${binary:Package} ' %s 2>/dev/nullrz'COLUMNS=79 dpkg --status %s 2>/dev/nullror7z /z (.+) ([0-9a-f]+).*$rrTcLg|]!}d|dD"S)cBg|]}|dSrr;r0ys r3r4z1get_package_status...$???QAGGIIaL???r5|rr0xs r3r4z&get_package_status..A??? @?!''#,,??????r5rcLg|]!}d|dD"S)cBg|]}|dSrrrs r3r4z1get_package_status...rr5rrrs r3r4z&get_package_status..rr5cLg|]!}d|dD"S)cBg|]}|dSrrrs r3r4z1get_package_status...rr5rrrs r3r4z&get_package_status..rr5) config-filesz not-installedrtyperbtsroot) statuscacherbrr8rrrrfrg _apt_cacher}r; IndexErrorlineseprstriprTfindallrextendr parse_bts_urlSYSTEMSrQrtupler>),ravail versionre packagere priorityre dependsrerecsre suggestsre conffilesremaintrestatusreoriginrebugsredescresrcre sectionre pkgversionpkgavail maintainerstatusoriginbugsvendorprioritydescsrc_namesection conffilesfulldescdepends recommendssuggestsconfmodedescmodestaterpackargoutputrcrud thisdepends installed reportinfors, r3get_package_statusrCsjN $W ++7## ;''I ;''IL))J -..I Z ' 'FL))J*\**Kj((Gz*%%Hz*%%H Z ! !F Z6 7 7F Jz " "E ;''I;??J??J?&;??D?6?H?t?hIHGJHHH E IKK   k'""G A j '>HJJFFFF (G'QSSSXSXSZSZ[\^GG    D # 5 ?AA RZ((;0;0{{}}    !Aw#~~%%%%   GBQBx4 RZ(?FFF ??4 ) 0!%D!!4!4 T:: ^^D ! !' 0!ZZa00NT66   d # #% 0#zz$22 T88 __T " "# 0#zz$22 T88 ^^D ! !! 0!ZZa00NT66 \\$   0::dA..LT44 \\$   0 0::dA..LT4HH __T " " 0"&**T1"5"5 T;??%0%6%6t%<%<???K NN; ' ' ' ' \\$   0"&**T1"5"5 T;??%0%6%6t%<%<???K   k * * * *   d # # 0"&**T1"5"5 T;??%0%6%6t%<%<???K OOK ( ( ( (   t $ $ 0HH ]]4  0#zz$22 D** [[   0!ZZa00ND(~~''*HH __T " " 0 JJtQ//MD'I E q!"CC J *400  W_ $ $_V,V4F!/&155fiHH!/&1)<>JJ&&((FF %..% 2C2C )    66:x (BJOOH55ueHoo   D $# G Ks$E,,F  F *G11 G>=G>c,eZdZdZddZdZdZdZdS)AvailDBz Split a pipe or file into chunks separated by empty lines This turns a pipe or file into an iterator that returns chunk by chunk on each next() call. NcJ||_|r ||_dS|r|j|_dSdSN)popenobrrq)selfrr s r3__init__zAvailDB.__init__s;  %DGGG  %nDGGG % %r5c|Srr/)r!s r3__iter__zAvailDB.__iter__s r5cd} |jr |jjrn7|j}|sn|dkr|S|t |z }K|r|St )NrT )r  returncoderrrv StopIteration)r!chunkrs r3__next__zAvailDB.__next__s| | <*7##%%D t|| SYY E   Lr5c|jrE |jjrn|jd}|sn+|j|jr|jdSdS)NTi)r r'rreadwaitr)r!stuffs r3__del__zAvailDB.__del__&s <  <* U++   L      7  GMMOOOOO  r5)NN)__name__ __module__ __qualname____doc__r"r$r*r/r/r5r3rrs_ %%%%(     r5rcftjddtjd}t|S)z Get the dpkg status database as an :class:`AvailDB` object. This is a helper function for :func:`get_package_info()`. Returns ------- AvailDB A :class:`AvailDB` object to access the dpkg status database )z dpkg-queryz--statusrrT)rtrqtextr rwPopenryrsubps r3get_dpkg_databaser;5s5  6?QZdZipt u u uD 4  r5cdtjdtjd}t|S)z Get the database of available packages as an :class:`AvailDB` object This function is not used anywhere and might be removed soon. Returns ------- AvailDB A :class:`AvailDB` object to access apt's available database )z apt-cache dumpavailT)rqr5r6r7r9s r3get_avail_databaser>Ds0  6zUY Z Z ZD 4  r5cB t|jdjS#t$rYnwxYw tj}||r|jSn4#tjj $r}td|dYd}~nd}~wwxYwdS)z Get the source package name of a given package Parameters ---------- package : str the name of a (source or binary) package Returns ------- str or None the name of the corresponding source package r Cannot look up source package: ''N) rversions source_nameKeyErroraptapt_pkg SourceRecordslookuprErrorr)r srcrecordses r3get_source_namerLTs '"+A.::      7[..00   W % % &% % & ; 777 5555666666667 4s# ,,9A++B?BBcg} tj}||r:|j|kr||j||:n4#tjj$r}td|dYd}~nd}~wwxYwt|dkr|dSdS)z Get the package version of a given source package Parameters ---------- package : str the name of a source package Returns ------- str or None the version of the source package r@rANrr) rErFrGrHrrTversionrIrr=)srcnamerBrJrKs r3get_source_versionrPpsH7[..00 (( 4!W,, 2333(( 4 ; 777 5555666666667 8}}{ 4sA-A22B#BB#cJg}t} tj}n6#tjj$r}t d|d|cYd}~Sd}~wwxYw||r|j|vr|r |j|kr-||jt|j D];} t|j dj }n#t$rY-wxYw|r|||fgz }<|d|jzdfgz }|||S)a Get list of binary packages belonging to a (source) package. Parameters ---------- package : str the name of a (source or binary) package only_source : bool should be set to True if only source package names should be matched (like apt-cache showsrc --only-source) Returns ------- [(str, str), ...] A list of (name, short description) tuples describing the binary packages belonging to the source package of the given package r@rANrzsrc:zSource package)setrErFrGrIrrHraddsortedbinariesrrBsummaryrD)r only_sourcerfoundrJrKbpr s r3get_source_packagerZsy$H EEE[..00 ;  5555666   G $ $F   & &   :-88  *$%%%,-- ) )B !"~.q19     )b$ZL(fz113CDEE#   G $ $F& Os-1A$AA$A$C## C0/C0c|sgSt}d}i}g}g}|D]6\}}|||<tj|} || dz7dd|zdzd|zdzd|zdz|zd zg}t |} id |D} tjd tj} tjd tj} tjd tj}tjdtj}g}|D]}| D]}| |}|rw| | d}| | d}| }|dd|ddz}|ddvs |ddkr| ddkr.| d d}nd}| | d}| | d}|||||f}||| |}|r |D]}d|<|vrd|<|r|S| D]a}fd|D}t|t|kr1|vr-|d|ddd dfb|S)!a Collect information about one or more packages This is a helper function for :func:`packages_providing()` and :func:`get_dependency_info()`. Parameters ---------- packages : [((str, ...), str), ...] List of ((pkg1, pkg2, ...), package) tuples about which to look up information. Each tuple consists of two elements: - another tuple specifying a "group" of package names representing alternative dependencies - one specific package name that should also be part of the group. Virtual package names are allowed. skip_notfound : bool Include information about (group, package) tuples about which no information at all was found, indicating just this. Returns ------- [(str, str, str, str, str or None), ...] List of (name, status, version, shortdescription, provides) tuples about each specific package in the input tuples (not groups). If multiple packages providing one of the packages are found, information on all of these packages is returned and the corresponding "provides" field is filled in the output tuples. z&(?:[\S]+(?:\s+\(=[^()]+\))?(?:$|,\s+))z(?:\s+\(=[^()]+\))?z^(?PPackage):\s+(rz)$z^(?PProvides):\s+z *(?Pz )(?:$|,\s+)z*$cLg|]!}tj|tj"Sr/)rbr MULTILINErs r3r4z$get_package_info..s&AAAAr|,,AAAr5z^Package: (?P.*)$z^Status: (?P.*)$z^Version: (?P.*)$z*^Description(?:-[a-zA-Z]+)?: (?P.*)$pkgstatrr7ihrnhdrProvidesNversr Tcg|]}|v| Sr/r/)r0rrXs r3r4z$get_package_info..s777!Ar5z | pnzz(no description available))r;rbescaperTr>listvaluesrr]searchrr;rQr=)r skip_notfoundpackinfopkgnamegroupfor searchpkgs searchbitsrrescpkggroups searchobspackobstatobversobdescobretpobrpackr_sinfoprovidesrdr ritemnotfoundrXs @r3get_package_infors>   ""H7GHJJ$;;!7## 9:::: "CHHZ$8$884?!G+l: ((:   !/ 029 :<@ A J(//## $ $F EAAjAAAI Z0", ? ?F Z0", ? ?F Z12< @ @F ZDbl S SF C ++ + +B ! A +}}Q''--e44}}Q''--f55 Qx{U1Xa[0 7$&&$q'S..775>>Z// wwu~~3355a8HH#H}}Q''--f55}}Q''--f55dD$9 4    T**+ %++&*d 5((&*E(O; +> AA7777u777 x==CJJ & &E!! EJJu--tX8$@AAA Jr5ct|f|fgd}g}|D]%}||d|df&|S)aw Get a list of packages providing a given package name Parameters ---------- package : str package name to be looked up in 'Package:' and 'Provides:' fields Returns ------- [(str, str), ...] List of (name, shortdescription) tuples for each (non-virtual) package providing the given (possibly virtual) package T)rkr)rrT)raretrxr^s r3packages_providingr(s[ wj'234 H H HD C%% CFCF#$$$$ Jr5 depends onc |s d|d|dSg}|D]7}d|D}|D]&}|t||f'8d|d|d}i}t|D]/}|d} | |vr||| <|dr|| ds||| <0t|} | g} | D]-\} } }}}|r | d |zd zz } | | || f.| } t d | D}t d | D}t|t d |z d}t|d |z }dd}| D]\} }} ||| | |||z }|S)a  Provide information on the dependencies of a package For each of the provided dependencies, the status and version is collected. The result is formatted as a table and returned as a single string. Parameters ---------- package : str name of the package to which the dependency list belongs depends : [(str, ...), (str, ...), ...] list of tuples, each tuple giving a "dependency group" of simple dependencies or groups of alternative dependencies rel : str should be either "depends on", "recommends", or "suggests" and will be printed along with the package name above the dependency table Returns ------- str a table listing the status and versions of dependencies r&roz no packages. cDg|]}|ddS)rOrr)r0rVs r3r4z'get_dependency_info.._s&,,,1qwws||A,,,r5z Versions of packages z: rrz []c8g|]}t|dSrr=rs r3r4z'get_dependency_info..}"+++aAaD +++r5c8g|]}t|dS)rrrs r3r4z'get_dependency_info..~rr5I$%cd|||||}||ds ||drY||d}||d}|d||||dzz }||dO||dY|S)z)line-wrap long package names and versionsz{:3.3} {:{wp}.{wp}} {:.{wv}} wpwvNz {:{wp}.{wp}} {:.{wv}}r&)formatr)rr{rNrrrs r3 table_rowz&get_dependency_info..table_rows077gRTY[7\\233i e7233< e9DbcclG 077g"QS7TT[[]]`dd dD233i e7233< e r5r)rr)rTrrrhrisortmaxmin)rrrel dependenciesdepbitdepinfopacksrr^deplistdeplist2r{rrdr r}maxpmaxvwidthpwidthvrs r3get_dependency_infor@s62 ;;,3GGSSS9:L33,,,,, 3 3C   sS 1 2 2 2 2 33 4;77CCC@G E ..""1g e  E#JJ !W ":a= "!c 5<<>>""G LLNNNH07..,vtT8  * D8Oc) )DtV,----G ++7+++ , ,D ++7+++ , ,D s29b)) * *F rF{ # #F!(GGtV99VT4FvFFFF Nr5ci}g}|D]\}} t|d5}|}dddn #1swxYwYn#t$r}|||<Yd}~Xd}~wwxYwtdt j|zd} | |kr||d} |D]"} | s| dkr|s| ddkr|s| | z } #| ||<||fS) a9 Get information about modified config files Parameters ---------- conffiles : [(str, str), ...] List of (filename, md5sum) tuples nocompress : bool determines whether empty lines and comment lines should be included in the output Returns ------- ({str: str, ... }, [str, ...]) tuple with two components: - dictionary of modified config files, with filenames as keys and ("compressed" if desired) config file content as values - filename list of the modified config files rrrsNzmd5sum rz changed: r&r)r readlinesrr}rfrgr;rT) r  nocompressconfinfochangedrDmd5sumrlinesmsgfilemd5thisinfors r3get_changed_config_filesrs*HG'&&6 h'9::: 'b  ' ' ' ' ' ' ' ' ' ' ' ' ' ' '   !$HX  HHHH %YX1F1F%FGGMMOOPQR f   x     D t||J|Aw#~~j~  HH% W s7A ? A A A A A  A$AA$)r!r"r#r$r%cdx}x}x}}g}td}|rtjdtj}i}||D]y}|dd\} } | t vr*t| t | } } n#t| tt } } d|| | | f<z|rct| }| | d|D}|dd} td d 5} | }d d d n #1swxYwYn+#t"$rt%d t&jYnwxYw|r |d|zdzz }|r |d|zdzz }|r'dd|D}|d|zz }|r||z }|S)a Collect information about the distribution and release Find out which distribution (Debian/Ubuntu/) this is, which release, and APT preferences and policy. Returns ------- str text summarizing the collected information rzapt-cache policy 2>/dev/nullzE\s+(\d+)\s+.*$\s+release\s.*o=(Ubuntu|Debian|Debian Ports),a=([^,]+),rrTc.g|]}|d|dfS)rr7r/rs r3r4z+get_debian_release_info..s$111aadAaD\111r5rz/etc/debian_versionrrrsNz"Unable to open /etc/debian_version)rJzDebian Release: r&z APT prefers rc,g|]}t|Sr/)rvrs r3r4z+get_debian_release_info..s555!s1vv555r5z APT policy: %s )r}rbrr]finditerr DISTORDERintindexr=rhkeysrreverserrrrrsysstderrr>)debversdebinfoverfilewarndistsrmrerXrpworddistnamepridistfob policystrs r3get_debian_release_inforsv*,+G+g+$ E  > ? ?F "jacecopp\\&)) 0 0E#kk!Q//OE89$$JJ (A(ATJJIT+/E3h' ( (  "&&E JJLLL MMOOO115111EAhqkGE '0B C C C -sllnn**,,G - - - - - - - - - - - - - - - EEE 2DDDDDDE7%/$665#g-44 4II55u55566 ')33 4 Ns63F'E7+ F7E;;F>E;?F%F+*F+c tdS)zl Get LSB release information Returns ------- str Information about LSB release zlsb_release -a 2>/dev/null)r}r/r5r3lsb_release_infors : ; ;;r5ctd}|s]tj}|d}t jdd|}t jdd|}t jdd|}|S) z Get the architecture of the current system. Returns ------- str architecture name (e.g., ``"i386"``) z0COLUMNS=79 dpkg --print-architecture 2>/dev/nullrzi[456]86i386s390xs390ppcpowerpc)r}rr8unamerbrc)archuns r3get_archr sx P Q Q W W Y YD / XZZ!uvk6400vh--vfi.. Kr5cntd}d|S)z Check if multiarch is used (foreign architecture(s) defined) Returns ------- str comma-separated list of foreign architectures z9COLUMNS=79 dpkg --print-foreign-architectures 2>/dev/nullr)r}r> splitlines)outs r3 get_multiarchr s. X Y YC 99S^^%% & &&r5cPtjddkrdndS)z Check if the system is merged-usr Returns ------- str Empty if merged-usr, a note that the system is not merged-usr otherwise z/librrzmerged-usr: no )r8r9rCr/r5r3get_merged_usrr-s)!!&))Z7722=OOr5debiancddlm}|tjvo |o|j }|||||||| | ||| | |||||||}t |S)a Generate a bug report template Parameters ---------- package : str package name pkgversion: str package version severity : str bug severity justification : str reason why critical severity is justified (if applicable) depinfo : str dependency information (like from :func:`get_dependency_info():func:`) confinfo : str config file information foundfile : str, optional the name of the file where the bug is incfiles : str, optional files to include in the report system : str, optional most often "debian" exinfo : int, debianbts.Bugreport or False number of the bug for which this message provides extra information type : str, optional should be either 'debbugs' or 'launchpad' klass : str, optional unused subject : str, optional could be bug report mail subject tags : str, optional tags to be set for this bug body : str, optional main report message text mode : int, optional reportbug mode (novice, expert, etc.) pseudos : str, optional pseudo-headers to include inline in the report body debsumsoutput : str, optional debsums error output text issource : bool, optional flag whether this report is on a source or binary package Returns ------- str bug report message template with inline system information r) bugreport)rNseverity justificationrDmodesubjecttagsbody pseudoheadersfollowuprsystemrsysinforincfiles debsumsoutputissource)rrrdebother buildd_formatrv)rrrrrr foundfilerrexinforklassrrrrpseudosrroptionsrrreps r3generate_blank_reportr9stg..ZG4YGDY@YG   gzH,9I#'t$,3f4%+Wg'/(,9H  N NC s88Or5ceZdZdZdZdS)our_lexz&Quote-removing lexical analyzer objectctj|}|t|s|S|d|dkr|d|jvr |dd}|S)z'Get token by token, with quotes removedNrr)rf get_tokenr=quotes)r!tokens r3rzour_lex.get_tokens` %%d++ =E =L !Hb ! !uQx4;'>'>!B$KE r5N)r0r1r2r3rr/r5r3rrs)00r5rz~/.reportbugrcz/etc/reportbug.conf)(sendtormuamtarrbtsverifyreplyto http_proxysmtphostr_debconfrsignnoccr dontquerynoconfmirrorskeyidheaders interfacetemplatercheck_available query_src printonlyoffline check_uidsmtptlssmtpuser smtppasswdparanoidmbox_reader_cmdmax_attachment_sizelistccmeoutfile draftpathtimeoutcLtjt S)z Check if user configuration file exists Unless reportbug is run for the first time, the user config file will often exist. Returns ------- bool True if reportbug is run for the first time )r8r9rUUSERFILEr/r5r3 first_runrsw~~h'' ''r5c i}tD]}tj|r t t |dd}n#t $rYQwxYw|jdz|_|}|r<| }|dvr||d<n|dkrZ| }|ttj vr||d<n|d kr1|d g|gz|d <no|d vr |d k|d <n`|dvr |dk|d<nQ|dvr |dk|d<nB|dvr |dk|d<n3|dvr |dk|d<n$|dvrd||<n|dvr|}|||<n|dvr |dk|d<n|dkrK| }|dvr||d<n|d krd!|d<n|d"krd#|d<n|d$krW| }|d%krd&}|ttj vr||d'<n=|d(krU| }|tt vr|||<n|d)krZ| }|ttj vr||d)<n|d*kr1|d+g|gz|d+<nK|d,vr |d-k|d.<n<|d/kr(| }n|t$vrt$||d0<n|d1vr |d2k|d3<n|d4vr |d5k|d5<n|d6vr |d7k|d7<n|d8vr |d9k|d:<n|d;vr |dkr'|}t'||d><nT|d?kr,| }||d?<n"t(jd@|z|}|<|S)Az Parse the reportbug configuration files Returns ------- dict dictionary with configuration parameter and their settings rrrsT)posixz-.@/:<>)quiet maintonlysubmitrrheaderr )no-ccccr&r) no-compresscompressr(r)z no-list-cc-me list-cc-mer*r) no-query-btsz query-btsr+r)rno-config-filesr,r)rr r)rrrrrr_rrrrrr rrr)z no-smtptlsrrr)pgpgpggnupgr.noneruigtk2gtkr rrmirrorr )zno-check-availablecheck-availabler5rreportbug_versionr) query-sourcezno-query-sourcer7r)rz no-debconfr)rz no-verifyr) check-uidz no-check-uidr8r)rz no-paranoidrrr envelopefromzUnrecognized token: %s )FILESr8r9rUrrr wordcharsrlowerrhr SEVERITIESrrQrMODESrrrrrwrite)argsrDlexrrrkrs r3parse_config_filesrBss D^(^( 7>>( # #] ( d84FGGGtTTT     MI5CMMMOOET ( <<<%*DNNj((MMOO1133EW%7%<%<%>%> ? ???+0Z(h&&&*hhy"&=&=@Q&QDOOo--$)W$4DLL999*/=*@D&&===(-(=D$$;;;)..)@D%%AAA&+/@&@DNNBBB"&DKKJJJ--//C"%DKK777', '9DOOf__MMOO1133E..',V '))',V &')V d]]MMOO1133E %]%7%9%9 : :::,1[)f__--////11Cd5::<<0000&)U e^^MMOO1133EW_%9%9%;%; < <<<&+U h&&&*hhy"&=&=@Q&QDOOGGG/48I/ID*++111 --//AAc\\"%e*DKKAAA)..)@D%%777', '9DOO555&+x&7DNN;;;).+)=D%%999(-(;D$$333--//C25c((D.//i''--//C&)#hhDOOn,,MMOO1133E+0D((J$$%?%%GHHH iT (l Ks A AAcdx}}g}g}t|d5}|}dddn #1swxYwY|D]}|}|d}t |dkr?|d|d} } | dkr| }j| d kr| }s| d kr|| d z }| d kr|| d z }||||fS) a Parse a packages bug control file Parameters ---------- filename : str bug control file name Returns ------- (str, str, [str, ...] , [str, ...]) tuple with (submit-as, send-to, report-with, package-status) control field values Nrrrsrr7rrz submit-aszsend-toz report-withrozpackage-status)rrrr;r=r<) rDsubmitassubmitto reportwith supplementalrrrpartsr%datas r3parse_bug_control_filerJsZHxJL h1 2 2 2b ,,zz|| 4   u::?? Qx~~''q [ HH y HH } $ $ $**S// )JJ ' ' ' DJJsOO +L Xz< 77s ;??cg}g}g}tjdtj}d}dx} } |D]@} || } | r'|| Adfdt D} |D]P}||} | r7| d}|| vr| |Q|tj D]H}| r|sd} ||} | ru|dkr | d| vs%|d krI| dd d kr*|| d} | rHd} | \}}|d d kr |}|||f| s>t|r/|d d kr#|d }|d |ddz|zf|d <!#| tkr||dzz }J|d kr!|D]\} }|r || d|gz }|| gz }|||fSi}g}|D]=\} }| tvr || d|gz }| dkr| |vr|| xxd|zz cc<8||| <>| D]} | |vr|| d|| gz }|||||fS)ad Clean up the bug report message Cleaning up consists of splitting off the headers and pseudo-headers from the message body. Two variants are distinguished, determined by the value of parameter `btstype`: - In "debbugs"-mode, pseudo-headers are recognized based on an internal list of known pseudoheader fields. This list can be extended using the `pseudos` parameter. Cleaning up includes making sure that only a single instance of non-repeatable pseudo-headers is present. If multiple instances are present in the input, the last one is used. - In "gnats"-mode, pseudo-headers start with the character '>'; the `pseudos` parameter is ignored. Headers not recognized as known pseudoheader fields are assumed to be proper headers. Parameters ---------- dmessage : str raw message. Headers and pseudoheaders found in the message will be split off and returned separately. headers : [str, ...] list of header strings. Headers and header content provided here are passed to the output. pseudos : [str, ...] list of additional fields to recognize as pseudoheaders. The field strings must include a colon; any further content after the colon is discarded. Field names must be capitalized. btstype : str should be either "debbugs" or "gnats" Returns ------- (str, [(str, str), ...], [str, ...]) tuple with three components: - "cleaned" message string - list of (header, content) tuples representing headers - list of pseudoheaders z^([^:]+):\s*(.*)$rTcfdd|dDS)N-c6g|]}|Sr/)rrs r3r4z/cleanup_msg..normph..{s @@@A@@@r5)r>r;)aphs r3normphzcleanup_msg..normphzs-xx@@3@@@AAAr5c&g|] }|Sr/r/)r0phrPs r3r4zcleanup_msg..}s!AAARffRjjAAAr5rFrgnatsr>rorr&rrr)rbrIrrTrr PSEUDOHEADERSrr;r8rr=r NEWBIELINEREPEATABLE_PSEUDOHEADERSr)dmessager rbtstype newheaderscollected_pseudoheadersclean_pseudoheadersheaderremessageparsing lastpseudor%mobaccepted_pseudoheadersrRrkeyvalue lastheadercontent unique_ph repeatable_phrPs @r3 cleanup_msgrj?sZJ z.55HGGj,,nnV$$  ,   cjjll + + +BBBBAAA=AAA22nnR    2 ! %%B///&--b111rz**!#!#  # ..&&C I--#VCIIaLL119OOO#w..399Q<<?c3I3I!!#**,,///"  ! !ZZ\\ Uq6S== &++C'..U|<<<< C OO Q3'^ ",Q-A1E1L!M 2 ZZ\\Z ' ' td{ "G'6 0 0OFG 0#FFFGG(D'EE###x/## $777IM2 ( ( - - - &&&'':; ;M  ^ # #)(;(; f    /    !(If  )LL Y    &8I8I$J#K K }--- J 3 33r5ct|||}|dSt\}} |D]}||dz||K ||z}n#t $r |d|}YnwxYwt j|}|s t j|dSt jd|zt j|dS#t j|wxYw)a  Download an mbox and open it in a mail user agent. Runs the command specified by cmd, passing the mbox file downloaded from url as a parameter. If cmd is None or fails, then fallback to mail program. Parameters ---------- cmd : str command to open the mbox file with, 'mail -f' if None url : str URL to download the mbox file from http_proxy : str http proxy timeout : int download connection timeout in seconds Returns ------- None Nr&rozmail -f ) rrrr?r TypeErrorr8runlink) r{urlrrmboxfdfnamererrors r3launch_mbox_readerrss'. CW - -D |**KROO%% " "D HHTD[ ! ! ! !  ? -Ek - - -!$ee, -IcNNE  % *u$%%% % %s6AC%.A43C%4BC%BC%8C%%C;c~tj}tj}|dkrd|zS|dkrd|zSdS)a Get the package of the currently running kernel Identifying the running kernel is needed to force assignment for 'kernel' package to a real one. Returns ------- str or None the name of the kernel package, unless it could not be determined Linuxz linux-image-z GNU/kFreeBSDzkfreebsd-image-N)platformrrelease)rrws r3get_running_kernel_pkgrxsP_  F  G '' > ! ! 7**tr5c rt\}}||d|dtj|dtj|}d}d}d}dx} x} } g} t |d5} | }dddn #1swxYwY|D]w}|dkrd } |d krd}|d krd }|d krd}&|d krd }/|dkrd}8|r| |z } @|r| |z } H|r(| |r| |z } xt||| | | | fS)a Execute and parse the output of the package bugscript Package bugscripts generate output that can be split into the following sections: headers, pseudo-headers, text, and a list of attachments. All sections are optional. This function executes a package bugscript and parses the ouput, identifying the section blocks, if present. Parameters ---------- handler : str name of an executable bugscript : str bugscript filename Returns ------- (int, str, str, [str, ...]) Tuple with 5 components: (returncode, headers, pseudoheaders, remaining text, list of attachments) z LC_ALL=C roFrrrrsNz-- BEGIN HEADERS -- Tz-- END HEADERS -- z-- BEGIN PSEUDOHEADERS -- z-- END PSEUDOHEADERS -- z-- BEGIN ATTACHMENTS -- z-- END ATTACHMENTS -- ) rrrfrgrrrTrr)handler bugscriptrunnerfhrDrc isheadersispseudoheaders isattachmentsr rr5 attachmentsrrrs r3exec_and_parse_bugscriptrs0::LBHHJJJ www I0F0F0F0F',{8'<'<'<> ? ?BIOM%''G'mdK h1 2 2 2b  * * *II * * *II 2 2 2"OO 0 0 0#OO 0 0 0 MM . . .!MM 4  %  ""4::<<0000 h k ::s=BB"%B"c\tjd}||rdndS)a Check the package name against Debian Policy Package names must comply with the policy requirements: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source Returns ------- bool True if the package name is valid. z^[a-z0-9][a-z0-9+-\.]+$TF)rbrr)r^pkg_res r3check_package_namerUs/Z2 3 3F<<$$ /44%/r5cTd}tjdrd}ntjddsd}ntjdrd }ntjd rhd } t d d 5}|d|z }dddn #1swxYwYnP#t$rYnDwxYwtjdr!tj dsd}|S)z Determines the init system on the current machine Returns ------- str the name of the init system, and how it was determined zunable to detectz/run/systemd/systemz!systemd (via /run/systemd/system)z+. /lib/lsb/init-functions ; init_is_upstartT)rpzupstart (via init_is_upstart())z/run/runit.stopitzrunit (via /run/runit.stopit)z /run/openrczOpenRC (via /run/openrc)z /proc/1/commrz , PID 1: Nz /sbin/initzsysvinit (via /sbin/init)) r8r9isdirrwcallisfilerr,r Exceptionr@)initpfs r3get_init_systemrfsb D w}}*+++2 _JRV W W W +0 + , , +. } % %+) nc** 8b7BGGIIOO$5$5777 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8    D   % %+bgnn\.J.J+* Ks6C-C  C CCCC C%$C%cvd}tjdrtjddgdkrd}tjdrtjdgdkr|d}n|dz }tjd gd }|d |dd zz }td d5}|}|D]B}| dr+|d| dddd zz }nCdddn #1swxYwY|S)z Determines the linux security module enabled on the current machine Returns ------- str or None Description of LSM info; None if there is no LSM enabled on the machine or if the state cannot be determined Nz/usr/bin/aa-enabledz--quietrzAppArmor: enabledz/usr/sbin/selinuxenabledzSELinux: enabled - z; SELinux: enabled - z/usr/sbin/getenforceasciiz Mode: %s - rz/etc/selinux/configrz SELINUXTYPE=zPolicy name: %s=r) r8r9rUrwr check_outputrzrrrr;)lsminfoenforce_statusrWrrs r3 get_lsm_inforsG w~~+,,& O2I> ? ?1 D D% w~~011 zHbGc7d7dhi7i7i ?+GG . .G#02H1IJJQQRYZZ=>#2##666 ' - - KKMME  ??>2204::c??13Ecrc3JJJGE                NsAD..D25D2cDgd}g}tjdrztd5}t |}dddn #1swxYwYt |D]"\}}|d|zzr||#|S)zX Determines the kernel taint flags Returns ------- list of strings )TAINT_PROPRIETARY_MODULETAINT_FORCED_MODULETAINT_CPU_OUT_OF_SPECTAINT_FORCED_RMMODTAINT_MACHINE_CHECKTAINT_BAD_PAGE TAINT_USER TAINT_DIETAINT_OVERRIDDEN_ACPI_TABLE TAINT_WARN TAINT_CRAPTAINT_FIRMWARE_WORKAROUNDTAINT_OOT_MODULETAINT_UNSIGNED_MODULETAINT_SOFTLOCKUPTAINT_LIVEPATCH TAINT_AUXTAINT_RANDSTRUCT TAINT_TESTz/proc/sys/kernel/taintedNr7)r8r9rUrrr, enumeraterT) TAINT_FLAGSflagsrtaintedrFflags r3get_kernel_taint_flagsrsK, E w~~011# , - - %"''))nnG % % % % % % % % % % % % % % % !-- # #GAtA~ # T""" Ls"A##A'*A'c8tjd}||}|sdS t|}dd|j|jDvrdSn#t $rYnwxYwd}d|d|fD]#}tj |rn$ tj |d 5}| }||vrt|D]j}|d kr,|d s|d sn%d |vrddddSkdddn #1swxYwYn#t $rYnwxYwdS)a Determine whether a given package is a security update Detection of security update versions works most reliably if the package version under investigation is the currently installed version. If this is not the case, the probability of false negatives increases. Parameters ---------- pkgname : str package name pkgversion : str package version Returns ------- bool True if there is evidence that this version is a security update, otherwise False z(\+|~)deb(\d+)u(\d+)FzDebian-Securitycg|] }|j Sr/)label)r0os r3r4z&is_security_update..s,!A!A!AQ!A!A!Ar5TNz%/usr/share/doc/{}/changelog.Debian.gzz/usr/share/doc/{}/changelog.gzrtrz -- rozCVE-20)rbrrjrrBoriginsrrr8r9rUgziprrrDrrrupper)rmrregex secversionryclrWlns r3is_security_updatersH8 J. / /Ej))J u w  !A!A!"J!7!?!A!A!A A A4 A      B6==gFF/66w??A 7>>"    E  Yr4 AB##kkmm  99;;"$$"--*?*?$r}}UXGYGY$Erxxzz)) *        5sT+A A*)A*>F BE>$ F 1E>2 F >FF FF FFr)T)F)rr)rrr)r)brr8rbrvr tempfilesrr ImportErrorrKrrexitrfr email.policyrrwrErurlutilsrmailerrrVrXr>MODELISTrexecrrrr reportbug.uirrWr?CODENAME2SUITEdictrhitemsSUITE2CODENAMECacherrCrSrYr`rdrmr}rrrrrrrrrobjectrr;r>rLrPrZrrrrrrrrrr MODE_EXPERTrrr9 expanduserrr: CONFIG_ARGSrrBrJrjrsrxrrrrrrr/r5r3rs. JJJ666666666xI%%  a     9 &=I*5B  C C 8 7 7 >>DDx~~d';';< <====&&&&&& = 7771.*)&%)#"022]]^EYEYE[E[@\@\]]]^^ SY[[ $$$N   %%%P4*Bqqq2::::z'3'3'3'3T$$$N###L111,<<<<089898989v wwww|11111f111h ! ! ! ! ! ! 88----`iiiiX0NNNNb2222j K J J 555p < < <& ' ' ' P P P8:B!)$T"$2B["&dU"& GGGGT     ek    7  . / / )'  ( ( (jjjZ$8$8$8NN4N4N4b***Z09; =;=;=;=;@000"<B---`JJJJJs A/AA