
Tc        $   @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z y, d  d l Z d  d l m Z m Z m Z Wn: e	 k
 r Z
 e j   d k r q e
 GHe  j d  n Xd  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z m Z d Z e j j e d  Z e j j e d	  Z d Z i d d 6d d 6d d 6d d 6Z d d d d g Z x/ e D]' Z d e j    e j! e  f d UqlW[ d  d l" Z" d  d l# j$ Z% d  d  l& m' Z' d! Z( d" d# d$ d% d& d' d( d) g Z) i d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d2 6Z* d3   Z+ d4 d) d5 d6 d7 d8 g Z, d9   Z- d d:  Z/ d;   Z0 e1 d<  Z2 e1 d=  Z3 e4 d>  Z5 d?   Z6 d@   Z7 dA   Z8 dB dB dC  Z9 dB dB dD dE  Z: i  Z; e4 dF  Z< dG e= f dH     YZ> dI   Z? dJ   Z@ dK   ZA dL   ZB dM   ZC e4 dN  ZD dO   ZE dP dQ  ZF e4 dR  ZG d* d, d. d0 d2 g ZH dS   ZI dT   ZJ dU   ZK dV   ZL dB dB dW d d dB dB dB dB eM d d e4 dX  ZN dY   ZO dZ e j f d[     YZP e j jQ d\  ZR d] eR f ZS d ZT d d d     YZU d eU f d     YZV i eU d  d 6eU d  d 6eV   d 6eU d  d 6ZW eW d eW d <i d eW d 6d eW d 6d eW d 6d eW d 6ZX d   ZY d   ZZ d   Z[ d   Z\ d   Z] d   Z^ d   Z_ d   Z` d   Za d   Zb d   Zc d   Zd d S(   iN(   t   TempFilet   tempfile_prefixt   cleanup_temp_filet   Windowsi   (   t   open_url(   t   ascii_letterst   digitss   /var/lib/dpkgt	   availablet   statust   Packaget   Sourcet   Versiont   Severityt   Filet   Tagst   Justifications   Followup-Fort   Ownert   Usert   Usertagst	   Forwardedt   Controls4   Offer simple prompts, bypassing technical questions.t   novices   Offer more extensive prompts, including asking about things that a moderately sophisticated user would be expected to know about Debian.t   standardsR   Like standard, but assumes you know a bit more about Debian, including "incoming".t   advanceds   Bypass most handholding measures and preliminary triage routines.  This mode should not be used by people unfamiliar with Debian's policies and operating procedures.t   experts
   MODE_%s=%d(   t   AVAILABLE_UISsf  Dear 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 ***t   /s   /usrs
   /usr/shares   /vars
   /usr/X11R6s   /usr/mans   /usr/docs   /usr/bint	   oldstablet   squeezet   stablet   wheezyt   testingt   jessiet   unstablet   sidt   experimentalc         C   s   t  j j |   }  |  j d  } x t d t |  d  D] } d j | d | ! } | t k ri q; n  t  j j |  r; t  j	 |  } t  j j |  \ } } t  j j
 t  j j | |   } t t  j j | g | |  } t |  Sq; W|  S(   NR   i   i   i    (   t   ost   patht   abspatht   splitt   ranget   lent   joint   fhs_directoriest   islinkt   readlinkt   normpatht   applyt   realpath(   t   filenamet   bitst   it	   componentt   resolvedt   dirt   filet   newpath(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR0   b   s     ! s	   /usr/sbins   /sbins   /bins   /usr/X11R6/bins
   /usr/gamesc         C   s   t  j j |   \ } } | r( t |   St  j j d t  j  j d  } x* t D]" } | | k rP | j |  qP qP Wx? | D]7 } t  j j	 | |  } t  j j
 |  r} t |  Sq} Wd  S(   Nt   PATHR   (   R$   R%   R'   R0   t   environt   gett   defpatht   pathdirst   appendR*   t   existst   None(   R1   t   dt   fR%   t   fullname(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   search_path_forw   s     
!c         C   sI   d } x< |  t  j j d  t  j j d  | g D] } | r1 Pq1 q1 W| S(   s   Determine which editor program to use.

        :parameters:
          `specified_editor`
            Specified editor for reportbug, to be used in preference
            to other settings.

        :return value:
            Command to invoke for selected editor program.

        s   /usr/bin/sensible-editort   VISUALt   EDITOR(   R$   R:   R;   (   t   specified_editort   debian_default_editort   editor(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   which_editor   s    c         C   s   t  j d d |   }  |  S(   Ns
   ([*?\[\]])s   \\\1(   t   ret   sub(   R1   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   glob_escape   s    c         C   s`   t  j |   } | r= t j j d  r= t j d |  } n t } t j d |  } | | f S(   Ns   /usr/bin/dlocates$   COLUMNS=79 dlocate -S %s 2>/dev/nulls'   COLUMNS=79 dpkg --search %s 2>/dev/null(   t   commandst   mkargR$   R%   R?   t   popent   False(   t
   searchfilet   use_dlocatet   argt   pipe(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   search_pipe   s    c         C   s,  y t  j   } Wn t k
 r0 t  j d  n Xt |   } t | |  \ } } i  } x | D] } | j   } d | k r q_ n  | j d d  \ } }	 |	 j   }	 | j d  }
 x> |
 D]6 } | j |  r | | j	 |	  q |	 g | | <q Wq_ W| j
   | r"| r"t |  d t S|  | f S(   NR   s   diversion bys   : i   s   , RS   (   R$   t   getcwdt   OSErrort   chdirRM   RV   t   stripR'   t   has_keyR>   t   closet   query_dpkg_forRQ   (   R1   RS   t   xt   searchfilenameRU   t   dlocate_usedt   packagest   linet   packageR%   t   packlist(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR]      s,     
c         C   s   i  } |  j  d  rP t j d  } | j |   } d | | j d  <|  | f S|  d d k r t |   \ } } | r | | f Sn  t |   } | r | r |  d f St | p |   S(   s)   Find the package(s) containing this file.s   /var/lib/dpkg/info/s   /var/lib/dpkg/info/(.+)\.[^.]+t    i   i    R   N(   t
   startswithRK   t   compilet   matcht   groupR]   RD   R@   (   R1   t   pathonlyRa   t	   dpkg_infot   mt   fnt   pkglistt   newfilename(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   find_package_for   s    
 
c         C   s   x d g D] } t  j j |  r
 y t |  } Wn t k
 rH q
 n Xx | D]~ } | j   j d  d } | s{ qP n  y5 | j d  \ } } | j   |  k r | j   SWqP t k
 r d | GHd  SXqP Wq
 q
 Wd  S(   Ns   /etc/email-addressest   #i    t   :s   Invalid entry in %s(	   R$   R%   R?   R7   t   IOErrorRZ   R'   t
   ValueErrorR@   (   t   usernameR1   t   fpRb   t   namet   alias(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   find_rewritten   s"    	c         C   s   d |  k r t  S|  j d  d k r) t  S|  j d  \ } } | j d  s\ | j d  r` t  Sd | k rp t  S| j d  s | j d  r t  St S(   s   Simple check for email validityt   @i   t   .(   RQ   t   countR'   Rf   t   endswitht   True(   t   addrt	   localpartt
   domainpart(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   check_email_addr   s    c         C   s   t  j |   }  |  j d S(   Ni    (   t   rfc822t   AddressListt   addresslist(   R   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_email_addr   s    Re   c         C   s   t  t |  |   S(   N(   R   t   get_user_id(   t   emailt   realname(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt	   get_email  s    s   utf-8c         C   s   t  j   } t j |  } t  j j d |   pQ t  j j d  pQ t  j j d  }  |  pq t | d  pq | d }  d |  k r t  j j d  r t	 d  j
   j   } n t j   } |  d | }  n  d |  k s d |  k r t |   \ } }  n  | sut  j j d	  p0t  j j d
  p0t  j j d  } | su| d j d d  d } | j d | d j    } qun  | s|  St | t  r| j | d  } n  t j d |  rd | |  f St j | |  f  } t | t  r| j d d  } n  | S(   Nt   REPORTBUGEMAILt   DEBEMAILt   EMAILi    Rz   s   /etc/mailnamet   <t   (t   DEBFULLNAMEt   DEBNAMEt   NAMEi   t   ,i   t   &t   replaces   [\w\s]+$u   %s <%s>s   utf-8(   R$   t   getuidt   pwdt   getpwuidR:   R;   Ry   R%   R?   R7   t   readlineRZ   t   sockett   getfqdnR   R'   R   t   uppert
   isinstancet   strt   decodeRK   Rh   R   t   dump_address_pair(   R   R   t   charsett   uidt   infot
   domainnameR   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR     s8    $ $"c   -      C   s  | r |  t  k r t  |  St j d  } t j d  } t j d  } t j d  } t j d  } t j d  } t j d  } t j d  }	 t j d	  }
 t j d
  } t j d  } t j d  } t j d  } t j d  } t j d  } d  } } } } } d  } } } } } } g  } g  } g  } g  } g  }  t }! d }" y t j   }# Wn t k
 rt j d  n Xt	 j
 |   }$ | rt	 j d |$  }% n t	 j d |$  }% |% j d d  }% x|% j t j  D]}& |& j   }& |& sqn  |! rG|& d  d k r't }! qG| t j d |&  d g } n  | j |&  rq|& j d d  \ }' } q|
 j |&  r|& j d d  \ }' } q| j |&  r|& j d d  \ }' } q| j |&  r|& j d d  \ }' } q| j |&  r|& j d d  \ }' } q| j |&  rC|& j d d  \ }' } q| j |&  rm|& j d d  \ }' } q| j |&  r|& j d d  \ }' }( g  |( j d  D]2 }# g  |# j d  D] }) |) j   d ^ q^ q}( | j |(  q| j |&  rk|& j d d  \ }' }( g  |( j d  D]2 }# g  |# j d  D] }) |) j   d ^ q9^ q#}( | j |(  q| j |&  r|& j d d  \ }' }( g  |( j d  D]2 }# g  |# j d  D] }) |) j   d ^ q^ q}( |  j |(  q| j |&  rt }! q|	 j |&  r,|& j d d  \ }' } q| j |&  rf|& j d d  \ }' } | j   d } q| j |&  r|& j d d  \ }' } q| r|& d d k r| j |&  qqWt }* | r| j   d }" |" d$ k }* n  d  }+ | rt j |  }+ nk | rht j j |  rYt j | d  } t j | j d! d"  t j | d# f }+ qn| j   } n d } | | t |  t |  t |  | |* | | |+ | | | t j j |  |" t |   | f }, | s|, t  |  <n  |, S(%   Ns	   Version: s	   Package: s
   Priority: s   (Pre-)?Depends: s   Recommends: s
   Suggests: s
   Conffiles:s   Maintainer: s   Status: s   Origin: s   Bugs: s   Description: t    s   Source: s	   Section: Re   R   s,   COLUMNS=79 dpkg --print-avail %s 2>/dev/nulls'   COLUMNS=79 dpkg --status %s 2>/dev/nulls   utf-8R   i   s    /s    (.+) ([^ ]+)$i    s   : i   s   , t   |s   config-filess   not-installedRw   t   typet   debbugst   btsroot(   s   config-filess   not-installed(   t   statuscacheRK   Rg   R@   RQ   R$   RW   RX   RY   RN   RO   t	   getoutputR   R'   t   linesept   rstript   findallRh   t   extendR~   R>   R   t   parse_bts_urlt   SYSTEMSR[   R;   t
   capitalizet   tupleR*   (-   Rc   t   availt	   versionret	   packageret
   priorityret	   dependsret   recsret
   suggestsret   conffilesret   maintret   statusret   originret   bugsret   descret   fullret   srcret	   sectionret
   pkgversiont   pkgavailt
   maintainerR   t   origint   bugst   vendort   priorityt   desct   src_namet   sectiont	   conffilest   fulldesct   dependst
   recommendst   suggestst   confmodet   stateR^   t   packargt   outputRb   t   crudt   thisdependst   yt	   installedt
   reportinfoR   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_package_status3  s     	 EEE		!	t   AvailDBc           B   s2   e  Z d d d   Z d   Z d   Z d   Z RS(   c         C   s4   | |  _  | r | |  _ n | r0 | j |  _ n  d  S(   N(   t   popenobRv   t   stdout(   t   selfRv   R   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   __init__  s
    	c         C   s   |  S(   N(    (   R   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   __iter__  s    c         C   s   d } xe t  rm |  j r+ |  j j r+ Pq+ n  |  j j   } | sD Pn  | d k rT | S| | j d d  7} q	 W| rx | St  d  S(   Nu    s   
s   utf-8R   (   R~   R   t
   returncodeRv   R   R   t   StopIteration(   R   t   chunkRb   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   next  s    		c         C   so   |  j  rR x6 t rA |  j  j r" Pn  |  j j d  } | s Pq q W|  j  j   n  |  j rk |  j j   n  d  S(   Ni   (   R   R~   R   Rv   t   readt   waitR\   (   R   t   stuff(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   __del__  s    			N(   t   __name__t
   __module__R@   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR     s   		c          C   s[   y# t  t  }  |  r" t d |   SWn1 t k
 rV t j d It IJt j d  n Xd  S(   NRv   s   Unable to openi   (   t   opent   STATUSDBR   Rs   t   syst   stderrt   exit(   Rv   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_dpkg_database  s    c          C   s%   t  j d d t  j }  t d |   S(   Ns	   apt-cachet	   dumpavailR   R   (   s	   apt-cacheR   (   t
   subprocesst   Popent   PIPER   (   t   subp(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_avail_database  s    c         C   s}   t  j d t  j |    } | j d d  } t j d  } x9 | j d  D]( } | j |  } | rM | j d  SqM Wd  S(   Ns   apt-cache shows   utf-8R   s   ^Description(?:-en): (.*)$s   
i   (
   RN   R   RO   R   RK   Rg   R'   Rh   Ri   R@   (   Rc   t   dataR   Rb   Rl   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   available_package_description  s    c         C   s   g  } t  j d t  j |    } | j d d  } t j d  } x9 | j d  D]( } | j |  } | rS | j d  SqS Wd  S(   Ns   apt-cache showsrcs   utf-8R   s   ^Package: (.*)$s   
i   (
   RN   R   RO   R   RK   Rg   R'   Rh   Ri   R@   (   Rc   Ra   R   t   packreRb   Rl   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_source_name  s    c         C   s	  g  } g  } i  } t  j d t  j |    } | j d d  } t j d  } xZ | j d  D]I } | j |  } | r_ | j d  } t j d |  }	 | |	 7} q_ q_ WxL | D]D }
 t	 |
  } | r |
 | k r | |
 | f g 7} | | |
 <q q W| j
   | S(   Ns   apt-cache showsrcs   utf-8R   s   ^Binary: (.*)$s   
i   s   ,\s*(   RN   R   RO   R   RK   Rg   R'   Rh   Ri   R   t   sort(   Rc   Ra   t   retlistt   foundR   t   binreRb   Rl   t   packsRd   t   pR   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_source_package	  s&    
c         C   sN  |  s
 g  St    } d } i  } g  } g  } x: |  D]2 \ } } | | | <t j |  }	 | j |	  q2 Wd d j |  d d | d d j |  d | d g } | j   }
 i  } g  | D] } t j | t j  ^ q } t j d	 t j  } t j d
 t j  } t j d t j  } t j d t j  } g  } x~| D]v} xm| D]e} | j |  } | rN| j |  j	 d  } | j |  j	 d  } | j
   } | d d | d d } | d d k sN| d d k rqNn  | j	 d  d k r| j	 d  } n d  } | j |  j	 d  } | j |  j	 d  } | | | | | f } | j |  | j |  } | rx | D] } t | | <qWn  | | k rt | | <qqNqNWqAW| r| Sx |
 D]z } g  | D] } | | k r| ^ q} t |  t |  k r| | k rF| j d j |  d d d d  f  qFqqW| S(   Ns   (?:[\S]+(?:$|,\s+))s   ^(?P<hdr>Package):\s+(R   s   )$s   ^(?P<hdr>Provides):\s+s	   *(?P<pkg>s   )(?:$|,\s+)s   *$s   ^Package: (?P<pkg>.*)$s   ^Status: (?P<stat>.*)$s   ^Version: (?P<vers>.*)$s   ^Description: (?P<desc>.*)$t   pkgt   stati    i   R3   i   t   nt   hdrt   Providest   versR   s    | t   pns   <none>s   (no description available)(   R   RK   t   escapeR>   R*   t   valuesRg   t	   MULTILINEt   searchRi   R'   R@   R;   R~   R)   (   Ra   t   skip_notfoundt   packinfot   pkgnamet   groupfort
   searchpkgst
   searchbitsRi   Rc   t   escpkgt   groupsR   R^   t	   searchobst   packobt   statobt   versobt   descobt   retR  t   obRl   t   packR  t   sinfot   providesR	  R   R   t   itemt   notfound(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_package_info!  sj    	
*( %c         C   sT   t  |  f |  f g d t } g  } x) | D]! } | j | d | d f  q+ W| S(   NR  i    i   (   R#  R~   R>   (   Rc   t   aretR  R  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   packages_providingm  s
    s
   depends onc      	   C   s  | s d |  | f Sg  } x8 | D]0 } x' | D] } | j  t |  | f  q. Wq! Wd |  | f } i  } x_ t |  D]Q } | d }	 |	 | k r | | |	 <qx | d rx | |	 d s | | |	 <q qx qx W| j   }
 |
 j   g  } xN |
 D]F \ } } } } } | r | d | d 7} n  | j  | | | f  q W| }
 t g  |
 D] } t | d  ^ qJ } t g  |
 D] } t | d  ^ qs } t | d |  } t | d |  } xL |
 D]D \ } } } d	 j | | | d
 | d | } | | j	   d 7} qW| S(   Ns   
%s %s no packages.
s   
Versions of packages %s %s:
i    i   s    [t   ]i   iI   s4   {0:3.3} {1:{widthp}.{widthp}}  {2:{widthv}.{widthv}}t   widthpt   widthvs   
(
   R>   R   R#  R  R   t   maxR)   t   mint   formatR   (   Rc   R   t   relt   dependenciest   dept   bitt   depinfoR  R   R  t   deplistt   deplist2R  R   R	  R   R   R^   t   maxpt   maxvR'  R(  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_dependency_infou  s@    !


))c         C   s  i  } g  } x|  D] \ } } y t  |  } Wn  t k
 rQ } | | | <q n Xt j d t j |   j   d } | | k r q n  | j |  d }	 xZ | D]R }
 |
 s q n  |
 d k r | r q n  |
 d d k r | r q n  |	 |
 7}	 q W|	 j d d  | | <q W| | f S(   Ns   md5sum i    s	   changed:
s   
Rq   s   utf-8R   (   R7   Rs   RN   R   RO   R'   R>   R   (   R   t
   nocompresst   confinfot   changedR1   t   md5sumRv   t   msgt   filemd5t   thisinfoRb   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_changed_config_files  s.    
&    c          C   s  d }  } } } g  } t  j d  } | r2t j d t j  } i  } x | j |  D]u } | j d d  \ }	 }
 |
 t k r t |	  t j	 |
  } } n t |	  t
 t  } } t | | | |
 f <qX W| r2| j   } | j   | j   g  | D] } | d | d f ^ q } | d d }  q2n  y, t d  } | j   j   } | j   Wn t k
 r~t j d	 IJn X| r| d
 | d 7} n  |  r| d |  d 7} n  | rd j g  | D] } t |  ^ q } | d | 7} n  | r| | 7} n  | S(   NRe   s   apt-cache policy 2>/dev/nullsE   \s+(\d+)\s+.*$\s+release\s.*o=(Ubuntu|Debian|Debian Ports),a=([^,]+),i   i   i    i   s   /etc/debian_versions"   Unable to open /etc/debian_versions   Debian Release: s   
s     APT prefers s   , s     APT policy: %s
(   RN   R   RK   Rg   R  t   finditerRi   t	   DISTORDERt   intt   indexR)   R~   t   keysR   t   reverseR   R   RZ   R\   Rs   R   R   R*   R   (   t   debverst   debinfot   verfilet   warnt   distsR   t   mreR   Rh   t   pwordt   distnamet   prit   distR^   t   fobt	   policystr(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_debian_release_info  sD    

'(c           C   s   t  j d  d S(   Ns   lsb_release -a 2>/dev/nulls   
(   RN   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   lsb_release_info  s    c          C   sq   t  j d  }  |  sm t j   } | d }  t j d d |   }  t j d d |   }  t j d d |   }  n  |  S(	   Ns0   COLUMNS=79 dpkg --print-architecture 2>/dev/nulli   s   i[456]86t   i386t   s390xt   s390t   ppct   powerpc(   RN   R   R$   t   unameRK   RL   (   t   archt   un(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_arch  s    
c          C   s"   t  j d  }  d j |  j    S(   Ns9   COLUMNS=79 dpkg --print-foreign-architectures 2>/dev/nulls   , (   RN   R   R*   t
   splitlines(   t   out(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_multiarch  s    t   debianc      &   C   s   d d  l  } |  d k } | j  |  d | d | d | d | d | d	 | d
 | d | d | d |	 d |
 d | d | d | d | d | d | d | } t |  S(   Nit   wnpps   ftp.debian.orgt   versiont   severityt   justificationR1   t   modet   subjectt   tagst   bodyt   pseudoheaderst   followupR   t   systemR0  t   sysinfoR7  t   incfilest   debsumsoutputt   issource(   R_  s   ftp.debian.org(   t	   bugreportt   unicode(   Rc   R   Ra  Rb  R0  R7  t	   foundfileRk  Ri  t   exinfoR   t   klassRd  Re  Rf  Rc  t   pseudosRl  Rm  Rn  Rj  t   rep(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   generate_blank_report  s    c          C   s   d }  y t  d  } Wn t k
 r7 t j d IJd SXxR | D]J } | j d  ra |  d 7}  n  | j d  r? t | j   d  }  q? q? W| j   t |  d  S(   Ni    s   /proc/cpuinfos   Unable to open /proc/cpuinfot	   processori   s   cpus detectedi(	   R   Rs   R   R   Rf   R@  R'   R\   R)  (   t   cpucountRN  Rb   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_cpu_cores  s    
t   our_lexc           B   s   e  Z d    Z RS(   c         C   sj   t  j  j |   } | d  k s+ t |  r/ | S| d | d k rf | d |  j k rf | d d !} n  | S(   Ni    ii   (   t   shlext	   get_tokenR@   R)   t   quotes(   R   t   token(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR{  +  s     '(   R   R   R{  (    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyRy  *  s   s   ~/.reportbugrcs   /etc/reportbug.conft   sendtoRa  t   muat   mtaR   R   t   btst   verifyt   replytot
   http_proxyt   smtphostRI   t   debconfRb  t   signt   noccR6  t	   dontqueryt   noconft   mirrorst   keyidt   headerst	   interfacet   templateRc  t   check_availablet	   query_srct	   printonlyt   offlinet	   check_uidt   smtptlst   smtpusert
   smtppasswdt   paranoidt   mbox_reader_cmdt   max_attachment_sizet   Muac           B   s/   e  Z d  Z d  Z d   Z d   Z d   Z RS(   Re   c         C   s    | |  _  | j   d |  _ d  S(   Ni    (   t   commandR'   Rw   (   R   R  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR   A  s    	c         C   s@   |  j  } d | k r" | d 7} n  t j | t j |  d  S(   Ns   %ss    %si   (   R  t   uiRi  RN   RO   (   R   R1   R  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   sendE  s    	c         C   s   |  j  S(   N(   Rw   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_nameK  s    (   R   R   R  Rw   R   R  R  (    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR  =  s
   		t   Gnusc           B   s    e  Z d  Z d   Z d   Z RS(   t   gnusc         C   s   d  S(   N(    (   R   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR   Q  s    c         C   sE   d } t  j d d |  } t j | |  } t j d | | f  S(   Ns   (progn
                      (load-file "/usr/share/reportbug/reportbug.el")
                      (tfheen-reportbug-insert-template "%s"))s   ["\\]s   \\\g<0>s>   emacsclient --no-wait --eval %s 2>/dev/null || emacs --eval %s(   RK   RL   RN   RO   R  Ri  (   R   R1   t   elisp(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR  T  s
    	(   R   R   Rw   R   R  (    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyR  N  s   	s   mutt -Ht   mutts   /usr/bin/mh/comp -use -filet   mhR  s   claws-mail --compose-from-files
   claws-mailt   nmhs   mutt -vs   emacs --versions   claws-mail --versionc         C   s   |  d k s |  t  d k r% d } n |  d k sA |  t  d k rJ d } nu |  d k sf |  t  d k ro d } nP |  d k s |  t  d k r d } n+ |  d k s |  t  d k r d } n |  } | t  k r t St Sd  S(   NR  R  R  R  s
   claws-mail(   t   MUARQ   R~   (   R  t   mua_tmp(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   mua_is_supportedm  s    					c         C   s  |  d k s |  t  d k r) t  d } n |  d k sE |  t  d k rR t  d } n |  d k sn |  t  d k r{ t  d } n\ |  d k s |  t  d k r t  d } n3 |  d k s |  t  d k r t  d } n
 t  |  } d } t j j |  rZy5 t j t | d t | d  d	 t j d
 t	 } Wqst
 t f k
 rVt j t | d
 t	 } qsXn t j t | d
 t	 } | d k rt St	 Sd  S(   NR  R  R  R  s
   claws-mails	   /dev/nullR   t   wR   t   shelli   (   R  R$   R%   R?   R   t   callt
   MUAVERSIONR   t   STDOUTR~   Rs   RX   RQ   (   R  R  R   t   returnvalue(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt
   mua_exists  s*    
5 c         C   s   |  t  k r t  |  S|  Sd  S(   N(   R  (   R  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   mua_name  s    c           C   s   t  j j t  S(   N(   R$   R%   R?   t   USERFILE(    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt	   first_run  s    c          C   s  i  }  xt  D]} t j j |  r y t t |  d t } Wn t k
 rY } q n X| j d | _ | j	   } x[| r| j
   } | dI k r | |  d <n| d k r | j	   j
   } | t j j   k r| |  d <qn| d k r|  j d	 g   | j	   g |  d	 <n| dJ k r8| d
 k |  d <n| dK k rW| d k |  d <nj| dL k rv| d k |  d <nK| dM k r| d k |  d <n,| dN k rt |  | <n| dO k r| j	   } | j d& d'  |  | <n| dP k r| d) k |  d) <n| d* k rj| j	   j
   } | dQ k r5| |  d* <q| d- k rNd, |  d* <q| d. k rd/ |  d* <qnW| d0 k r| j	   j
   } | t j   k r| |  d1 <qn| d2 k r| j	   j
   } | t j   k r| |  | <qn| d3 k r-| j	   j
   } | t j j   k r| |  d3 <qn| d4 k r_|  j d5 g   | j	   g |  d5 <nb| dR k r~| d7 k |  d8 <nC| d9 k r| j	   j
   } n"| t k rt | |  d <n| dS k r| d: k |  d< <n | dT k r| d= k |  d= <n | dU k r| d? k |  d? <n | dV k r8| dA k |  dC <n | dW k rW| dD k |  dD <nj | dF k r| j	   } t |  |  dF <n? | dG k r| j	   j
   } | |  dG <n t j j dH |  | j	   } qy Wq q W|  S(X   Nt   posixs   -.@/:<>t   quiett	   maintonlyt   submitR~  Ra  t   headerR  s   no-cct   ccR  s   no-compresst   compressR6  s   no-query-btss	   query-btsR  s   config-filess   no-config-filesR  R  R  R  R   R   R  R  R  RI   R  R  R  R  Rb  R  R  s   utf-8R   s
   no-smtptlsR  R  t   pgpt   gpgt   gnupgt   noneRe   R  R  Rc  R  t   mirrorR  s   no-check-availables   check-availableR  t   reportbug_versions   query-sources   no-query-sourceR  R  s
   no-debconfR  s	   no-verifys	   check-uids   no-check-uidR  R  s   no-paranoidR  t   envelopefroms   Unrecognized token: %s
(   R  R  R  (   s   no-ccR  (   s   no-compressR  (   s   no-query-btss	   query-bts(   s   config-filess   no-config-files(   R  s   templateR  (   s   emails   realnameR  s
   http_proxyR  s   editors   muaR  R  R  s   justificationR  R  (   s
   no-smtptlsR  (   R  R  (   s   no-check-availables   check-available(   s   query-sources   no-query-source(   R  s
   no-debconf(   R  s	   no-verify(   s	   check-uids   no-check-uid(   R  s   no-paranoid(   t   FILESR$   R%   R?   Ry  R7   R~   Rs   t	   wordcharsR{  t   lowerR   t
   SEVERITIESRB  R;   R   R   t   MODESR   R  R@  R   R   t   write(   t   argsR1   t   lexR:  R}  R/  RT   t	   w_version(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   parse_config_files  s    	  	c   
      C   s   d  } } g  } g  } t |   } x | D] } | j   } | j d  } t |  d k rb q) n  | d j   | d } }	 | d k r |	 } q) | d k r |	 } q) | d k r | |	 j d  7} q) | d	 k r) | |	 j d  7} q) q) W| | | | f S(
   Ns   : i   i    i   s	   submit-ass   send-tos   report-withR   s   package-status(   R@   R7   RZ   R'   R)   R  (
   R1   t   submitast   submittot
   reportwitht   supplementalt   fhRb   t   partsR  R   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   parse_bug_control_file  s&    
		c         C   s  g  } t  j d t  j  } d } } t } }	 g  }
 x9 | D]1 } | j |  } | r< |
 j | j    q< q< Wg  } x< | D]4 } | j |  } | r~ | j | j d   q~ q~ Wx|  j t	 j
  D]} | r | r t } q | rT| j |  } | rz| d k r6| j d  t k r6| j d  | k s[| d k rz| j d  d d k rz|
 j | j    t }	 q qw| rt }	 | j   \ } } | d d k rd j g  | j d  D] } | j   ^ q } n  | j | | f  qw|	 r5t |
  r5|
 d	 } | d | d d
 | f |
 d	 <q qw| j t  j d | d   q | j   t k r | | d
 7} q q Wg  } | d k rx| D]9 \ } } | r| d | | f g 7} q| | g 7} qWn i  } t t  } x* | D]" } | | k r| j |  qqWx@ | D]8 \ } } | | k r?| | | <q|
 j | | f  qWx8 | D]0 } | | k r]| d | | | f g 7} q]q]W| |
 | f S(   Ns   ^([^:]+):\s*(.*)$Re   i   R   t   gnatsi    t   >t   -is   
s   :\s+s   %s: %s(   RK   Rg   t   IR~   Rh   R>   R  Ri   R'   R$   R   RQ   t   PSEUDOHEADERSR*   R   R)   RZ   t
   NEWBIELINEt   list(   t   dmessageR  Rs  R   Rg  t   headerret
   newsubjectt   messaget   parsingt
   lastpseudot
   newheadersR  t   mobt   PSEUDOSt   phRb   t   keyt   valueR^   t
   lastheadert   contentt   ph2t   pseudo_listR  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   cleanup_msg  st    

	%4
 "c   	      C   s   t  | | |  } | d k r" d St   \ } } z x | D] } | j |  q; W| j   |  d k	 r y |  | }  Wn! t k
 r d |  | f }  n Xt j |   } | s d Sn  t j d |  Wd t j |  Xd S(   s   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.Ns   %s %ss   mail -f (	   R   R@   R    R  R\   t	   TypeErrorR$   Ri  t   unlink(	   t   cmdt   urlR  t   timeoutt   mboxt   fdt   fnameRb   t   error(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   launch_mbox_readerq  s$    
c          C   sH   t  j   }  t  j   } |  d k r, d | S|  d k r@ d | Sd Sd S(   su   Return the package of the currently running kernel, needed to force
    assignment for 'kernel' package to a real onet   Linuxs   linux-image-s   GNU/kFreeBSDs   kfreebsd-image-N(   t   platformRi  t   releaseR@   (   Ri  R  (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_running_kernel_pkg  s    c         C   s  t    \ } } | j   t j d |  t j |  t j |  f  } t } t } t } d } }	 }
 g  } t |  } x | j   D] } | d k r t	 } q | d k r t } q | d k r t	 } q | d k r t } q | d k r t	 } q | d k r
