σ
Q+GPc           @@ s  d  d l  m Z m Z d  d l Z 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 rd  d l Z e d  e j d!  Z e j j    Z  e! e  j" d   n  d S("   i    (   t   absolute_importt   print_functionN(   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@ s   e  Z d  Z d   Z d   Z e d    Z d   Z d d d  Z	 d d d  Z
 d   Z d   Z e j d	 k  r d
   Z n  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   tgzA   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_memberV   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_fileg   s    c         C@ sυ   t  j |  } y |  j   j d |  } Wn& t k
 rT |  j   j |  } n X| d k	 rν t j d k r³ d d l } t	 | d  s d   | _
 n  | j | d | d | Sd d l } | d k rΤ d	 } n  | j | | d | Sn | Sd S(
   sΎ   Return a file object corresponding to a given file name.

        If encoding is given, then the file object will return Unicode data;
        otherwise, it will return binary data.
        s   ./t   3i    Nt   flushc           S@ s   d  S(   N(   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   <lambda>   s    t   encodingt   errorst   strict(   R   R)   R$   t   extractfilet   KeyErrorR   t   syst   versiont   iot   hasattrR.   t   TextIOWrappert   codecst   EncodedFile(   R   R'   R0   R1   t   fobjR7   R:   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   get_fileo   s     	c         C@ sD   |  j  | d | d | } d } | r@ | j   } | j   n  | S(   sΥ   Return the string content of a given file, or None (e.g. for
        directories).

        If encoding is given, then the content will be a Unicode object;
        otherwise, it will contain binary data.
        R0   R1   N(   R=   R   t   readt   close(   R   R'   R0   R1   t   ft   content(    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   get_content   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    R-   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(   RB   (   R   R'   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __getitem__₯   s    c         C@ s   |  j  j   d  S(   N(   R   R?   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR?   ¨   s    N(   R   R   t   __doc__R   R$   t   staticmethodR)   R,   R   R=   RB   RD   RE   R5   R6   RF   RG   R?   (    (    (    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.pyRJ   ¬   s   t
   DebControlc           B@ s)   e  Z d    Z d   Z d d 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,   RB   (   R   t   scriptsR'   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyRM   ³   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   RB   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 d | d | } i  } | d k rX d } n d } xp | j   D]b } | j |  j d d  \ } } t j	 d k rΓ t
 | t  rΓ | j   | | <qk | | | <qk W| j   | S(   sσ   Return a dictionary mapping filenames (of the data part) to
        md5sums. Fails if the control part does not contain a 'md5sum' file.

        Keys of the returned dictionary are the left-hand side values of lines
        in the md5sums member of control.tar.gz, usually file names relative to
        the file system root (without heading '/' or './').

        The returned keys are Unicode objects if an encoding is specified,
        otherwise binary. The returned values are always Unicode.s(   '%s' file not found, can't list MD5 sumsR0   R1   s   
i   R-   N(   R,   t   MD5_FILER   R=   R   t	   readlinest   rstript   splitR5   R6   t
   isinstancet   bytest   decodeR?   (	   R   R0   R1   t   md5_filet   sumst   newlinet   linet   md5R'   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR   Η   s    	!
N(   R   R   RM   RO   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyRK   ±   s   			t   DebFilec           B@ s   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 d 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   R_   R*   t	   INFO_PARTR   t   _DebFile__partsRK   t	   getmembert	   CTRL_PARTRJ   t	   DATA_PARTR   t   _DebFile__pkgnameR>   t   stript   _DebFile__versionR?   (   R   t   filenameR   R   Rg   R@   (    (   Rf   s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR   φ   s    				c         C@ s   |  j    d |  _ d  S(   Nt   package(   RO   Rm   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   __updatePkgName  s    c         C@ s   |  j  S(   N(   Ro   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR/     s    c         C@ s   |  j  t S(   N(   Ri   Rl   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR/     s    c         C@ s   |  j  t S(   N(   Ri   Rk   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR/     s    c         C@ s   |  j  j   S(   s    See .control.debcontrol() (   R   RO   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyRO     s    c         C@ s   |  j  j   S(   s    See .control.scripts() (   R   RM   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyRM   #  s    c         C@ s   |  j  j d | d |  S(   s    See .control.md5sums() R0   R1   (   R   R   (   R   R0   R1   (    (    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(   Rm   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    
c         C@ s   |  j  j   |  j j   d  S(   N(   R   R?   Rv   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR?   ;  s    N(   R   R   RH   R   R   Rs   t   propertyR6   Rv   R   RO   RM   R   Rx   R?   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyR\   η   s    				t   __main__Rp   i   (#   t
   __future__R    R   R   R!   R5   t   debian.arfileR   R   t   debian.changelogR   t   debian.deb822R   Rl   Rk   R]   Rh   RL   RN   Ru   Rt   RP   R   t   objectR   RJ   RK   R\   R   t   argvt   debR   R$   t   printRj   (    (    (    s2   /usr/lib/python2.7/dist-packages/debian/debfile.pyt   <module>   s2   6Y