ó
^;Tc           @   sÿ   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Td „  Z d d d „  ƒ  YZ d d d „  ƒ  YZ d d d	 „  ƒ  YZ d
 d d „  ƒ  YZ d d g Z d S(   iÿÿÿÿN(   t   *c         C   s?   i d d 6d d 6d d 6d d 6d d	 6} | j  |  j ƒ  d
 ƒ S(   Ni   t   lowi   t   mediumi   t   highi   t	   emergencyt   criticali   (   t   gett   lower(   t   ut   urgency_map(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   numeric_urgency*   s    

t   ControlStanzac           B   s;   e  Z e j d  ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   s   ^\S+ \((?P<version>.*)\).*c         C   s™   d  } xŒ | j d ƒ D]{ } | s& Pn  | d d k rc | r‘ t |  | t |  | ƒ d | ƒ q‘ q | j d d ƒ \ } } t |  | | j ƒ  ƒ q Wd  S(   Ns   
i    t    s   	t   :i   (   R   s   	(   t   Nonet   splitt   setattrt   getattrt   lstrip(   t   selft   strt   fieldt   linet   value(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   __init__7   s    'c         C   s    t  |  d |  j ƒ j d ƒ d S(   Nt   SourceR   i    (   R   t   PackageR   (   R   (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   sourceD   s    c         C   s)   t  |  d ƒ o( |  j j d ƒ d d k S(   Nt   StatusR   i   t	   installed(   t   hasattrR   R   (   R   (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR   G   s    c         C   s_   |  j  } t |  d ƒ r[ |  j j |  j ƒ } | r[ | j d ƒ } | j | ƒ sX | Sq[ n  | S(   sþ  
        This function returns the version of the package. One would like it to
        be the "binary" version, though we have the tough case of source
        package whose binary packages versioning scheme is different from the
        source one (see OOo, linux-source, ...).

        This code does the following, if the Source field is set with a
        specified version, then we use the binary version if and only if the
        source version is a prefix. We must do that because of binNMUs.
        R   t   version(   t   VersionR   t   source_version_ret   matchR   t   groupt
   startswith(   R   t   vR"   t   sv(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR   J   s    	
(	   t   __name__t
   __module__t   ret   compileR!   R   R   R   R   (    (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR   4   s
   			t   ControlParserc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   g  |  _  i  |  _ d  S(   N(   t   stanzast   index(   R   (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR   `   s    	c         C   s?   i  |  j  | <x+ |  j D]  } | |  j  | t | | ƒ <q Wd  S(   N(   R-   R,   R   (   R   R   t   stanza(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt	   makeindexd   s    c         C   sJ   |  j  g  t | d ƒ j ƒ  j d ƒ D] } | r& t | ƒ ^ q& 7_  d  S(   Nt   rs   

(   R,   t   opent   readR   R   (   R   t   filet   x(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   readfilei   s    c         C   s3   t  j d | ƒ } |  j j t | j ƒ  ƒ ƒ d  S(   Ns   dpkg-deb -f %s(   t   ost   popenR,   t   appendR   R2   (   R   t   debt   fh(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   readdebl   s    c         C   s~   |  j  j | ƒ r> |  j  | j | ƒ r7 |  j  | | Sd  Sn< x9 |  j D]. } t | | ƒ rH t | | ƒ | k rH | SqH Wd  S(   N(   R-   t   has_keyR   R,   R   R   (   R   R   R   R.   (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   findp   s    $(   R'   R(   R   R/   R5   R;   R=   (    (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR+   _   s
   				R   c           B   sM   e  Z e j d  ƒ Z d „  Z d d d „ Z d „  Z e	 d „ Z
 d „  Z RS(   s8   ^\S+ \((?P<version>.*)\) .*;.*urgency=(?P<urgency>\w+).*c         C   si   | |  _  t ƒ  } | j |  j  ƒ | j d } | j |  _ | j ƒ  |  _ | j ƒ  |  _ | j	 |  _
 d  S(   Ni    (   t   pathR+   R;   R,   R   t   binaryR   R   R    t   Architecturet   arch(   R   R>   t   parsert   pkgdata(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR      s    		c            s1  ˆ j  d ƒ } ˆ j  d ƒ } ˆ j  d ˆ j ƒ } ˆ j  d ƒ } g  } | d k sa | d k rq | j | ƒ n  | d k s‰ | d k r³ | j | ƒ | j | ƒ | j | ƒ n  ˆ j | ƒ ‰ ‡  ‡ ‡ ‡ f d †  }	 t |	 | d
 ƒ }
 t |	 | | d
 ƒ } t |	 | d
 ƒ } t j ˆ d	 ƒ |
 | | f S(   sÅ   Extract changelog entries, news or both from the package.
        If since_version is specified, only return entries later than the specified version.
        returns a sequence of Changes objects.s   NEWS.Debians   changelog.Debians   changelog.Debian.t	   changelogt   botht   newst
   changelogsc            s(   |  p' ˆ j  t j j ˆ | ƒ ˆ ˆ  ƒ S(   N(   t   read_changelogR6   R>   t   join(   t   acct   fname(   t   reverseR   t   since_versiont   tempdir(    s)   /usr/share/apt-listchanges/DebianFiles.pyt   <lambda>Ÿ   s    i   N(   t   _changelog_variationsRA   t   extendt   extract_contentst   reduceR   t   shutilt   rmtree(   R   t   whichRM   RL   t   news_filenamest   changelog_filenamest   changelog_filenames_binnmut   changelog_filenames_nativet	   filenamest
   find_firstRF   RD   t   binnmu(    (   RL   R   RM   RN   s)   /usr/share/apt-listchanges/DebianFiles.pyt   extract_changes‹   s$    c         C   sŸ   t  j d d ƒ } d |  j | d j g  | D] } d | d ^ q+ ƒ f } t j | ƒ } t j | ƒ r› t j | ƒ t j	 k r› t
 j | d ƒ t ‚ n  | S(   Nt   prefixs   apt-listchangessF   dpkg-deb --fsys-tarfile %s | tar xf - --wildcards -C %s %s 2>/dev/nullR   t   'i   (   t   tempfilet   mkdtempR>   RI   R6   t   systemt   WIFSIGNALEDt   WTERMSIGt   signalt   SIGINTRT   RU   t   KeyboardInterrupt(   R   R[   RN   R4   t   extract_commandt   status(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyRR   ©   s    	.'	c         C   sù  t  j  | ƒ } d  } xš | D]’ } y^ t j j | ƒ rQ t j t d ƒ | IJn- | j d ƒ rr t	 j
 | ƒ } n t | ƒ } PWq t k
 r­ } | j t j k r§ q® ‚  q Xq W| s¼ d  St d ƒ } d } g  }	 d }
 xž | j ƒ  D] } |  j j | ƒ } | rm|	 | g 7}	 d } d }
 | rmt j | j d ƒ | ƒ d k rft t | j d ƒ ƒ | ƒ } qjPqmn  | | 7} qç W|
 s…d  S| d k r¡|	 | g 7}	 n  | r´|	 j ƒ  n  d j |	 ƒ } | ræ| j d	 ƒ ræ| d
 7} n  t |  j | | ƒ S(   Ns(   Ignoring `%s' (seems to be a directory!)s   .gzR   t    i    i   R   t   urgencys   

s   
(   t   globR   R6   R>   t   isdirt   syst   stderrt   _t   endswitht   gzipt   GzipFileR1   t   IOErrort   errnot   ENOENTR
   t	   readlinest   changelog_headerR"   t   apt_pkgt   version_compareR#   t   maxRL   RI   t   ChangesR   (   R   t   filenameRM   RL   R[   t   fdt   eRl   t   entryt   entriest   is_debian_changelogR   R"   t   changes(    (    s)   /usr/share/apt-listchanges/DebianFiles.pyRH   »   sV    c         C   s9   d d d d d d d d g } g  | D] } | | ^ q% S(	   Ns   usr/doc/*/%s.gzs   usr/share/doc/*/%s.gzs   usr/doc/*/%ss   usr/share/doc/*/%ss   ./usr/doc/*/%s.gzs   ./usr/share/doc/*/%s.gzs   ./usr/doc/*/%ss   ./usr/share/doc/*/%s(    (   R   R~   t   formatsR4   (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyRP   ó   s    	N(   R'   R(   R)   R*   Ry   R   R   R^   RR   t   FalseRH   RP   (    (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR   |   s   		8R}   c           B   s   e  Z d  „  Z RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   packageR„   Rl   (   R   R‡   R„   Rl   (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR   ÿ   s    		(   R'   R(   R   (    (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyR}   þ   s   (    (    (    (    (   R)   Ro   R6   t   os.pathRa   Rs   Rv   Rm   RT   Rf   t
   subprocessRz   t   ALChacksR
   R   R+   R   R}   t   __all__(    (    (    s)   /usr/share/apt-listchanges/DebianFiles.pyt   <module>   s    $
	
+‚