ó
ñ±$Nc           @   s\  d  d l  Z  d  d l Z d  d l m Z m Z d  d l m Z d  d l m Z d Z	 d Z
 d d d	 g a d
 Z d d d d d g Z d Z d Z d Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d k rXd  d l Z e d e j d  ƒ Z e j j ƒ  Z e j d ƒ GHn  d S(!   iÿÿÿÿN(   t   ArFilet   ArError(   t	   Changelog(   t   Deb822s   data.tars   control.tart   gzt   bz2t   lzmas   debian-binaryt   preinstt   postinstt   prermt   postrmt   configt   controls   usr/share/doc/%s/changelog.gzs$   usr/share/doc/%s/changelog.Debian.gzt   md5sumst   DebErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR   %   s   t   DebPartc           B   sn   e  Z d  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z RS(   sW  'Part' of a .deb binary package.
    
    A .deb package is considered as made of 2 parts: a 'data' part
    (corresponding to the 'data.tar.gz' 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; supported compression formats are: .tar.gz, .tar.bz2 .

    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         C   s   | |  _  d  |  _ d  S(   N(   t   _DebPart__membert   Nonet   _DebPart__tgz(   t   selft   member(    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __init__:   s    	c         C   s­   |  j  d k r¦ |  j j } | j d ƒ rc t j d |  j d d ƒ } t j d | d d ƒ |  _  q¦ | j d ƒ r“ t j	 d |  j d d ƒ |  _  q¦ t
 d | ƒ ‚ n  |  j  S(	   sÝ   Return 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.
        s   .gzt   fileobjt   modet   rs   .bz2s   r:bz2s"   part '%s' has unexpected extensionN(   R   R   R   t   namet   endswitht   gzipt   GzipFilet   tarfilet   TarFilet   openR   (   R   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   tgz>   s    !c         C   s<   |  j  d ƒ r |  d }  n |  j  d ƒ r8 |  d }  n  |  S(   sw    try (not so hard) to obtain a member file name in a form relative
        to the .tar.gz root and with no heading '.' s   ./i   t   /i   (   t
   startswith(   t   fname(    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __normalize_memberS   s
    c         C   s;   t  j | ƒ } |  j ƒ  j ƒ  } d | | k p: | | k S(   s.   Check if this part contains a given file name.s   ./(   R   t   _DebPart__normalize_memberR"   t   getnames(   R   R%   t   names(    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   has_filed   s    c         C   sR   t  j | ƒ } y |  j ƒ  j d | ƒ SWn! t k
 rM |  j ƒ  j | ƒ SXd S(   s8   Return a file object corresponding to a given file name.s   ./N(   R   R'   R"   t   extractfilet   KeyError(   R   R%   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   get_filel   s
    c         C   s8   |  j  | ƒ } d } | r4 | j ƒ  } | j ƒ  n  | S(   sR   Return the string content of a given file, or None (e.g. for
        directories).N(   R-   R   t   readt   close(   R   R%   t   ft   content(    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   get_contentu   s    c         C   s   t  |  j ƒ  j ƒ  ƒ S(   N(   t   iterR"   R(   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __iter__‚   s    c         C   s   |  j  | ƒ S(   N(   R*   (   R   R%   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __contains__…   s    c         C   s   |  j  | ƒ S(   N(   R*   (   R   R%   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   has_keyˆ   s    c         C   s   |  j  | ƒ S(   N(   R2   (   R   R%   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __getitem__‹   s    (   R   R   t   __doc__R   R"   t   staticmethodR'   R*   R-   R2   R4   R5   R6   R7   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR   )   s   									t   DebDatac           B   s   e  Z RS(    (   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR:      s   t
   DebControlc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s@   i  } x3 t  D]+ } |  j | ƒ r |  j | ƒ | | <q q W| S(   so    Return a dictionary of maintainer scripts (postinst, prerm, ...)
        mapping script names to script text. (   t   MAINT_SCRIPTSR*   R2   (   R   t   scriptsR%   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR=   –   s
    c         C   s   t  |  j t ƒ ƒ S(   s¾    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') (   R   R2   t   CONTROL_FILE(   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt
   debcontrol¡   s    c         C   s‡   |  j  t ƒ s" t d t ƒ ‚ n  |  j t ƒ } i  } x? | j ƒ  D]1 } | j d ƒ j d d ƒ \ } } | | | <qD W| j ƒ  | S(   sf   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 './'). s(   '%s' file not found, can't list MD5 sumss   
i   N(	   R*   t   MD5_FILER   R-   t	   readlinest   rstript   splitR   R/   (   R   t   md5_filet   sumst   linet   md5R%   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR   ª   s    !
(   R   R   R=   R?   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR;   ”   s   			t   DebFilec           B   sz   e  Z d  Z d d d d „ Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z RS(   sÊ  Representation 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 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
    R   c            sÞ   t  j |  | | | ƒ t |  j ƒ  ƒ ‰  ‡  f d †  } t ˆ  k rV t d t ƒ ‚ n  i  |  _ t |  j | t	 ƒ ƒ ƒ |  j t	 <t
 |  j | t ƒ ƒ ƒ |  j t <d  |  _ |  j t ƒ } | j ƒ  j ƒ  |  _ | j ƒ  d  S(   Nc            sˆ   g  t  D] } d |  | f ^ q } ˆ  j t | ƒ ƒ } | sQ t d | ƒ ‚ n3 t | ƒ d k rv t d | ƒ ‚ n t | ƒ d Sd  S(   Ns   %s.%ss9   missing required part in given .deb (expected one of: %s)i   s>   too many parts in given .deb (was looking for only one of: %s)i    (   t	   PART_EXTSt   intersectiont   setR   t   lent   list(   t   basenamet   extt
   candidatest   parts(   t   actual_names(    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   compressed_part_nameÓ   s    #s4   missing required part in given .deb (expected: '%s')(   R    R   RK   R(   t	   INFO_PARTR   t   _DebFile__partsR;   t	   getmembert	   CTRL_PARTR:   t	   DATA_PARTR   t   _DebFile__pkgnameR.   t   stript   _DebFile__versionR/   (   R   t   filenameR   R   RS   R0   (    (   RR   s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR   Ï   s    				c         C   s   |  j  ƒ  d |  _ d  S(   Nt   package(   R?   RY   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __updatePkgNameï   s    c         C   s   |  j  S(   N(   R[   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   <lambda>ò   s    c         C   s   |  j  t S(   N(   RU   RX   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR_   ó   s    c         C   s   |  j  t S(   N(   RU   RW   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR_   ô   s    c         C   s   |  j  j ƒ  S(   s    See .control.debcontrol() (   R   R?   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR?   ø   s    c         C   s   |  j  j ƒ  S(   s    See .control.scripts() (   R   R=   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR=   ü   s    c         C   s   |  j  j ƒ  S(   s    See .control.md5sums() (   R   R   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR      s    c         C   s•   |  j  d k r |  j ƒ  n  xr t |  j  t |  j  g D]V } |  j j | ƒ r7 t j d |  j j	 | ƒ ƒ } | j
 ƒ  } | j ƒ  t | ƒ Sq7 Wd S(   s†    Return a Changelog object for the changelog.Debian.gz of the
        present .deb package. Return None if no changelog can be found. R   N(   RY   R   t   _DebFile__updatePkgNamet   CHANGELOG_DEBIANt   CHANGELOG_NATIVEt   dataR*   R   R   R-   R.   R/   R   (   R   R%   R   t   raw_changelog(    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt	   changelog  s    
N(   R   R   R8   R   R   R`   t   propertyt   versionRc   R   R?   R=   R   Re   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyRH   À   s    				t   __main__R\   i   (   R   R   t   arfileR    R   Re   R   t   deb822R   RX   RW   RI   RT   R<   R>   Rb   Ra   R@   R   t   objectR   R:   R;   RH   R   t   syst   argvt   debR   R"   RV   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   <module>   s.   f,U