ó
¹¢ºSc           @   sÉ   d  Z  d d l m Z d d l Z d d l Z d d l Z d Z d Z d Z d „  Z e j	 e e d e ƒ  ƒZ
 d	 e f d
 „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   sð   Query Debian's Bug Tracking System (BTS).

This module provides a layer between Python and Debian's BTS. It provides
methods to query the BTS using the BTS' SOAP interface, and the Bugreport class
which represents a bugreport from the BTS.
iÿÿÿÿ(   t   datetimeNs'   http://bugs.debian.org/cgi-bin/soap.cgis   Debbugs/SOAP/V1s   http://bugs.debian.org/c          C   s5   t  j ƒ  j d ƒ }  |  d k r% d St j |  ƒ j S(   sù   Returns an HTTP proxy URL formatted for consumption by SOAPpy.

    SOAPpy does some fairly low-level HTTP manipulation and needs to be
    explicitly made aware of HTTP proxy URLs, which also have to be
    formatted without a schema or path.

    t   httpN(   t   urllibt
   getproxiest   gett   Nonet   urlparset   netloc(   t
   http_proxy(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyt   _get_http_proxy+   s    R   t	   Bugreportc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÃ  Represents a bugreport from Debian's Bug Tracking System.

    A bugreport object provides all attributes provided by the SOAP interface.
    Most of the attributs are strings, the others are marked.

    * bug_num: The bugnumber (int)
    * severity: Severity of the bugreport
    * tags: List of tags of the bugreport (list of strings)
    * subject:  The subject/title of the bugreport
    * originator: Submitter of the bugreport
    * mergedwith: List of bugnumbers this bug was merged with (list of ints)
    * package: Package of the bugreport
    * source: Source package of the bugreport
    * date: Date of bug creation (datetime)
    * log_modified: Date of update of the bugreport (datetime)
    * done: Is the bug fixed or not (bool)
    * archived: Is the bug archived or not (bool)
    * unarchived: Was the bug unarchived or not (bool)
    * fixed_versions: List of versions, can be empty even if bug is fixed (list of strings)
    * found_versions: List of version numbers where bug was found (list of strings)
    * forwarded: A URL or email address
    * blocks: List of bugnumbers this bug blocks (list of ints)
    * blockedby: List of bugnumbers which block this bug (list of ints)
    * pending: Either 'pending' or 'done'
    * msgid: Message ID of the bugreport
    * owner: Who took responsibility for fixing this bug
    * location: Either 'db-h' or 'archive'
    * affects: List of Packagenames (list of strings)
    * summary: Arbitrary text
    c         C   sÜ   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   R   t
   originatort   datet   subjectt   msgidt   packaget   tagst   donet	   forwardedt
   mergedwitht   severityt   ownert   found_versionst   fixed_versionst   blockst	   blockedbyt
   unarchivedt   summaryt   affectst   log_modifiedt   locationt   archivedt   bug_numt   sourcet   pending(   t   self(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyt   __init__\   s0    																							c         C   sq   d } xd |  j  j ƒ  D]S \ } } t | ƒ t t ƒ  ƒ k rO | j d ƒ } n  | d | t | ƒ f 7} q W| S(   Nt    s   utf-8s   %s: %s
(   t   __dict__t	   iteritemst   typet   unicodet   encodet   str(   R#   t   st   keyt   value(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyt   __str__~   s    c         C   s@   |  j  ƒ  } | j  ƒ  } | | k  r( d S| | k r8 d Sd Sd S(   sÍ  Compare a bugreport with another.

        The more open and and urgent a bug is, the greater the bug is:
            outstanding > resolved > archived
            critical > grave > serious > important > normal > minor > wishlist.
        Openness always beats urgency, eg an archived bug is *always* smaller
        than an outstanding bug.

        This sorting is useful for displaying bugreports in a list and sorting
        them in a useful way.
        iÿÿÿÿi    i   N(   t
   _get_value(   R#   t   othert   myvalt   otherval(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyt   __cmp__†   s    c         C   sp   |  j  r d } n |  j r$ d } n d } | i d d 6d d 6d d	 6d
 d 6d d 6d d 6d d 6|  j 7} | S(   Ni    i
   i   i   u   criticali   u   gravei   u   seriousi   u	   importanti   u   normali   u   minori   u   wishlist(   R   R   R   (   R#   t   val(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyR0      s    				(   t   __name__t
   __module__t   __doc__R$   R/   R4   R0   (    (    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyR
   <   s
   	"		c          G   s€   t  j |  Œ  } g  } | s n^ t | d ƒ t g  ƒ k re x? | d D] } | j t | ƒ ƒ qE Wn | j t | d ƒ ƒ | S(   s$   Returns a list of Bugreport objects.i    (   t   servert
   get_statusR(   t   appendt   _parse_status(   t   nrt   replyt   bugst   elem(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyR:   ±   s    c         G   s/   t  j |  | Œ } | d k r% t ƒ  S| j ƒ  S(   s»   Return a dictionary of "usertag" => buglist mappings.

    If tags are given the dictionary is limited to the matching tags, if no
    tags are given all available tags are returned.
    R%   (   R9   t   get_usertagt   dictt   _asdict(   t   emailR   R>   (    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyRA   Â   s    c         C   s™   t  j |  ƒ } g  | j ƒ  D] } | j ƒ  ^ q } x^ | D]V } t | d ƒ | d <t | d ƒ | d <t | d ƒ | d <| d j ƒ  | d <q; W| S(   sÄ   Return a list of Buglogs.

    A buglog is a dictionary with the following mappings:
        "header" => string
        "body" => string
        "attachments" => list
        "msg_num" => int
    t   headert   bodyt   msg_numt   attachments(   R9   t   get_bug_logt   _aslistRC   t   _uct   int(   R=   R>   t   it   buglogt   b(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyRI   Í   s    	%c         C   s   t  j |  ƒ } | j ƒ  S(   s9   Returns a list of bugnumbers of the `amount` newest bugs.(   R9   t   newest_bugsRJ   (   t   amountR>   (    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyRP   à   s    c          G   s   t  j |  Œ  } | j ƒ  S(   s  Returns a list of bugnumbers, that match the conditions given by the
    key-value pair(s).

    Possible keys are:
        "package": bugs for the given package
        "submitter": bugs from the submitter
        "maint": bugs belonging to a maintainer
        "src": bugs belonging to a source package
        "severity": bugs with a certain severity
        "status": can be either "done", "forwarded", or "open"
        "tag": see http://www.debian.org/Bugs/Developer#tags for available tags
        "owner": bugs which are assigned to `owner`
        "bugs": takes list of bugnumbers, filters the list according to given criteria
        "correspondent": bugs where `correspondent` has sent a mail to

    Example: get_bugs('package', 'gtk-qt-engine', 'severity', 'normal')
    (   R9   t   get_bugsRJ   (   t	   key_valueR>   (    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyRR   æ   s    c         C   sÀ  |  j  ƒ  }  t ƒ  } |  d } t | d ƒ | _ t j | d ƒ | _ t | d ƒ | _ t | d ƒ | _ t | d ƒ | _	 t | d ƒ j
 ƒ  | _ t | d ƒ | _ t | d	 ƒ | _ g  t | d
 ƒ j
 ƒ  D] } t | ƒ ^ q× | _ t | d ƒ | _ t | d ƒ | _ g  | d D] } t t | ƒ ƒ ^ q#| _ g  | d D] } t t | ƒ ƒ ^ qO| _ g  t | d ƒ j
 ƒ  D] } t | ƒ ^ q‡| _ g  t | d ƒ j
 ƒ  D] } t | ƒ ^ q¹| _ t | d ƒ | _ t | d ƒ | _ | d j ƒ  } | r>g  | j
 d ƒ D] } t | j ƒ  ƒ ^ q n g  | _ t j | d ƒ | _ t | d ƒ | _ t | d ƒ | _ t | d ƒ | _ t | d ƒ | _  t | d ƒ | _! | S(   s.   Return a bugreport object from a given status.R.   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   ,R   R   R   R    R!   R"   ("   RC   R
   RK   R   R    t   utcfromtimestampR   R   R   R   t   splitR   t   boolR   R   R+   RL   R   R   R   R   R   R   R   R   R   t   stripR   R   R   R   R    R!   R"   (   t   statust   bugt   tmpRM   R   (    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyR<   ü   s:    	
2,,22=c         C   s   t  |  d d ƒ S(   sl   Convert string to unicode.

    This method only exists to unify the unicode conversion in this module.
    s   utf-8t   replace(   R)   (   t   string(    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyRK   %  s    (   R8   R    R   R   t   SOAPpyt   URLt   NSt   BTS_URLR	   t	   SOAPProxyR9   t   objectR
   R:   RA   RI   RP   RR   R<   RK   (    (    (    s)   /usr/lib/pymodules/python2.7/debianbts.pyt   <module>   s"   	u						)