ó
ÍÿŠTc           @   sÔ   d  d l  m Z d  d l Z d Z d Z d Z d Z d Z d e BZ d e BZ	 d e BZ
 d e BZ d e BZ d e BZ d e BZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d „ Z e e d „ Z d S(   iÿÿÿÿ(   t   sha1Ni   i    i   i   i   i   i   i   i   t   PackageTypeErrorc           B   s   e  Z d  Z RS(   sD   Raised when an unsupported package type is passed to build_skeleton.(   t   __name__t
   __module__t   __doc__(    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyR      s   t   PackageSkeletonc           B   sP   e  Z d Z d Z d Z d Z d Z d Z d  „  Z	 d „  Z
 d „  Z d „  Z RS(   c         C   s(   | |  _  | |  _ | |  _ g  |  _ d  S(   N(   t   typet   namet   versiont	   relations(   t   selfR   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   __init__"   s    			c         C   s   |  j  j | | f ƒ d  S(   N(   R	   t   append(   R
   R   t   info(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   add_relation(   s    c         C   st   |  j  d k	 r |  j  St d |  j |  j |  j f ƒ } |  j j ƒ  x" |  j D] } | j d | ƒ qO W| j	 ƒ  S(   sš   Calculate the package hash.

        If C{set_hash} has been used, that hash will be returned and the
        hash won't be the calculated value.
        s
   [%d %s %s]s   [%d %s]N(
   t   _hasht   NoneR    R   R   R   R	   t   sortt   updatet   digest(   R
   R   t   pair(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   get_hash+   s    "c         C   s   | |  _  d S(   sZ  Set the hash to an explicit value.

        This should be used when the hash is previously known and can't
        be calculated from the relations anymore.

        The only use case for this is package resurrection. We're
        planning on getting rid of package resurrection, and this code
        can be removed when that is done.
        N(   R   (   R
   t   package_hash(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   set_hash9   s    
N(   R   R   R   t   sectiont   summaryt   descriptiont   sizet   installed_sizeR   R   R   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyR      s   			c         C   s6   |  \ } } } | } | r2 | d | | f 7} n  | S(   s  Convert an apt relation to a string representation.

    @param relation_tuple: A tuple, (name, version, relation). version
        and relation can be the empty string, if the relation is on a
        name only.

    Returns something like "name > 1.0"
    s    %s %s(    (   t   relation_tupleR   R   t   relation_typet   relation_string(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   relation_to_stringG   s
    	c         C   s›   t  ƒ  } t j |  j | d ƒ ƒ } xp | D]h } g  | D] } t | ƒ ^ q8 } | }	 t | ƒ d k rq | }	 n  d j | ƒ }
 | j |	 |
 f ƒ q+ W| S(   s¬  Parse an apt C{Record} field and return skeleton relations

    @param record: An C{apt.package.Record} instance with package information.
    @param record_field: The name of the record field to parse.
    @param relation_type: The deb relation that can be passed to
        C{skeleton.add_relation()}
    @param or_relation_type: The deb relation that should be used if
        there is more than one value in a relation.
    t    i   s    | (   t   sett   apt_pkgt   parse_dependst   getR    t   lent   joint   add(   t   recordt   record_fieldR   t   or_relation_typeR	   t   valuest   valuet   relationt   value_stringst   value_relation_typeR   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   parse_record_fieldW   s    		c         C   sã  |  j  j |  j } } | r8 t | ƒ t | ƒ } } n  t t | | ƒ } t ƒ  } | j t |  j	 d t
 ƒ ƒ | j t d |  j  j |  j f f ƒ | j t |  j	 d t t ƒ ƒ | j t |  j	 d t t ƒ ƒ | j t d |  j  j |  j f f ƒ | j t |  j	 d t ƒ ƒ | j t |  j	 d t ƒ ƒ t | ƒ | _ | rß|  j | _ |  j | _ |  j | _ |  j | _ |  j d k r”|  j | _ n  | rß| j j d	 ƒ | _ | j j d	 ƒ | _ | j j d	 ƒ | _ qßn  | S(
   sS  Build a package skeleton from an apt package.

    @param version: An instance of C{apt.package.Version}
    @param with_info: Whether to extract extra information about the
        package, like description, summary, size.
    @param with_unicode: Whether the C{name} and C{version} of the
        skeleton should be unicode strings.
    t   Providess   %s = %ss   Pre-Dependst   Dependss   %s < %st	   Conflictst   Breaksi    s   utf-8(   t   packageR   R   t   unicodeR   t   DEB_PACKAGER"   R   R1   R)   t   DEB_PROVIDESR(   t   DEB_NAME_PROVIDESt   DEB_REQUIRESt   DEB_OR_REQUIRESt   DEB_UPGRADESt   DEB_CONFLICTSt   sortedR	   R   R   R   R   R   t   decode(   R   t	   with_infot   with_unicodeR   t   version_stringt   skeletonR	   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   build_skeleton_aptn   sB    					 		i   i   i   i   i   i   i   i   i   i   i   i   (   t   landscape.lib.hashlibR    R#   t   PACKAGEt   PROVIDESt   REQUIRESt   UPGRADESt	   CONFLICTSR8   R9   R:   R;   R<   R=   R>   t	   ExceptionR   t   objectR   R    R   R1   t   FalseRE   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/skeleton.pyt   <module>   s$   






.	