t } q | r| | 7} q | r0|	 | 7}	 q | rL| j
 | j    q |
 | 7}
 q W| j   t |  |
 j d	 d
  }
 | | |	 |
 | f S(   s   Execute and parse the output of the package bugscript, in particular
    identifying the headers and pseudo-headers blocks, if presents   LC_ALL=C %s %s %sRe   s   -- BEGIN HEADERS --
s   -- END HEADERS --
s   -- BEGIN PSEUDOHEADERS --
s   -- END PSEUDOHEADERS --
s   -- BEGIN ATTACHMENTS --
s   -- END ATTACHMENTS --
s   utf-8R   (   R    R\   R$   Ri  RN   RO   RQ   R   t	   readlinesR~   R>   RZ   R   R   (   t   handlert	   bugscriptR  R1   t   rct	   isheaderst   ispseudoheaderst   isattachmentsR  Rg  t   textt   attachmentsRv   Rb   (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   exec_and_parse_bugscript  sD    
						

c         C   s&   t  j d  } | j |   r" t St S(   s   Check the package name against Debian Policy:
    https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source

    Returns True if the package name is valid.s   ^[a-z0-9][a-z0-9+-\.]+$(   RK   Rg   Rh   R~   RQ   (   R  t   pkg_re(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   check_package_name  s    c          C   sq   d }  t  j j d  r! d }  n  t j d d t s? d }  n. t  j j d  rm t  j j d  rm d }  n  |  S(	   s1   Determines the init system on the current machines   unable to detects   /run/systemd/systems!   systemd (via /run/systemd/system)s+   . /lib/lsb/init-functions ; init_is_upstartR  s   upstart (via init_is_upstart())s
   /sbin/inits   sysvinit (via /sbin/init)(   R$   R%   t   isdirR   R  R~   t   isfileR,   (   t   init(    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   get_init_system  s    		%	(   R	   R
   R   R   R   R   R   s   Followup-ForR   R   R   R   R   ($   s   sendtos   severitys   muas   mtas   emails   realnames   btss   verifys   replytos
   http_proxys   smtphosts   editors   debconfs   justifications   signs   noccs
   nocompresss	   dontquerys   noconfs   mirrorss   keyids   headerss	   interfaces   templates   modes   check_availables	   query_srcs	   printonlys   offlines	   check_uids   smtptlss   smtpusers
   smtppasswds   paranoids   mbox_reader_cmds   max_attachment_size(    (e   R   R$   RK   R  R   t	   tempfilesR    R   R   t   ImportErrort   eRi  R   RN   Rz  R   R   R   t   urlutilsR   t   stringR   R   t   DPKGLIBR%   R*   t   AVAILDBR   R  R  t   MODELISTRc  R   RA  R   t
   ui.text_uit   text_uiR  t   reportbug.uiR   R  R+   t   SUITES2DISTSR0   R=   RD   R@   RJ   RM   R~   RV   R]   RQ   Rp   Ry   R   R   R   R   R   R   t   objectR   R   R   R   R   R  R#  R%  R5  R=  R?  RP  RQ  RZ  R]  t   MODE_EXPERTRu  Rx  Ry  t
   expanduserR  R  t   CONFIG_ARGSR  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s3   /usr/lib/python2.7/dist-packages/reportbug/utils.pyt   <module>   s      

%

								,-				
		L	3	-		
		     
					_		U			,	
