
GpNc           @   s  d  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 y d d l	 m
 Z
 Wn! e k
 r d d l m
 Z
 n Xd d l m Z d d l m Z d d l Z d d l Z e j j d  Z d   Z d   Z d	 e j j f d
     YZ d d l Z d d l Z d d l Z d d l Z e a d e j  f d     YZ! d e j" f d     YZ# e d d  Z$ e% d k rd d l& Z& d d l Z e a e a' e a( d e& j) f d     YZ* e& j+   n  d S(   s,   Crash database implementation for Launchpad.iN(   t   StringIO(   t	   HTTPError(   t	   Launchpads%   ~/.cache/apport/launchpad.credentialsc         c   s{   xt |  D]l } y | j  j   } Wn! t k
 rC t j d  q n X| j } | j d  sk | j d  r | Vq q Wd  S(   Ns"   Broken attachment on bug, ignorings   .txts   .gz(   t   datat   openR   t   apportt   errort   filenamet   endswith(   t   attachmentst
   attachmentt   ft   name(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   filter_filename   s    	c         C   s   t  d   |  D  S(   Nc         s   s-   |  ]# } t  | j j d   j    Vq d S(   t   /N(   t   intt	   self_linkt   splitt   pop(   t   .0t   i(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pys	   <genexpr>)   s    (   t   set(   t   tasks(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   id_set'   s    t   CrashDatabasec           B   s  e  Z d  Z d   Z e d    Z d   Z e d    Z d d  Z	 d   Z
 d   Z d   Z e d d d	  Z d
 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z RS(   s5   Launchpad implementation of crash database interface.c         C   s9  t  j d  r% t  j d  | d <n  | sj | j d  } | ra t d | j d d  d } qj t } n  t j j j |  | | |  | j d  |  _	 |  j	 r d | k s t
 d	  n d | k s t
 d
  d t j j   |  _ | |  _ | |  _ |  j st
  d |  _ d |  _ t  j d | j d   |  _ d S(   sO  Initialize Launchpad crash database. 
        
        You need to specify a launchpadlib-style credentials file to
        access launchpad. If you supply None, it will use
        default_credentials_path (~/.cache/apport/launchpad.credentials).

        Recognized options are:
        - distro: Name of the distribution in Launchpad
        - project: Name of the project in Launchpad
        (Note that exactly one of "distro" or "project" must be given.)
        - launchpad_instance: If set, this uses the given launchpad instance
          instead of production (optional). This can be overriden or set by
          $APPORT_LAUNCHPAD_INSTANCE environment.
        - cache_dir: Path to a permanent cache directory; by default it uses a
          temporary one. (optional). This can be overridden or set by
          $APPORT_LAUNCHPAD_CACHE environment.
        - escalation_subscription: This subscribes the given person or team to
          a bug once it gets the 10th duplicate.
        - escalation_tag: This adds the given tag to a bug once it gets more
          than 10 duplicates.
        t   APPORT_LAUNCHPAD_INSTANCEt   launchpad_instancet   .s   ://i   it   distrot   projects/   Must not set both "project" and "distro" options0   Need to have either "project" or "distro" options   need-%s-retracet   APPORT_LAUNCHPAD_CACHEt	   cache_dirN(   t   ost   getenvt   gett   default_credentials_pathR   R   t   crashdbR   t   __init__R   t   AssertionErrort	   packagingt   get_system_architecturet   arch_tagt   optionst   autht   Nonet   _CrashDatabase__launchpadt   _CrashDatabase__lp_distrot   _CrashDatabase__lpcache(   t   selfR+   t   bugpattern_baseurlR*   t   lp_instance(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR%   /   s*    !	
					c         C   s  |  j  r |  j  S|  j j d  r7 |  j j d  } n d } t j j |  j  } | r{ t j j |  r{ t j |  n  y: t	 j
 d | d |  j d d g d |  j d d	 |  _  Wn] t k
 r} t | d
  r | j } n t |  } t j d | |  j  t j d  n X|  j  S(   s   Return Launchpad instance.R   t
   productions   apport-collectt   launchpadlib_dirt   allow_access_levelst   WRITE_PRIVATEt   credentials_filet   versions   1.0t   contentsZ   connecting to Launchpad failed: %s
You can reset the credentials by removing the file "%s"ic   (   R-   R*   R"   R    t   patht   dirnameR+   t   isdirt   makedirsR   t
   login_withR/   t	   Exceptiont   hasattrR9   t   strR   R   t   syst   exit(   R0   R   t   auth_dirt   et   msg(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt	   launchpad`   s*    				c         c   si   |  j  s t  n  xP | D]H } | j j   |  j  k sY t j d |  j  | j j    r | Vq q Wd  S(   Ns   ^.+\(%s.*\)$(   R   t   StopIterationt   bug_target_namet   lowert   ret   match(   R0   R   t   t(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   _get_distro_tasks   s    		"c         C   s<   |  j  s d  S|  j d  k r5 |  j j |  j  |  _ n  |  j S(   N(   R   R,   R.   RG   t   distributions(   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt	   lp_distro   s
    	c         C   s  i  } d | d j    | d <| j d  } | s@ | d k rR | j d  } n  | ro | d c d | 7<n  | j d  r | d c d | d 7<n  d | k r$| r d	 | k s d
 | k r d | d <d | d <| d c d | 7<q$d | k r$d | d <d | d <| d c d 7<q$n  d | k rSd | d k rS| d c d 7<n  | j d  rs| d | d <n  d d d d d d d d d g	 } t j   } | j | d | d d g d | | j   | j d   t | | d! |  j	   } | s t
  | S("   s  Upload given problem report return a handle for it. 
        
        This should happen noninteractively. 
        
        If the implementation supports it, and a function progress_callback is
        passed, that is called repeatedly with two arguments: the number of
        bytes already sent, and the total number of bytes to send. This can be
        used to provide a proper upload progress indication on frontends.s	   apport-%st   ProblemTypet   Tagst   PackageArchitecturet   allt   Architecturet    t   DistroReleaset   VmCoret   CoreDumpt   yest   PrivateR   t   Subscriberss    need-%s-retracet	   Tracebacks    need-duplicate-checkt   DuplicateSignatures   need-duplicate-checkt   CheckboxSubmissions   HWDB-Submissiont   Packaget
   Regressiont   Reproduciblet   TestedUpstreamt   ProcVersionSignaturet   Unamet   NonfreeKernelModulest   extra_headerst	   skip_keyst   priority_fieldsi    t   hostname(   RJ   R"   t   has_keyt   tempfilet   TemporaryFilet
   write_mimet   flusht   seekt   upload_blobt   get_hostnameR&   (   R0   t   reportt   progress_callbackt   hdrt   at   ordert   mimet   ticket(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   upload   s@    



"
c         C   s@   |  j  j d  } | r6 | d k r- d } q< d } n d } | S(   s/   Return the hostname for the Launchpad instance.R   t   stagings   staging.launchpad.nets   launchpad.devs   launchpad.net(   R*   R"   (   R0   R   Rj   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyRr      s    		c         C   s   i  } | j  d | j    } | r1 | | d <n  |  j   } |  j j  d  } | s | j d  r d | |  j | d | t j |  f Sd | |  j | t j |  f Sn d | | | t j |  f Sd S(   s/  Return an URL that should be opened after report has been uploaded
        and upload() returned handle.

        Should return None if no URL should be opened (anonymous filing without
        user comments); in that case this function should do whichever
        interactive steps it wants to perform.t   Titles   field.titleR   t   SourcePackages,   https://bugs.%s/%s/+source/%s/+filebug/%s?%ss!   https://bugs.%s/%s/+filebug/%s?%sN(   R"   t   standard_titleRr   R*   Rk   R   t   urllibt	   urlencode(   R0   Rs   t   handlet   argst   titleRj   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_comment_url   s    $ c         C   sI  t  j   } |  j j | } t j d | j t j  } | sb t j d | j t j t j B } n  | sq t	 d  | j
 d  j d  j d d  j d d	  } d
 | k rd | k r | j d d  \ } } | j d
 d	  d | j d
 d  d } q| j d
 d  d } n  | j t |   d | k rqy | j j   | d <Wqqt k
 rm| j | d <qqXn  d | k r	d | j k rd | d <q	d | j k rd | d <q	d | j k rd | d <q	d | j k rd | d <q	t d t | j    n  d j | j  | d <d | k r<| d | d <n  | j | d <x t | j  D] } t j j | j  \ }	 }
 y d | |	 <Wn
 qYn X|
 d k r| j   | |	 <qY|
 d k r.y  t j  d |  j   | |	 <WqAt! k
 r*} d t |  k r
  n  | j" d  | j   | |	 <qAXqYt# d  | j   qYW| S(!   s>   Download the problem report from given ID and return a Report.s   (ProblemType:.*)$s   ^--- \r?$[\r\n]*(.*)s8   bug description must contain standard apport format datai   s   UTF-8s    RV   s   
s   
s   

s   Uname:i    t   DateRQ   s
   apport-bugt   Bugs   apport-crasht   Crashs   apport-kernelcrasht   KernelCrashs   apport-packageR`   s(   cannot determine ProblemType from tags: RR   R|   t   OriginalTitlet    s   .txts   .gzt   fileobjs
   Not a gzips   Unknown attachment type: ($   R   t   ReportRG   t   bugsRK   t   searcht   descriptiont   St   MR&   t   groupt   encodet   replaceR   t   loadR    t   date_createdt   ctimet   AttributeErrort   tagst
   ValueErrorRA   t   joinR   R   R	   R    R:   t   splitextR   t   readt   gzipt   GzipFilet   IOErrorRp   R?   (   R0   t   idRs   t   bt   mR   t   part1t   part2R
   t   keyt   extRE   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   download   sd    %0- c         C   s  |  j  j | } | r5 t | j    t |  } n d } t j   }	 | j |	 d | |	 j   |	 j	 d  t
 j |	  }
 |
 j   } | j   } | j   s t  | j   } | j   s t  | j   d k s t  | sJ| j } | j d  | j d  r$| | d j   7} n  | | _ | j   |  j  j | } n  | r| j d | j d t  j d d	  | _ | j   n" | j d
 | j d t  d |  xZ | D]R } | j d | pd d | j   d d d | j d t  d | j   d t  qWd S(   sq  Update the given report ID with all data from report.

        This creates a text comment with the "short" data (see
        ProblemReport.write_mime()), and creates attachments for all the
        bulk/binary data. 
        
        If change_description is True, and the crash db implementation supports
        it, the short data will be put into the description instead (like in a
        new bug).

        comment will be added to the "short" data. If attachment_comment is
        given, it will be added to the attachment uploads.

        If key_filter is a list or set, then only those keys will be added.
        Rh   i    s
   text/plains   apport-collectedRR   s   
--- 
t   decodes   UTF-8R   R9   t   subjectt   commentR   R   t   content_typeR   R   t   is_patchN(   RG   R   R   t   keysR,   Rl   Rm   Rn   Ro   Rp   t   emailt   message_from_filet   walkt   nextt   is_multipartR&   t   get_content_typeR   t   appendRk   R   t   lp_saveR   t   get_payloadt   TrueR   t
   newMessaget   addAttachmentt   get_filenamet   False(   R0   R   Rs   R   t   change_descriptiont   attachment_commentt
   key_filtert   bugRh   Rx   RF   t   msg_itert   partt   x(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   updateB  sD    

	
,R   c         C   sO  t  j j j |  | | |  |  j j | } | j d  r xc | j D]U } | j j	 j
 d  rE |  j j d | d  | _ | j   |  j j | } PqE qE Wn  | j   r;xE | j D]: } | j d k r y | j   Wq t k
 r q Xq q Wy/ |  j | j  j   } d | _ | j   Wq;t k
 r7q;Xn  |  j | |  d S(   s   Update the given report ID for retracing results.
        
        This updates Stacktrace, ThreadStacktrace, StacktraceTop,
        and StacktraceSource. You can also supply an additional comment.
        R}   s   #distributionR   s   CoreDump.gzt   MediumN(   R   R$   R   t   update_tracesRG   R   Rk   t	   bug_taskst   targett   resource_type_linkR   RP   t   getSourcePackageR   t   has_useful_stacktraceR	   R   t   removeFromBugR   RN   R   t
   importanceRH   t   _subscribe_triaging_team(   R0   R   Rs   R   R   t   taskRv   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR     s.    
	c         C   sH   |  j  j | } t j d | j  } | r8 | j d  St d   d S(   sN   Get 'DistroRelease: <release>' from the given report ID and return
        it.s"   DistroRelease: ([-a-zA-Z0-9.+/ ]+)i   s)   URL does not contain DistroRelease: fieldN(   RG   R   RK   R   R   R   R   (   R0   R   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_distro_release  s
    c         C   s   t  j d |  j  } |  j j | } g  } x] | j D]R } | j | j j  } | s] q6 n  | j	 d k rr q6 n  | j
 | j d   q6 W| S(   s5   Return list of affected source packages for given ID.s5   /%s/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$t   Invalids	   Won't Fixs   Fix Releasedt   source(   R   s	   Won't Fixs   Fix Released(   RK   t   compileR   RG   R   R   R   R   R   t   statusR   R   (   R0   R   t   bug_target_reR   t   resultR   RL   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_affected_packages  s    c         C   s)   |  j  j | } | j j |  j  j j k S(   s3   Check whether the user is the reporter of given ID.(   RG   R   t   ownerR   t   me(   R0   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   is_reporter  s    c         C   sz   |  j  j | } | j r t S| j j |  j  j j k r< t S|  j  j j } x( | j	 j
 D] } | d | k rX t SqX Wt S(   sB  Check whether the user is eligible to update a report.

        A user should add additional information to an existing ID if (s)he is
        the reporter or subscribed, the bug is open, not a duplicate, etc. The
        exact policy and checks should be done according to  the particular
        implementation.
        t   person_link(   RG   R   t   duplicate_ofR   R   R   R   R   R   t   subscriptionst   entries(   R0   R   R   R   t   sub(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt
   can_update  s    	c         C   sc   y& |  j  j d |  j  } t |  SWn6 t k
 r^ } t j d t |   t j	 d  n Xd S(   s}   Return an ID set of all crashes which have not been retraced yet and
        which happened on the current host architecture.R   s"   connecting to Launchpad failed: %sic   N(
   RP   t   searchTasksR)   R   R?   R   R   RA   RB   RC   (   R0   R   RE   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_unretraced  s    c         C   s`   y# |  j  j d d  } t |  SWn6 t k
 r[ } t j d t |   t j d  n Xd S(   s#  Return an ID set of all crashes which have not been checked for
        being a duplicate.

        This is mainly useful for crashes of scripting languages such as
        Python, since they do not need to be retraced. It should not return
        bugs that are covered by get_unretraced().R   s   need-duplicate-checks"   connecting to Launchpad failed: %sic   N(	   RP   R   R   R?   R   R   RA   RB   RC   (   R0   R   RE   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_dup_unchecked  s    c         C   s   |  j  j d d  } t |  S(   sW  Return an ID set of all crashes which are not yet fixed.

        The list must not contain bugs which were rejected or duplicate.
        
        This function should make sure that the returned list is correct. If
        there are any errors with connecting to the crash database, it should
        raise an exception (preferably IOError).R   s   apport-crash(   RP   R   R   (   R0   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_unfixed  s    	c         C   s5   |  j  j j d t d | d |  j  j  } | d j S(   s   Return the version of given source package in the latest release of
        given distribution.

        If 'distro' is None, we will look for a launchpad project . 
        t   exact_matcht   source_namet   distro_seriesi    (   RP   t   main_archivet   getPublishedSourcesR   t   current_seriest   source_package_version(   R0   t   packaget   sources(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   _get_source_version  s
    c   	         s  y   j  j | } Wn t k
 r( d SX| j r6 d St | j  }   j r^d   j j    t  f d   |  } | s t   f d   |  } | r d Sn  t	 |  d k r t
 j d   j |  d S| r| j   } y   j | j j   d  SWq[t k
 rd SXqt  f d	   |  } | rt  f d
   |  } | s[d Sqn2 t d   |  } | rzd St d   |  rd Sd S(   s  Return the package version that fixes a given crash.

        Return None if the crash is not yet fixed, or an empty string if the
        crash is fixed, but it cannot be determined by which version. Return
        'invalid' if the crash report got invalidated, such as closed a
        duplicate or rejected.

        This function should make sure that the returned result is correct. If
        there are any errors with connecting to the crash database, it should
        raise an exception (preferably IOError).
        t   invalids   (%s)c            s"   |  j  d k o!   |  j j   k S(   Ns   Fix Released(   R   t   bug_target_display_nameRJ   (   R   (   t   distro_identifier(    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   <lambda>5  s   c            s+   |  j  d k o* |  j j     j j   k S(   Ns   Fix Released(   R   RI   RJ   R   (   R   (   R0   (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   9  s   R   i   sV   There is more than one task fixed in %s %s, using first one to determine fixed versioni    c            s"   |  j  d k o!   |  j j   k S(   NR   s	   Won't Fix(   s   Invalids	   Won't Fix(   R   R   RJ   (   R   (   R   (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   L  s   c            s"   |  j  d k o!   |  j j   k S(   NR   s	   Won't Fix(   s   Invalids	   Won't Fix(   R   R   RJ   (   R   (   R   (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   O  s   c         S   s   |  j  d k S(   Ns   Fix Released(   R   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   T  s    c         S   s   |  j  d k S(   NR   (   R   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   Z  s    N(   RG   R   t   KeyErrorR   t   listR   R   RJ   t   filtert   lenR   t   warningR   R   R   R   t
   IndexErrorR,   (	   R0   R   R   R   t   fixed_taskst   fixed_distroR   t   invalid_taskst   non_invalid_tasks(    (   R0   R   sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   get_fixed_version  sN    						
		c         C   s(   |  j  j | j } | r  | j Sd Sd S(   sc   Return master ID for a duplicate bug.

        If the bug is not a duplicate, return None.
        N(   RG   R   R   R   R,   (   R0   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   _  s    c      
   C   s7  |  j  j | } | r| | k s5 t d t |   |  j  j | } | j r | j } | j | k r t j d | |  d Sn  xE | j D]: } | j	 d k r y | j
   Wq t k
 r q Xq q W|  j  j | } | j d d | d d  |  j  j | } | j rt | _ n  | j s,| | _ n  t | j  d k rd |  j k r|  j d | j k r|  j j d d  | j k r| j |  j d g | _ | j   n  d |  j k r|  j j d d  | j k r|  j  j |  j d } | j d |  qqn | j rd | _ n  | j r3| j   n  d S(   st   Mark a crash id as duplicate of given master ID.
        
        If master is None, id gets un-duplicated.
        s+   cannot mark bug %s as a duplicate of itselfsN   Bug %i was manually marked as a dupe of newer bug %i, not closing as duplicateNs   CoreDump.gzs   Stacktrace.txts   ThreadStacktrace.txts   Dependencies.txts   ProcMaps.txts   ProcStatus.txts   Registers.txts   Disassembly.txtR9   s  Thank you for taking the time to report this crash and helping to make Ubuntu better.  This particular crash has already been reported and is a duplicate of bug #%i, so is being marked as such.  Please look at the other bug report to see if there is any missing information that you can provide, or to see if there is a workaround for the bug.  Additionally, any further discussion regarding the bug should occur in the other report.  Please continue to report any other bugs you may find.R   s   This bug is a duplicatei
   t   escalation_tagt   escalated_tags	    invalid t   escalation_subscriptiont   person(   s   CoreDump.gzs   Stacktrace.txts   ThreadStacktrace.txts   Dependencies.txts   ProcMaps.txts   ProcStatus.txts   Registers.txts   Disassembly.txt(   RG   R   R&   RA   R   R   R   R   R	   R   R   R   R   t   privateR   R   t
   duplicatesR*   R   R"   R   t   peoplet	   subscribeR,   t   _dirty_attributes(   R0   R   t	   master_idR   t   masterRv   t   p(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   close_duplicatej  sR    			
 		
				c         C   s[   |  j  j | } | j d d | d d  |  j  j | } | j d g | _ | j   d S(   sp   Mark a crash id as reintroducing an earlier crash which is
        already marked as fixed (having ID 'master').R9   s   This crash has the same stack trace characteristics as bug #%i. However, the latter was already fixed in an earlier package version than the one in this report. This might be a regression or because the problem is in a dependent package.R   s   Possible regression detecteds   regression-retracerN(   RG   R   R   R   R   (   R0   R   R  R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   mark_regression  s    	
c         C   sn   |  j  j | } |  j | j k rj | j } | j |  j  | | _ y | j   Wqj t k
 rf qj Xn  d S(   s   Mark crash id as retraced.N(   RG   R   R)   R   t   removeR   R   (   R0   R   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   mark_retraced  s    
	c         C   s   |  j  j | } | r y |  j | j  j   } Wn t k
 rR | j d } n Xd | _ | j   | j d | d d  xw | j	 D]: } | j
 d k r y | j   Wq t k
 r q Xq q Wn/ d | j k r | j d g | _ | j   n  d S(	   s%   Mark crash id as 'failed to retrace'.i    R   R9   R   s    Crash report cannot be processeds   CoreDump.gzs   apport-failed-retraceN(   RG   R   RN   R   R   RH   R   R   R   R	   R   R   R   R   (   R0   R   t   invalid_msgR   R   Rv   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   mark_retrace_failed  s&    	
c         C   s   |  j  j | } | j d  r xc | j D]U } | j j j d  r) |  j j d | d  | _ | j	   |  j  j | } Pq) q) Wn  d | j
 k r | j
 } | j d  | | _
 | j	   n  |  j | |  d S(   s/   Mark crash id as checked for being a duplicate.R}   s   #distributionR   s   need-duplicate-checkN(   RG   R   Rk   R   R   R   R   RP   R   R   R   R  R   (   R0   R   Rs   R   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   _mark_dup_checked  s    

	c         C   sN   d | k r* | d j    d d k r* d Sd |  j j } | j d |  d S(   s-   Subscribe the right triaging team to the bug.RW   i    t   UbuntuNs   %s~ubuntu-crashes-universeR  (   R   RG   t	   _root_uriR  (   R0   R   Rs   R  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR     s    &N(    t   __name__t
   __module__t   __doc__R%   t   propertyRG   RN   RP   R,   Rz   Rr   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R
  R  R  R  R  R   (    (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR   ,   s8   	1 		7			QH"						
				F		A			t   HTTPSProgressConnectionc           B   s   e  Z d  Z d   Z RS(   sW   Implement a HTTPSConnection with an optional callback function for
    upload progress.c         C   s   t  s t j j |  |  d  Sd } t |  } d } x | | k  r t  | |  t j   } t j j |  | | | | ! | | 7} t j   } | | d k  r | d 9} q8 | | d k r8 | d :} q8 q8 Wd  S(   Ni    i   g      ?i   (   t   _https_upload_callbackt   httplibt   HTTPSConnectiont   sendR   t   time(   R0   R   t   sentt   totalt	   chunksizet   t1t   t2(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR    s     
(   R  R  R  R  (    (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR    s   t   HTTPSProgressHandlerc           B   s   e  Z d    Z RS(   c         C   s   |  j  t |  S(   N(   t   do_openR  (   R0   t   req(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt
   https_open.  s    (   R  R  R%  (    (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR"  ,  s   s   launchpad.netc         C   sd   d } | a t j t t j  } d | } | j | i d d 6|  d 6 } | j   j	 d  } | S(   s  Upload blob (file-like object) to Launchpad.

    progress_callback can be set to a function(sent, total) which is regularly
    called with the number of bytes already sent and total number of bytes to
    send. It is called every 0.5 to 2 seconds (dynamically adapted to upload
    bandwidth).

    Return None on error, or the ticket number on success.

    By default this uses the production Launchpad hostname. Set
    hostname to 'launchpad.dev' or 'staging.launchpad.net' to use another
    instance for testing.
    s   https://%s/+storeblobt   1t   FORM_SUBMITs
   field.blobs   X-Launchpad-Blob-TokenN(
   R,   R  t   urllib2t   build_openerR"  t   multipartpost_handlert   MultipartPostHandlerR   t   infoR"   (   t   blobRt   Rj   Ry   t   openert   urlR   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyRq   1  s    
	t   __main__t   _Tc           B   s[  e  Z d  Z d  Z d   Z d   Z d   Z e d    Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d    Z e d    Z d   Z d# d  Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d    Z& d!   Z' d"   Z( RS($   t	   coreutilsc         C   s   t  s |  j   a  n  t  |  _  t j   |  _ |  j j   |  j j   d |  j d <|  j   |  _ |  j	 d  |  j j
 |  _ |  j   j
 |  _ d  S(   NR2  R}   s   langpack-o-matic(   R$   t   _get_instanceR   R   t
   ref_reportt   add_os_infot   add_user_infot   _file_uncommon_description_bugt   uncommon_description_bugt   _create_projectR   t   known_test_idt   known_test_id2(   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   setUpa  s    	c         C   s]   |  j  j j | } | sY |  j  j j j d | d d | d | d | d d | d  n  d S(   s8   Create a project using launchpadlib to be used by tests.R   t   display_nameR   t   summaryR   N(   R$   RG   t   projectst   new_project(   R0   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR9  v  s    

c         C   s1   d } |  j  j j j d d d | d |  j  j  S(   s  File a bug report with an uncommon description.

            Example taken from real LP bug 269539. It contains only
            ProblemType/Architecture/DistroRelease in the description, and has
            free-form description text after the Apport data.
            sb   problem

ProblemType: Package
Architecture: amd64
DistroRelease: Ubuntu 8.10

more text

and more
R   u   mixed description bugR   R   (   R$   RG   R   t	   createBugRP   (   R0   t   desc(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR7    s
    c         C   s   |  j  j   S(   s1   Get the Launchpad hostname for the given crashdb.(   R$   Rr   (   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyRj     s    c         C   s   t  j j j   } | j |  j  | j   | j   | j   |  j	 | j
   d  d | d <d | d <|  j j |  } |  j |  |  j |  j |  } |  j |  |  j | | |  } |  j | d k  | S(   sD   File a SEGV crash report.

            Return crash ID.
            s!   crash crashed with SIGSEGV in f()s    "]"
t   ShortGibberishs   a
b
c
d
e

t   LongGibberishi    (   R   Rs   R1  t   _generate_sigsegv_reportt   add_package_infot   test_packageR5  t   add_gdb_infoR6  t   assertEqualR~   R$   Rz   t
   assertTruet   _get_bug_targett	   _file_bug(   R0   t   rR   t
   bug_targetR   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   _file_segv_report  s    




c         C   s3   |  j    } | a t j j d |  j | f  d S(   s   upload() and get_comment_url() for SEGV crash
            
            This needs to run first, since it sets segv_report.
            s   (https://%s/bugs/%i) N(   RO  t   segv_reportRB   t   stderrt   writeRj   (   R0   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_1_report_segv  s    c         C   s   t  j d  } d | d <d | d <d | d <| j |  j  | j   | j   |  j | j   d  |  j j	 |  } |  j
 |  |  j |  j |  } |  j
 |  |  j | | |  } |  j
 | d	 k  | a t j j d
 |  j | f  d S(   s   upload() and get_comment_url() for Python crash
            
            This needs to run early, since it sets python_report.
            R   s   /bin/foot   ExecutablePaths   Traceback (most recent call last):
  File "/bin/foo", line 67, in fuzz
    print(weird)
NameError: global name 'weird' is not definedR]   s   boogus pybogusRR   sH   foo crashed with NameError in fuzz(): global name 'weird' is not definedi    s   (https://%s/bugs/%i) N(   R   R   RF  RG  R5  R6  RI  R~   R$   Rz   RJ  RK  RL  t   python_reportRB   RQ  RR  Rj   (   R0   RM  R   RN  R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_1_report_python  s"    




c         C   st  |  j  j t  } |  j | d d  |  j | d d  |  j | d |  j d  |  j | d |  j d  |  j | d |  j d  |  j | j d  |  j j d   |  j | j d	  |  j j d	   t | d
 j    } |  j | t |  j  j d t	 j
 j   g   |  j | d d  |  j | d j d   |  j | d |  j  |  j | d j |  j d   |  j d | d k  |  j d | d k  |  j d | d k  |  j t | d  d k  |  j d | k  |  j d | k  |  j d | k  |  j  j t  } t | d
 j    } |  j | t d d d d t	 j
 j   g   d S(    s
   download()RQ   R   R|   s!   crash crashed with SIGSEGV in f()RW   RU   Re   Rf   t
   UserGroupsRR   s   apport-crasht   Signalt   11RT  s   /crashR}   R`   RV   s   f (x=42)t
   Stacktracet   StacktraceTopt   ThreadStacktraceRY   i  t   Dependenciest   Disassemblyt	   Registerst   boogust   pyboguss   need-duplicate-checkN(   R$   R   RP  RI  R4  R"   R   R   R)   R   R'   R(   RJ  R   t   test_srcpackaget
   startswithRG  R   RU  (   R0   RM  R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_2_download  s6    %!c         C   s  |  j  j t  } |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  d | d <d	 | d <d
 | d <d | d <|  j  j t | d  |  j  j t  } |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j  j j t j } |  j d | k  |  j d | k  d | d <d	 | d <d
 | d <|  j  j t | d  |  j  j t  } |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  |  j d | k  d | d <d | d <d | d <|  j  j t | d  d S(   s   update_traces()RY   R]  R^  R_  RZ  R\  s   ?? ()R[  s
   long
traces   thread
even longer
tracet   bogust   FooBars   I can has a better retrace?s   apport-crashs   apport-collecteds=   read () from /lib/libc.6.so
foo (i=1) from /usr/lib/libfoo.sos   good retrace!R   s   "]"
s   a
b
c
d
e

t   StacktraceSourcet   testsN(	   R$   R   RP  RJ  R   t   assertFalseRG   R   R   (   R0   RM  R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_3_update_traces   sN    









c         C   sf  |  j  j j d d  } |  j  j j j d d d | d d  } | j } |  j | d k  t j	 j
 d	 |  j | f  t j d
  } d | d <d | d <d | d <d | d <d d | d <|  j  j | | d d t |  j  j |  } |  j | d d  |  j | d d  |  j | d d  |  j | d d d  |  j |  j  j j | j d g  d S(   s"   update() with changing descriptionR   t   bashR   s   test description for test bug.R   R   t   testbugi    s   (https://%s/bugs/%i) R   s   bogus→t   OneLiners   f()
g()
h(1)R[  s   lineone
linetwot   ShortGoos   one
two
three
four
five
sixt   DpkgTerminalLogs   i   t   VarLogDistupgradeBinGoot   NotMeR   s   apport-collectedN(   R$   RP   R   RG   R   RA  R   RJ  RB   RQ  RR  Rj   R   R   R   R   R   RI  R   (   R0   RN  R   R   RM  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_update_description2  s,    		



c         C   sx  |  j  j j d d  } |  j  j j j d d d | d d  } | j } |  j | d k  t j	 j
 d	 |  j | f  t j d
  } d | d <d | d <d | d <d | d <d d | d <|  j  j | | d d t |  j  j |  } |  j d | k  |  j d | k  |  j | d d
  |  j | d d  |  j | d d d  |  j |  j  j j | j d g  d S(   s   update() with appending commentR   Rk  R   s   Pr0blem

--- 
ProblemType: BugR   R   Rl  i    s   (https://%s/bugs/%i) R   s   bogus→Rm  s   f()
g()
h(1)R[  s   lineone
linetwoRn  s   one
two
three
four
five
sixRo  s   i   Rp  t   meowR   RQ   s   apport-collectedN(   R$   RP   R   RG   R   RA  R   RJ  RB   RQ  RR  Rj   R   R   R   R   R   Ri  RI  R   (   R0   RN  R   R   RM  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_update_commentR  s.    		



c      
   C   s  |  j  j j d d  } |  j  j j j d d d | d d  } | j } |  j | d k  t j	 j
 d	 |  j | f  t j d
  } d | d <d | d <d | d <d | d <d d | d <|  j  j | | d d t d d d d g |  j  j |  } |  j d | k  |  j | d d  |  j | d d
  |  j | d d  |  j d | k  |  j |  j  j j | j g   d S(   s   update() with a key filterR   Rk  R   s   test description for test bugR   R   Rl  i    s   (https://%s/bugs/%i) R   s   bogus→Rm  s   f()
g()
h(1)R[  s   lineone
linetwoRn  s   one
two
three
four
five
sixRo  s   i   Rp  Rq  R   R   RQ   N(   R$   RP   R   RG   R   RA  R   RJ  RB   RQ  RR  Rj   R   R   R   R   R   Ri  RI  R   (   R0   RN  R   R   RM  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_update_filteru  s.    		



c         C   s'   |  j  |  j j t  |  j d  d S(   s   get_distro_release()RW   N(   RI  R$   R   RP  R4  (   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_get_distro_release  s    c         C   s*   |  j  |  j j t  |  j d g  d S(   s   get_affected_packages()R}   N(   RI  R$   R   RP  R4  (   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_get_affected_packages  s    c         C   s6   |  j  |  j j t   |  j |  j j d   d S(   s   is_reporter()i   N(   RJ  R$   R   RP  Ri  (   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_is_reporter  s    c         C   s6   |  j  |  j j t   |  j |  j j d   d S(   s   can_update()i   N(   RJ  R$   R   RP  Ri  (   R0   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_can_update  s    c         C   sP  |  j  |  j j t  d  |  j  |  j j t  d  |  j j t |  j  |  j  |  j j t  |  j  |  j j t |  j  |  j  |  j j t  |  j  |  j  |  j j t  d  |  j j t d  |  j  |  j j t  d  |  j  |  j j t  d  |  j j t  } |  j	 d | k  |  j	 d | k  |  j	 d | k  |  j	 d | k  |  j j |  j |  j
  |  j j t |  j  |  j  |  j j t  |  j
  |  j j |  j d  |  j j |  j
 d  |  j j t d  |  j j |  j d  |  j  |  j j |  j  d  |  j j t |  j  |  j t  d S(   s   duplicate handlingR   RY   R]  R^  R_  N(   RI  R$   R   RP  R,   R   R
  R:  R   Ri  R;  R  t   _verify_marked_regression(   R0   RM  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_duplicates  s6    

c         C   s  |  j  j   } |  j t | k  |  j t | k  |  j  j t  |  j  j   } |  j t | k  |  j | | j t	 t g    |  j |  j  j
 t  d  |  j t  |  j  j t  |  j  j t  |  j  j   } |  j t | k  |  j | | j t	 t g    |  j |  j  j
 t  d  |  j t  |  j  j t  |  j  j t d  |  j  j   } |  j t | k  |  j | | j t	 t g    |  j |  j  j
 t  d  d S(   s-   processing status markings for signal crashess   I don't like youR   N(   R$   R   RJ  RP  Ri  RU  R  RI  t   unionR   R   R,   t   _mark_needs_retraceR  (   R0   t   unretraced_beforet   unretraced_after(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_marking_segv  s4    			c         C   s   |  j  j   } |  j t | k  |  j t | k  |  j  j t |  j  |  j  j   } |  j t | k  |  j | | j	 t
 t g    |  j |  j  j t  d  d S(   s2   processing status markings for interpreter crashesN(   R$   R   RJ  RU  Ri  RP  R  R4  RI  R|  R   R   R,   (   R0   t   unchecked_beforet   unchecked_after(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_marking_python   s    	c         C   s   |  j    } t j j d |  j | f  |  j j |  } |  j j | t  d | d <d | d <d | d <|  j j	 | | d  |  j j |  } |  j
 d	 | k  d
 S(   s   updating an invalid crash
            
            This simulates a race condition where a crash being processed gets
            invalidated by marking it as a duplicate.
            s   (https://%s/bugs/%i) s=   read () from /lib/libc.6.so
foo (i=1) from /usr/lib/libfoo.soR[  s
   long
traceRZ  s   thread
even longer
traceR\  s   good retrace!RY   N(   RO  RB   RQ  RR  Rj   R$   R   R
  RP  R   Ri  (   R0   R   RM  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_update_traces_invalid  s    


c         C   ss   |  j  t  |  j j t  } |  j | d  |  j | d j    |  j t  |  j	 |  j j t  d  d S(   s   get_fixed_version() for fixed bugs

            Other cases are already checked in test_marking_segv() (invalid
            bugs) and test_duplicates (duplicate bugs) for efficiency.
            i    N(
   t   _mark_report_fixedRP  R$   R   t   assertNotEqualR,   RJ  t   isdigitt   _mark_report_newRI  (   R0   t	   fixed_ver(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_get_fixed_version$  s    c         C   sB   t  j j d  p d } t t  j j d  d i d d 6| d 6 S(   s   Create a CrashDB instanceR   R{   t   LP_CREDENTIALSR   t   ubuntuR   R   (   R    t   environR"   R   (   t   klassR   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR3  5  s    
c         C   sW   | j  j d  } | j d  r8 | j j d | d  S| rL | j j | St j Sd S(   s&   Return the bug_target for this report.R   R}   R   N(   R*   R"   Rk   RP   R   RG   R?  R0   (   R  t   dbRs   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyRK  ?  s    c         C   s'   |  j  j   } d | k r d Sd Sd S(   s@   Return the librarian hostname according to the LP hostname used.R{   s   staging.launchpadlibrarian.nets   launchpad.dev:58080N(   R$   Rr   (   R0   Rj   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   _get_librarian_hostnameK  s    c         C   s  | j  d | j    } |  j j j j d |  } |  j j j | d  } x | j   sk t j	 d  qO W| j
   } |  j j j j d | d d | d d | d	 d
 | d |  }	 x" | d D] } |	 j d |  q Wd |  j   }
 xu | d D]i } | d } } t j t j |
 t | d  d |   j   } |	 j d | d | d | d |  q Wx> | d D]2 } |  j j j | } | ro|	 j d |  qoqoWxJ | d D]> } |  j j j d |  j j   | f  } |	 j d |  qWt |	 j  S(   s   File a bug report.R|   t   tokenR   i   R   t   extra_descriptionR  R   t   initial_tagsR   R   t   commentsR9   s	   http://%sR	   t   file_alias_idR   R   R   R   t   subscribersR  t   hwdb_submission_keyss(   https://api.%s/beta/+hwdb/+submission/%st
   submission(   R"   R~   R$   RG   t   temporary_blobst   fetchR   t   hasBeenProcessedR  t   sleept   getProcessedDataR   RA  R   R  R   t   urlopent   basejoinRA   R   R   R  R  Rr   t   linkHWSubmissionR   R   (   R0   RN  Rs   R   R   t	   bug_titlet	   blob_infoR-  t   processed_blobR   t   librarian_urlR
   R   R   R   t
   subscriberR   t   submission_keyR  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyRL  T  sF    	


	
$	c         C   sR   |  j  j j | } |  j  j | j k rN | j |  j  j g | _ | j   n  d S(   s$   Mark a report ID as needing retrace.N(   R$   RG   R   R)   R   R   (   R0   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR}    s    c         C   sF   |  j  j j | } d | j k rB | j d g | _ | j   n  d S(   s,   Mark a report ID as needing duplicate check.s   need-duplicate-checkN(   R$   RG   R   R   R   (   R0   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   _mark_needs_dupcheck  s    c         C   s[   |  j  j j | } t | j  } t |  d k s: t  | d } d | _ | j   d S(   s   Close a report ID as "fixed".i   i    s   Fix ReleasedN(	   R$   RG   R   R   R   R   R&   R   R   (   R0   R   R   R   RM   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR    s    
	c         C   s[   |  j  j j | } t | j  } t |  d k s: t  | d } d | _ | j   d S(   s   Reopen a report ID as "new".i   i    t   NewN(	   R$   RG   R   R   R   R   R&   R   R   (   R0   R   R   R   RM   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR    s    
	c         C   s-   |  j  j j | } |  j d | j k  d S(   s.   Verify that report ID is marked as regression.s   regression-retracerN(   R$   RG   R   RJ  R   (   R0   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyRz    s    c         C   s   t  j j d  p d } t t  j j d  d i d d 6| d 6 } |  j | j d  t j d  } d	 | d
 <d | d <| j	   | j
   |  j | j   d  | j |  } |  j |  |  j | |  } |  j | j d  |  j | | |  } |  j | d k  t j j d |  j | f  | j |  } d | d <d | d <d | d <| j | | d  | j |  } |  j | j |  d  | j | |  j  |  j | j |  |  j  |  j | j |  d  | j | d  |  j | j |  d  |  j | j |  d  d S(   s7   reporting crashes against a project instead of a distroR   R{   R  R   s   langpack-o-maticR   R   R   s   /bin/fooRT  s   Traceback (most recent call last):
  File "/bin/foo", line 67, in fuzz
    print(weird)
NameError: global name 'weird' is not definedR]   sH   foo crashed with NameError in fuzz(): global name 'weird' is not definedi    s   (https://%s/bugs/%i) s=   read () from /lib/libc.6.so
foo (i=1) from /usr/lib/libfoo.soR[  s
   long
traceRZ  s   thread
even longer
traceR\  s   good retrace!R   N(   R    R  R"   R   RI  R   R,   R   R   R5  R6  R~   Rz   RJ  RK  R   RL  RB   RQ  RR  Rj   R   R   R   R
  R:  R   (   R0   R   R$   RM  R   RN  R   (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_project  s@    







c         C   s^   |  j  j |  j j  } |  j | d d  |  j | d d  |  j | d j d   d S(   s*   download() of uncommon description formatsRQ   R`   RU   t   amd64RW   s   Ubuntu N(   R$   R   R8  R   RI  RJ  Rc  (   R0   RM  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_download_robustness  s    c   
      C   s  t  s t d  t j j d  p$ d } t t j j d  d i d d 6| d 6d	 d
 6d d 6 } d } | j j | j d j	 } d } z x t
 | | d  D] } | d 7} t j j d |  | j | t   | j j t  } | j d
 | j k } t g  | j D] } | j | k ^ q }	 | d k rL|  j |  |  j |	  q |  j |  |  j |	  q WWd x? t
 | | |  D]* } t j j d |  | j | d  qWXt j j d  d S(   s,   Escalating bugs with more than 10 duplicatess*   you need to run test_1_report_segv() firstR   R{   R  R   R  R   R   t
   omgkittensR   s   apport-hackersR   i    i;   i   i   s   %i i
   Ns   R%i s   
(   RP  R&   R    R  R"   R   RG   R  R*   R   t   rangeRB   RQ  RR  R
  R   R   t   anyR   R   Ri  RJ  R,   (
   R0   R   R  t   countR	  t	   first_dupR   t   has_escalation_tagt   st   has_escalation_subscription(    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_escalation  s6    

+c         C   s  |  j  t  |  j j   } |  j t | k  |  j j j t } | j d } |  j j j d | _	 | j
   | j d |  j j j d  |  j j t |  j  |  j j   } |  j t | k  |  j | | j t t g    |  j j j t } |  j | j d j d  |  j | j d j d  |  j | j d j d  |  j | j d j d  |  j |  j j t  d  d S(	   s9   source package task fixup for marking interpreter crashesi    R  R   R2  R  i   s   coreutils (Ubuntu)N(   R  RU  R$   R   RJ  RG   R   R   RO   R   R   t   addTaskR?  R  R4  Ri  RI  R|  R   RI   R   R   R,   (   R0   R  R   RM   R  (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   test_marking_python_task_mangle  s(    
	N()   R  R  RG  Rb  R<  R9  R7  R  Rj   RO  RS  RV  Rd  Rj  Rr  Rt  Ru  Rv  Rw  Rx  Ry  R{  R  R  R  R  t   classmethodR3  RK  R  R,   RL  R}  R  R  R  Rz  R  R  R  R  (    (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyR1  W  sH   					
		"	2	 	#	!					/	#			
		C			
	
		2			#(,   R  R   Rl   t   os.pathR    RK   R   RB   R   t	   cStringIOR    t   ImportErrort   iot   launchpadlib.errorsR   t   launchpadlib.launchpadR   t   apport.crashdbR   R:   t
   expanduserR#   R   R   R$   R   R*  R(  R  R  R,   R  R  R  t   HTTPSHandlerR"  Rq   R  t   unittestRP  RU  t   TestCaseR1  t   main(    (    (    sA   /usr/lib/python2.7/dist-packages/apport/crashdb_impl/launchpad.pyt   <module>   s<   H		  0  