
GpNc           @   sS  d  Z  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	 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 d d l Z d d l 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 e j j d d  a d Z d	   Z e  e! d
  Z" d f  d     YZ# d f  d     YZ$ e% d k rO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/ Z d d l0 Z0 d d l1 Z d e# f d     YZ2 d e& j3 f d     YZ4 e& j5   n  d S(   s   Abstract Apport user interface.

This encapsulates the workflow and common code for any user interface
implementation (like GTK, Qt, or CLI).
s   1.23iN(   t   get_crashdbt   NeedsCredentials(   t   unicode_gettextt   APPORT_SYMPTOMS_DIRs   /usr/share/apport/symptomsi    c         C   s   t  |   j t j   d  S(   s$   Return exception message as unicode.t   replace(   t   strt   decodet   localet   getpreferredencoding(   t	   exception(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   excstr   s    c         C   s  |  j    |  j   | r i  } yd t | |  | d |  |  } | s] t j d |  d St j j t j j |   d |  d <Wq t	 k
 r t
 j d  q t j d |  t j   t
 j d  q Xn  | s|  j d  rt j j |  d  } qt d   n  y |  j |  Wn@ t k
 rB| sf  qfn$ t k
 re} t |  |  d	 <d SX|  j |  rt
 j d  n  yb d
 |  k st j j |  d
 j   d  rd |  k rt d  |  d j   d |  d	 <n  Wn t k
 r| s  qn Xd |  k r5|  j   } | r5| |  d <q5n  |  d d k rd t j k r|  j   }	 |	 rt d  d j |	  |  d	 <qn  |  j   | rt  | d  }
 t j! | d  |  j" |
 d t# |
 j$   t j j% |  t j! | d  n  d S(   sy  Collect information about report.

    Encapsulate calls to add_*_info() and update given report, so that this
    function is suitable for threading.

    ui must be a HookUI instance, it gets passed to add_hooks_info().

    If reportfile is not None, the file is written back with the new data.

    If symptom_script is given, it will be run first (for run_symptom()).
    t   runs8   symptom script %s did not determine the affected packageNi    t   Symptoms   symptom script %s crashed:t   ExecutablePathsA   called without a package, and report does not have ExecutablePatht   UnreportableReasont   Packaget   CrashDBs    This is not a genuine %s packaget   DistroReleaset   Titlet   ProblemTypet   Crasht   APPORT_IGNORE_OBSOLETE_PACKAGESs   You have some obsolete package versions installed. Please upgrade the following packages and check if the problem still occurs:

%ss   , t   at   only_newi  (&   t   add_gdb_infot   add_os_infot   execfilet   apportt   errort   ost   patht   splitextt   basenamet   StopIterationt   syst   exitt	   tracebackt	   print_exct   has_keyt	   fileutilst   find_file_packaget   KeyErrort   add_package_infot
   ValueErrort   SystemErrorR
   t   add_hooks_infot	   packagingt   is_distro_packaget   splitt   _t   standard_titlet   environt   obsolete_packagest   joint	   anonymizet   opent   chmodt   writet   Truet   closet   mark_report_seen(   t   reportt
   reportfilet   packaget   uit   symptom_scriptt   ignore_uninstalledt   symbt   et   titlet   old_pkgst   f(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   thread_collect_info$   st    

*
	!	 
 

t   UserInterfacec           B   sy  e  Z d  Z d   Z d   Z e 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( 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% d!   Z& d"   Z' d#   Z( d$   Z) d%   Z* d&   Z+ d'   Z, RS()   s  Apport user interface API.

    This provides an abstract base class for encapsulating the workflow and
    common code for any user interface implementation (like GTK, Qt, or CLI).

    A concrete subclass must implement all the abstract ui_* methods.
    c         C   s   d |  _  d |  _ d |  _ d |  _ y t d  |  _ WnF t k
 rb } t j	 d t
 |   n t k
 r t j	 d  n Xt j |  j   |  j   d S(   s8   Initialize program state and parse command line options.R   sD   Could not import module, is a package upgrade in progress? Error: %ss8   /etc/apport/crashdb.conf is damaged: No default databaseN(   t   gettext_domaint   NoneR=   t   report_filet   cur_packageR    t   crashdbt   ImportErrorR   t   fatalR   R)   t   gettextt
   textdomaint
   parse_argv(   t   selfRD   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   __init__   s    				c         C   sa   t  } t j   d k r* t j j   } n t j j   } x! | D] } |  j |  t } q@ W| S(   s   Present all currently pending crash reports.
        
        Ask the user what to do about them, and offer to file bugs for them.
        
        Return True if at least one crash report was processed, False
        otherwise.
        i    (	   t   FalseR   t   geteuidR   R'   t   get_new_system_reportst   get_new_reportst	   run_crashR:   (   RT   t   resultt   reportsRG   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_crashes   s    
c      	   C   s  | |  _  yy t j j |  Wn t k
 r3 n X|  j |  sG d Sd |  j k rZ d S|  j j d  d k rd |  j k rd |  j k rd |  j k rt j	 j
 |  j j d t d	    } t d
  | } |  j t d  | d | t d  f  d S| sn|  j j d  d k rV|  j   } | d k rAd S| d k st  nx|  j j d  d k r|  j   } | d k rd S| d k st  n/|  j j d  d k r|  j   } | d k rd S| d k st  n y |  j   } Wn8 t k
 r2|  j t d  t d   |  j   d SX|  j |  } | j d  sWt  | j d  slt  | d r|  j j   n  | d d k rd S| d d k r|  j   d S| d d k st  y  d |  j k r|  j   n  Wn t t j f k
 rB} d |  _ |  j t d  d t d  t |  f  t St k
 ry|  j t d  t d   |  j   d SX|  j   rd S|  j   rd S|  j  t  } | d k rd S| d k ry |  j d =Wqt! k
 rqXn | d k st  |  j"   Wn t k
 r} | j# t# j$ t# j% f k r`|  j t d  t d   t& j' d  q| j# t# j( k r|  j t d  t d   t& j' d  q|  j t d  | j)  t& j' d  n8 t k
 r} | j# t# j* k rt j+ d   q  n Xd S(!   s  Present and report a particular crash.

        If confirm is True, ask the user what to do about it, and offer to file
        a bug for it.
        
        If confirm is False, the user will not be asked, and the crash is
        reported right away.
        Nt   IgnoreR   R   t   Signalt   CoreDumpt
   StacktraceR   s   unknown programs+   Sorry, the program "%s" closed unexpectedlys   Problem in %ss   %s

%ssx   Your computer does not have enough free memory to automatically analyze the problem and send a report to the developers.R   t   cancelR=   t   KernelCrasht
   KernelOopss   Invalid problem reports6   The report belongs to a package that is not installed.t   actiont	   blacklistt   restartt   Dependenciess7   This problem report is damaged and cannot be processed.t   reducedt   fulls2   You are not allowed to access this problem report.i   t   Errors@   There is not enough disk space available to process this report.s   Out of memory, aborting(,   RL   R   R'   R<   t   OSErrort   load_reportR=   t   getR   R   R    R1   t   ui_error_messaget   ui_present_package_errort   AssertionErrort   ui_present_kernel_errort   get_desktop_entryR+   t   ui_shutdownt   ui_present_crashR&   t   mark_ignoreRg   t   collect_infot   IOErrort   zlibR   RK   t   reprRV   t   check_unreportablet   handle_duplicatet   ui_present_report_detailsR)   t   file_reportt   errnot   EPERMt   EACCESR"   R#   t   ENOSPCt   strerrort   ENOMEMRP   (   RT   RL   t   confirmt   subjectt   headingt   responset   desktop_entryRD   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRZ      s    			


		
c         C   sb  |  j  j rQ |  j  j rQ | rQ |  j   r1 t S|  j t d  t d   t St j	 d  |  _
 |  j  j rkye t d |  j  j  j   j   } t | d  } | t @r d |  j  _ n |  j
 j |  j  j  Wqxt t f k
 r
|  j t d  t d   t St k
 rg} | j t j k r/t S| j t j k ra|  j t d	  t d
   t S  qxXn |  j
 j   |  j  j r|  j  j j   |  j  _ n  |  j  j d k rt j j   |  _ n |  j  j |  _ y |  j |  Wn{ t k
 rc} t |  d k r]|  j s6|  j t d  t d  |  n# |  j t d  t d  |  j  t S  n X|  j   rtd S|  j   |  j    rt Sy |  j
 d =Wn t! k
 rn X|  j  j" r6y? t t# j$ j% |  j  j"  d  } |  j
 j& |  | j'   Wq^t t f k
 r2} |  j t d  t( |   q^Xn( |  j) t  } | d k r^|  j*   n  t S(   s@  Report a bug.

        If a pid is given on the command line, the report will contain runtime
        debug information. Either a package or a pid must be specified; if none
        is given, show a list of symptoms.

        If a symptom script is given, this will be run first (used by
        run_symptom()).
        s   No package specifiedsH   You need to specify a package or a PID. See --help for more information.t   Bugs   /proc/%s/stati   t   linuxs   Invalid PIDs6   The specified process ID does not belong to a program.s   Permission deniedsf   The specified process does not belong to you. Please run this program as the process owner or as root.s   package does not exists   Invalid problem reports7   Symptom script %s did not determine an affected packages   Package %s does not existNt   ProcCmdlinet   ws   Cannot create reportRb   (+   t   optionsR?   t   pidt   run_symptomsR:   Ro   R1   RV   R   t   ReportR=   R7   t   readR0   t   intt
   PF_KTHREADt   add_proc_infoR+   Rx   Rl   R   t   ENOENTR   t   add_proc_environt   stripR.   t   get_kernel_packageRM   Rw   R   R{   t   add_extra_tagsR|   R)   t   saveR   R   t
   expanduserR9   R;   R
   R}   R~   (   RT   RA   t   statt   flagsRD   RG   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_report_bug=  s    
"

	
!#c         C   s{  |  j  j |  j j  s8 |  j t d  t d   t S|  j  j |  j j  } | sx |  j t d   } | sx t Sn  t	 j
 d  |  _ |  j j r |  j j j   g } n |  j  j |  j j  } t } x | D] } | |  _ | |  j d <| |  j d <y t	 j j |  WnK t k
 r]t j j t j j t	 j j d |   s^d | GHq q^n X|  j d	 t  t } q W| s|  j t d  t d
   t S|  j j   |  j j   |  j   |  j d =|  j d =y |  j d =Wn t k
 rn Xt |  j  d k r-|  j t d  t d
   t S|  j  t  } | d k rw|  j  j! |  j j |  j d d | d d t St S(   s:   Update an existing bug with locally collected information.s   Updating problem reports   You are not the reporter or subscriber of this problem report, or the report is a duplicate or already closed.

Please create a new report using "apport-bug".sH  You are not the reporter of this problem report. It is much easier to mark a bug as a duplicate of another than to move your comments and attachments to a new bug.

Subsequently, we recommend that you file a new bug report using "apport-bug" and make a comment in this bug about the one you file.

Do you really want to proceed?R   t   SourcePackageR   s   source_%s.pys8   Package %s not installed and no hook available, ignoringRB   s$   No additional information collected.R   t   Datei    Rb   s   apport informationt   change_descriptiont   attachment_comment("   RN   t
   can_updateR   t   update_reportRo   R1   RV   t   is_reportert   ui_question_yesnoR   R   R=   R?   R   t   get_affected_packagesRM   R.   t   get_versionR+   R   R   t   existsR5   t	   _hook_dirRw   R:   t   ui_info_messaget   add_user_infoR   R   R)   t   lenR}   t   update(   RT   R   t   rt   pkgst   info_collectedt   pR   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_update_report  sf    	+	




c         C   s  t  j  t j j t d   } g  } g  } x | D] } t j j |  j d  rX q1 n  i  } y t | |  Wn$ t j	 d |  t
 j   q1 n Xd | k r t j	 d |  q1 n  | j t j j t j j |   d  | j | j d | d   q1 W| st St t t | |     \ } } t |  } t |  } | j d  | j d	  |  j t d
  | t  } | d k r| | d } | r|  j t j j t | d   qt Sn  t S(   st   Report a bug from a list of available symptoms.
        
        Return False if no symptoms are available.
        s   *.pyR1   s   symptom script %s is invalidR   s0   symptom script %s does not define run() functioni    t   descriptionis   Other problems+   What kind of problem do you want to report?s   .pyN(   t   globR   R   R5   t   symptom_script_dirR    t
   startswithR   R   R   R$   R%   t   appendR   Rn   RV   t   zipt   sortedt   listRK   t   ui_question_choiceR1   R   R:   (   RT   t   scriptst   symptom_namest   symptom_descriptionst   scriptRC   t   cht   symptom(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     sB    
)!!#c         C   sl   t  j j t |  j j d  } t  j j |  s[ |  j t d  t d  |  j j  d S|  j	 |  d S(   s#   Report a bug with a symptom script.s   .pys   Unknown symptoms   The symptom "%s" is not known.N(
   R   R   R5   R   R   R   R   Ro   R1   R   (   RT   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_symptom#  s    c         C   s  |  j  j r |  j   t S|  j  j r0 |  j   S|  j  j rF |  j   S|  j  j r[ t	 GHt S|  j  j
 r y |  j |  j  j
 t  Wn/ t k
 r } |  j t d  t |   n Xt S|  j  j r|  j d t d   t j d d g d t j d t j } | j   \ } } | j d k r|y  t | j   d	  |  j  _ Wn. t k
 rq|  j t d
  t d   t SX|  j   S|  j t d
  t d  d |  t Sn
 |  j   Sd S(   s   Call appopriate run_* method according to command line arguments.
        
        Return True if at least one report has been processed, and False
        otherwise.
        s   Invalid problem reportt    s^   After closing this message please click on an application window to report a problem about it.t   xpropt   _NET_WM_PIDt   stdoutt   stderri    is   Cannot create reports2   xprop failed to determine process ID of the windows   

N(   R   R   R   R:   t   filebugR   R   R   t   versiont   __version__t
   crash_fileRZ   RV   Rl   Ro   R1   R
   t   windowR   t
   subprocesst   Popent   PIPEt   communicatet
   returncodeR   R0   R   R+   R]   (   RT   RD   R   t   outt   err(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_argv.  sB    


  
c      	   C   s
  t  j t d   } | j d d d t d  | j d d d d	 g  d t d
  | j   \ |  _ |  _ t |  j  d k s |  j d j   r | j	 d  t
 j d  n  t |  j d  |  j _ d |  j _ t |  j _ d |  j _ d |  j _ g  |  _ d S(   sg   Parse command line options when being invoked in update mode.

        Return (options, args).
        s   %prog <report number>s   -ps	   --packaget   helps   Specify package name.s   --tagRe   R   t   defaults@   Add an extra tag to the report. Can be specified multiple times.i   i    s-   You need to specify a report number to updateN(   t   optparset   OptionParserR1   t
   add_optiont
   parse_argsR   t   argsR   t   isdigitR   R"   R#   R   R   RK   R   RV   R   R   R   (   RT   t	   optparser(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   parse_argv_update]  s    )c         C   s  t  t j  d k r d t j k ri t j j t j j t j d  t j j t j d   t j d <n  t j d } | j	 d  s | j	 d  r |  j
   d Sn  t j t d   } | j d d d	 d
 d d d t d t d  | j d d d	 d
 d t d t d  | j d d d d d d d t d  | j d d d d d t d  | j d d d t d   | j d! d" d d d t d#  | j d$ d% d d& d t d'  t j j | j d( d d& d t d)  | j d* d	 d+ d g  d t d,  | j d- d. d	 d
 d t d/  t  t j  d k rw| j	 d0  rwx& d7 D] } t j | j |  _ qUWn  | j   \ |  _ |  _ t  t j  d k rd St  t j  d1 k r| j	 d0  rt |  j _ d St  |  j  d1 k rd St j j t j j t |  j d d2   rLt |  j _ |  j d |  j _ g  |  _ n/|  j d j	 d3  sx|  j d j	 d4  r|  j d |  j _ g  |  _ n |  j d j   rt |  j _ |  j d |  j _  g  |  _ n d5 |  j d k rSt j! j" |  j d  } | s/| j# d6 |  j d  t j$ d1  n  g  |  _ t |  j _ | |  j _% n( t |  j _ |  j d |  j _% g  |  _ d S(8   s   Parse command line options.

        If a single argument is given without any options, this tries to "do
        what I mean".
        i    t   APPORT_INVOKED_ASs   -update-bugs   -collectNsF   %prog [options] [symptom|pid|package|program path|.apport/.crash file]s   -fs
   --file-bugRe   t
   store_truet   destR   R   R   s   Start in bug filing mode. Requires --package and an optional --pid, or just a --pid. If neither is given, display a list of known symptoms. (Implied if a single argument is given.)s   -ws   --windows7   Click a window as a target for filing a problem report.s   -us   --update-bugt   typeR   R   s;   Start in bug updating mode. Can take an optional --package.s   -ss	   --symptomt   metavart   SYMPTOMsW   File a bug report about a symptom. (Implied if symptom name is given as only argument.)s   -ps	   --packages   Specify package name in --file-bug mode. This is optional if a --pid is specified. (Implied if package name is given as only argument.)s   -Ps   --pids   Specify a running program in --file-bug mode. If this is specified, the bug report will contain more information.  (Implied if pid is given as only argument.)s   -cs   --crash-filet   PATHs   Report the crash from given .apport or .crash file instead of the pending ones in %s. (Implied if file is given as only argument.)s   --saves   In bug filing mode, save the collected information into a file instead of reporting it. This file can then be reported later on from a different machine.s   --tagR   s@   Add an extra tag to the report. Can be specified multiple times.s   -vs	   --versions    Print the Apport version number.s   -bugi   s   .pys   .crashs   .apportt   /s    %s does not belong to a package.(   s   -fs   -us   -ss   -ps   -Ps   -c(&   R   R"   t   argvR   R3   R   R5   t   dirnameR    t   endswithR   R   R   R1   R   RV   R   R'   t
   report_dirt   SUPPRESS_HELPt
   get_optionR   R   R   R   R:   R   R   R   R   R   R   R   R.   t   get_file_packageR   R#   R?   (   RT   t   cmdR   t   ot   pkg(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRS   t  s~    &
$$,,	c         C   sf   | d k  r$ t  j d | d  d S| d k  rH t  j d | d  d St  j d | t d   d S(	   sC   Format the given integer as humanly readable and i18n'ed file size.i@B s   %.1fg     @@s    KBi ʚ;g    .As    MBs    GB(   R   t   formatt   float(   RT   t   size(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   format_filesize  s
    c         C   s   d } xr |  j  D]g } |  j  | r y& | t |  j  | j  d d 7} Wqw t k
 rs | t |  j  |  7} qw Xq q W| S(   s'   Return the size of the complete report.i    i   i   (   R=   R   t	   gzipvaluet   AttributeError(   RT   R   t   k(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   get_complete_size  s    &"c         C   s   d } x |  j  D]v } | d k r |  j  | r y& | t |  j  | j  d d 7} Wq t k
 r | t |  j  |  7} q Xq q q W| S(   s&   Return the size of the reduced report.i    R`   i   i   (   R=   R   R   R   (   RT   R   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   get_reduced_size  s    &%c         C   st   |  j  j d  s t  t j   d k rp t j   t j d d d |  j  j d |  j  d   t j	 d  n  d S(   s   Reopen the crashed application.R   i    t   shs   -ct   RespawnCommandi   N(
   R=   R&   Rq   R   t   forkt   setsidt   execlpRn   R"   R#   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRg     s
    
,c         C   s  |  j  r4 |  j j d  r4 | r4 |  j j   n|  j d d k rZ d |  j k rZ d S|  j   t |   } |  j j d  sTt j j   } t	 j	 d t
 d d d	 |  j |  j |  j  | | | f  } | j   xI | j   r|  j   y | j   Wq t k
 rt j d
  q Xq W| j   t j j   t j j |  | j   n  |  j j d  rt d |  j d  |  _ n  |  j d d k s|  j d d k s|  j j d  rlt	 j	 d |  j j d	 |  j j   f  } | j   xL | j   r<|  j   y | j d  Wqt k
 r8t j d
  qXqW| j   | j   rl| j   |  j d <qln  |  j   d |  j k s|  j d j d  rd |  j k r|  j t  d  t  d   |  j!   t j d
  n  d S(   sH  Collect additional information.

        Call all the add_*_info() methods and display a progress dialog during
        this.

        In particular, this adds OS, package and gdb information and checks bug
        patterns.

        If a symptom script is given, this will be run first (used by
        run_symptom()).
        R   R   R   Ra   Nt   targett   nameRH   R   i   R   Rc   Rd   R   g?t   BugPatternURLR   t   Kernels   Invalid problem reports7   Could not determine the package or source package name.("   RM   R=   R&   R   t!   ui_start_info_collection_progresst   HookUIR   R3   t   copyt   REThreadRH   RL   t   startt   isAlivet!   ui_pulse_info_collection_progresst   process_eventt   KeyboardInterruptR"   R#   R5   t   clearR   t	   exc_raiseR    RK   RN   t   search_bug_patternst   get_bugpattern_baseurlt   return_valuet    ui_stop_info_collection_progressR   Ro   R1   Rt   (   RT   RA   RB   t   hookuit   orig_envt   icthreadt   bpthread(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRw     s\    "



8



&
c      	   C   s%  t  j   \ } } t  j   d k r t  j |  t  j   \ } } | r t d  } t d |  } t  j |  j   } | r | d | 7} n  |  j | |  n  y t  j |  Wn t	 k
 r n Xd St  j
   t  j |  yJ t t  j d   }	 t t  j d   }
 d d	 d
 d t |	  g } Wn) t k
 rYt  j   }	 d }
 g  } n Xyyv t  j d  rt j d d d
 t |	  d g d t j d t j d k rt j | d | g  t j d  n  Wn t	 k
 rn Xygt  j d  rMt j d d d
 t |	  d g d t j d t j d k rMt j | d d d g d t j d t j } | j d k r| j   d } t j d |  } | rt j | | j d  d | g  t j d  n  t j d |  } | rt j | | j d  d | g  t j d  qn  t j | d | g  d k rMt j d  qMn  Wn t	 k
 ran X|	 r|
 rt  j |
 g  t  j |
  t  j |	  t  j d  t  j! |	  j" t  j# d <n  t$ j% | d t& d t& t j d  Wn6 t' k
 r } t  j( | t |   t j d   n Xd S(!   sj   Open the given URL in a new browser window.

        Display an error dialog if everything fails.
        i    s   Unable to start web browsers'   Unable to start web browser to open %s.s   
Nt   SUDO_UIDt   SUDO_GIDt   sudos   -Hs   -ut   #t   DISPLAYt   pgreps   -xt	   ksmserverR   R   s   kde-opens   gnome-panel|gconfd-2t	   gconftools   --gets(   /desktop/gnome/url-handlers/http/commands!   ((firefox|seamonkey|flock)[^\s]*)s   -new-windows   (epiphany[^\s]*)s   --new-windows
   gnome-opent	   SUDO_USERt   HOMEt   newt	   autoraisei   ()   R   t   pipeR   R;   t   waitR1   t   fdopent   readlineRo   Rl   R   R   t   getenvR   t	   TypeErrort   getuidRK   R   t   callR   R"   R#   R   R   R   t   ret   matcht   groupt	   setgroupst   setgidt   setuidt   unsetenvt   pwdt   getpwuidt   pw_dirR3   t
   webbrowserR7   R:   t	   ExceptionR9   (   RT   t   urlR   R   R   t   statusRE   R   t   messaget   uidt   gidt   sudo_prefixt   gctt   preferred_browsert   browserRD   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   open_urlT  s    
 
!!
##c   
      C   s  |  j  j d  |  j  j d  k rI y |  j  d =WqI t k
 rE qI Xn  d a d   } |  j   t j d |  j j d |  j  | f  } | j	   x.| j
   r|  j t  y | j d  | j   Wq t k
 r t j d  q t k
 r} t d  } |  j | t |   } | d k	 r| \ } } |  j j | |  t j d |  j j d |  j  | f  } | j	   qq t k
 r} |  j t d	  d
 t d  t |  f  d SXq W| j   | j   } |  j   |  j j |  j  |  }	 |	 r|  j |	  n  d S(   sG   Upload the current report and guide the user to the reporting web page.t   PackageArchitecturet   Architecturec         S   s   t  |   | a d  S(   N(   R   t   _UserInterface__upload_progress(   t   sentt   total(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   progress_callback  s    R  R   g?i   sD   Please enter your account information for the %s bug tracking systems   Network problems   %s

%ssH   Cannot connect to crash database, please check your Internet connection.N(   R=   Rn   R)   RK   RD  t   ui_start_upload_progressR  RN   t   uploadR	  R
  t   ui_set_upload_progressR5   R  R  R"   R#   R   R1   t   ui_question_userpassR
   t   set_credentialsR7  Ro   R  t   ui_stop_upload_progresst   get_comment_urlRA  (
   RT   RG  t   upthreadRD   R:  t   datat   usert   passwordt   ticketR8  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR~     sP    $	

		

c         C   sX  yM t  j   |  _ |  j j t |  d d d |  j k rL t d   n  Wn t k
 r d |  _ |  j t	 d  t	 d   t
 St k
 r } d |  _ |  j t	 d  | j  t
 St t t t j f k
 r} d |  _ |  j t	 d  d t	 d	  t |  f  t
 SX|  j j d
  rB|  j d
 j   d |  _ n$ t  j j |  j j d d   |  _ |  j d d k rT|  j j d d  } t j j |  st	 d  } | rd | |  j d f } n  d |  _ |  j t	 d  |  t
 Sd |  j k rTt j j |  j d  sQt	 d  } |  j t	 d  d | |  j d f  t
 SqTn  t S(   s   Load report from given path and do some consistency checks.

        This might issue an error message and return False if the report cannot
        be processed, otherwise self.report is initialized and True is
        returned.
        t   binaryt
   compressedR   s+   Report does not contain "ProblemType" fields   Memory exhaustionsE   Your system does not have enough memory to process this crash report.s   Invalid problem reports   %s

%ss7   This problem report is damaged and cannot be processed.R   i    R   R   R   sI   This problem report applies to a program which is not installed any more.s   %s (%s)t   InterpreterPathN(   R   R   R=   t   loadR7   R+   t   MemoryErrorRK   Ro   R1   RV   Rx   R   R)  Rq   Ry   R   Rz   R&   R0   RM   R'   R(   Rn   R   R   R   R   R:   (   RT   R   RD   t   exe_patht   msg(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRm     sP    				$	
c         C   s   d |  j  k r t |  j  d t  rE |  j  d j d  |  j  d <n  |  j t d  |  j  d j   d t d  |  j  d  t St S(   sn   Check if the current report is unreportable.

        If so, display an info message and return True.
        R   s   UTF-8s   Problem in %sR   i    s#   The problem cannot be reported:

%s(	   R=   t
   isinstanceR   R   R   R1   R0   R:   RV   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR{     s     $	c         C   s   |  j  j d  r; t j j |  j  d  r; |  j  d } n t j j |  j  } | r y  d d l	 } | j
 j
 |  SWq d SXn  d S(   s   Return a matching xdg.DesktopEntry for the current report.
        
        Return None if report cannot be associated to a .desktop file.
        t   DesktopFileiN(   R=   R&   R   R   R   R   R'   t   find_package_desktopfileRM   t   xdg.DesktopEntryt   DesktopEntryRK   (   RT   t   desktop_filet   xdg(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRs   &  s    +c         C   sJ   |  j  j d  s t S|  j t d  t d   |  j |  j  d  t S(   s   Check if current report matches a bug pattern.

        If so, tell the user about it, open the existing bug in a browser, and
        return True.
        R  s   Problem already knowns   This problem was already reported in the bug report displayed in the web browser. Please check if you can add any further information that might be helpful for the developers.(   R=   R&   RV   R   R1   RA  R:   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR|   6  s    
c         C   sj   |  j  s t  |  j j rf |  j  j d d  } | rC | d 7} n  | d j |  j j  |  j  d <n  d S(   s6   Add extra tags to report specified with --tags on CLI.t   TagsR   t    N(   R=   Rq   R   t   tagRn   R5   (   RT   t   tags(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR   G  s    c         C   s   t  d   d S(   s  Ask what to do with a crash.

        Inform that a crash has happened for self.report and self.cur_package
        and ask about an action.

        If the package can be mapped to a desktop file, an xdg.DesktopEntry is
        passed as an argument; this can be used for enhancing strings, etc.

        Return the action and options as a dictionary:

        - Valid values for the 'action' key: ignore the crash ('cancel'), restart
          the crashed application ('restart'), or report a bug about the crash
          ('report').
        - Valid values for the 'blacklist' key: True or False (True will cause
          the invocation of report.mark_ignore()).
        s.   this function must be overridden by subclassesN(   t   NotImplementedError(   RT   t   desktopentry(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRu   U  s    c         C   s   t  d   d S(   s#  Ask what to do with a package failure.

        Inform that a package installation/upgrade failure has happened for
        self.report and self.cur_package and ask about an action.

        Return the action: ignore ('cancel'), or report a bug about the problem
        ('report').
        s.   this function must be overridden by subclassesN(   Rf  (   RT   Rg  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRp   h  s    	c         C   s   t  d   d S(   s   Ask what to do with a kernel error.

        Inform that a kernel crash has happened for self.report and ask about
        an action.

        Return the action: ignore ('cancel'), or report a bug about the problem
        ('report').
        s.   this function must be overridden by subclassesN(   Rf  (   RT   Rg  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRr   s  s    	c         C   s   t  d   d S(   sk  Show details of the bug report.
        
        This lets the user choose between sending a complete or reduced report.

        This method can use the get_complete_size() and get_reduced_size()
        methods to determine the respective size of the data to send, and
        format_filesize() to convert it to a humanly readable form.

        If is_update is True, the text should describe that an existing report is
        updated, otherwise a new report will be created.

        Return the action: send full report ('full'), send reduced report
        ('reduced'), or do not send anything ('cancel').
        s.   this function must be overridden by subclassesN(   Rf  (   RT   t	   is_update(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR}   ~  s    c         C   s   t  d   d S(   s:   Show an information message box with given title and text.s.   this function must be overridden by subclassesN(   Rf  (   RT   RE   t   text(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    c         C   s   t  d   d S(   s4   Show an error message box with given title and text.s.   this function must be overridden by subclassesN(   Rf  (   RT   RE   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRo     s    c         C   s   t  d   d S(   s   Open a indefinite progress bar for data collection.
        
        This tells the user to wait while debug information is being
        collected.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    c         C   s   t  d   d S(   sa   Advance the data collection progress bar.

        This function is called every 100 ms.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    c         C   s   t  d   d S(   s,   Close debug data collection progress window.s.   this function must be overridden by subclassesN(   Rf  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    c         C   s   t  d   d S(   s{   Open progress bar for data upload.

        This tells the user to wait while debug information is being uploaded.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRH    s    c         C   s   t  d   d S(   s   Update data upload progress bar.

        Set the progress bar in the debug data upload progress window to the
        given ratio (between 0 and 1, or None for indefinite progress).

        This function is called every 100 ms.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   t   progress(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRJ    s    c         C   s   t  d   d S(   s(   Close debug data upload progress window.s.   this function must be overridden by subclassesN(   Rf  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRM    s    c         C   s   d S(   sl   Called right before terminating the program.
        
        This can be used for for cleaning up.
        N(    (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRt     s    c         C   s   t  d   d S(   s   Show a yes/no question.

        Return True if the user selected "Yes", False if selected "No" or
        "None" on cancel/dialog closing.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    c         C   s   t  d   d S(   sm  Show an question with predefined choices.

        options is a list of strings to present. If multiple is True, they
        should be check boxes, if multiple is False they should be radio
        buttons.

        Return list of selected option indexes, or None if the user cancelled.
        If multiple == False, the list will always have one element.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   Ri  R   t   multiple(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    
c         C   s   t  d   d S(   sm   Show a file selector dialog.

        Return path if the user selected a file, or None if cancelled.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   ui_question_file  s    c         C   s   t  d   d S(   s   Request username and password from user.

        message is the text to be presented to the user when requesting for
        username and password information.

        Return a tuple (username, password), or None if cancelled.
        s.   this function must be overridden by subclassesN(   Rf  (   RT   R:  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRK    s    N(-   t   __name__t
   __module__t   __doc__RU   R]   R:   RZ   RK   R   R   R   R   R   R   RS   R   R   R   Rg   RV   Rw   RA  R~   Rm   R{   Rs   R|   R   Ru   Rp   Rr   R}   R   Ro   R  R  R  RH  RJ  RM  Rt   R   R   Rl  RK  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRI      sP   		d	R	0		/		^					
P	X	6	6															
					R  c           B   sP   e  Z d  Z d   Z d   Z d   Z e d  Z d   Z d   Z	 d   Z
 RS(   sg  Interactive functions which can be used in package hooks.

    This provides an interface for package hooks which need to ask interactive
    questions. Directly passing the UserInterface instance to the hooks needs
    to be avoided, since we need to call the UI methods in a different thread,
    and also don't want hooks to be able to poke in the UI.
    c         C   sF   | |  _  t j   |  _ t j   |  _ d |  _ d |  _ d |  _ d S(   sS   Create a HookUI object.

        ui is the UserInterface instance to wrap.
        N(	   R@   t	   threadingt   Eventt   _request_eventt   _response_eventRK   t   _request_fnt   _request_argst	   _response(   RT   R@   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRU     s    			c         C   s   |  j  d d |  S(   s   Show an information with OK/Cancel buttons.

        This can be used for asking the user to perform a particular action,
        such as plugging in a device which does not work.
        R   R   (   t   _trigger_ui_request(   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   information  s    c         C   s   |  j  d |  S(   s   Show a yes/no question.

        Return True if the user selected "Yes", False if selected "No" or
        "None" on cancel/dialog closing.
        R   (   Rw  (   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   yesno  s    c         C   s   |  j  d | | |  S(   sm  Show an question with predefined choices.

        options is a list of strings to present. If multiple is True, they
        should be check boxes, if multiple is False they should be radio
        buttons.

        Return list of selected option indexes, or None if the user cancelled.
        If multiple == False, the list will always have one element.
        R   (   Rw  (   RT   Ri  R   Rk  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   choice  s    
c         C   s   |  j  d |  S(   sm   Show a file selector dialog.

        Return path if the user selected a file, or None if cancelled.
        Rl  (   Rw  (   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   file*  s    c         G   s   |  j  j   s t  |  j j   s, t  |  j d k sA t  d |  _ | |  _ | |  _ |  j  j   |  j j	   d |  _ |  j j
   |  j S(   s5   Called by HookUi functions in info collection thread.N(   Rr  t   is_setRq   Rs  Rt  RK   Rv  Ru  t   setR%  R  (   RT   t   fnR   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRw  5  s    				c         C   sx   |  j  j d  |  j  j   s# d S|  j j   s9 t  |  j  j   t |  j |  j  |  j	   |  _
 |  j j   d S(   s;   Called by GUI thread to check and process hook UI requests.g?N(   Rr  R%  R|  Rs  Rq   R  t   getattrR@   Rt  Ru  Rv  R}  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR  H  s    !(   Rm  Rn  Ro  RU   Rx  Ry  RV   Rz  R{  Rw  R  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s   					t   __main__(   t   StringIOt   _TestSuiteUserInterfacec           B   s   e  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 d   Z d   Z RS(   s6   Concrete UserInterface suitable for automatic testing.c         C   s   t  j   |  _ |  j j d  |  j j   |  j j t j d <t j	 |   t
 |  _ d |  _ t
 |  _ d |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ t
 |  _ |  j   d  S(   Nsz   default = 'testsuite'
databases = {
    'testsuite': { 
        'impl': 'memory',
        'bug_pattern_url': None
    }
}
t   APPORT_CRASHDB_CONFi    (   t   tempfilet   NamedTemporaryFilet   crashdb_confR9   t   flushR  R   R3   RI   RU   RV   t   ic_progress_activet   ic_progress_pulsest   upload_progress_activet   upload_progress_pulsesRK   t   present_crash_responset   present_package_error_responset   present_kernel_error_responset   present_details_responset   question_yesno_responset   question_choice_responset   question_file_responset
   opened_urlt   present_details_shownt	   clear_msg(   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRU   f  s(    														c         C   s(   d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   RK   t	   msg_titlet   msg_textt   msg_severityt   msg_choices(   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    			c         C   s   |  j  S(   N(   R  (   RT   Rg  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRu     s    c         C   s   |  j  S(   N(   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRp     s    c         C   s   |  j  S(   N(   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRr     s    c         C   s   t  |  _ |  j S(   N(   R:   R  R  (   RT   Rh  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR}     s    	c         C   s   | |  _  | |  _ d |  _ d  S(   Nt   info(   R  R  R  (   RT   RE   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    		c         C   s   | |  _  | |  _ d |  _ d  S(   NR   (   R  R  R  (   RT   RE   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRo     s    		c         C   s   d |  _  t |  _ d  S(   Ni    (   R  R:   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    	c         C   s"   |  j  s t  |  j d 7_ d  S(   Ni   (   R  Rq   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    c         C   s   t  |  _ d  S(   N(   RV   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    c         C   s   d |  _  t |  _ d  S(   Ni    (   R  R:   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRH    s    	c         C   s"   |  j  s t  |  j d 7_ d  S(   Ni   (   R  Rq   R  (   RT   Rj  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRJ    s    c         C   s   t  |  _ d  S(   N(   RV   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRM    s    c         C   s   | |  _  d  S(   N(   R  (   RT   R8  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRA    s    c         C   s   | |  _  |  j S(   N(   R  R  (   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    	c         C   s   | |  _  | |  _ |  j S(   N(   R  R  R  (   RT   Ri  R   Rk  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    		c         C   s   | |  _  |  j S(   N(   R  R  (   RT   Ri  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRl    s    	(   Rm  Rn  Ro  RU   R  Ru   Rp   Rr   R}   R   Ro   R  R  R  RH  RJ  RM  RA  R   R   Rl  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR  c  s&   	%																t   _Tc           B   s  e  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 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& d$   Z' d%   Z( d&   Z) d'   Z* d(   Z+ d)   Z, d*   Z- d+   Z. d,   Z/ d-   Z0 d.   Z1 d/   Z2 d0   Z3 d1   Z4 d2   Z5 d3   Z6 RS(4   c         C   so  x< d d d d g D]( } y t  j | =Wq t k
 r: q Xq Wt j j |  _ t j   t j _ t	 |  _
 t j   a	 t j j |  _ t j   \ } t j _ t  j |  t j |  _ d g t _ t   |  _ t j   |  _ d |  j d <d |  j d	 <d
 |  j d <d d |  j d <d d |  j d <t j   |  _ |  j   t j   |  _ t j j |  _ |  j t j _ d  S(   Nt   LANGt   LANGUAGEt   LC_MESSAGESt   LC_ALLs   ui-tests	   /bin/bashR   s   libfoo1 1-1R   t   fooR   t   Ai  t   Fooi R`   (   R   R3   R)   R   R'   R   t   orig_report_dirR  t   mkdtempR   t   orig_symptom_script_dirR=   t   _ignore_filet   orig_ignore_filet   mkstempR;   R"   R   t	   orig_argvR  R@   R   R  RL   t   update_report_filet   hookdirR   t   orig_hook_dir(   RT   t   vt   fd(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   setUp  s4    	
c         C   sA   |  j  j d  |  j  j   |  j j |  j   |  j  j   d  S(   Ni    (   RL   t   seekt   truncateR=   R9   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    s    c         C   s   |  j  t _ t j t j j  |  j t j _ d  |  _ t j t
  |  j a
 d  |  _ t j t j j  |  j t j _ d  |  _ |  j j   |  j t j d d g  d d  |  j t j d d g  d d  t j |  j  |  j t j _ d  S(   Nt   pidofs   /bin/cati   s   no stray catss
   /bin/sleeps   no stray sleeps(   R  R"   R   t   shutilt   rmtreeR   R'   R   R  RK   R   R  R   t   unlinkR=   R  R  R@   RL   R;   t   assertEqualR   R+  R  R  R   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   tearDown  s    				""c         C   s   |  j  |  j j d  d  |  j  |  j j d  d  |  j  |  j j d  d  |  j  |  j j d  d  |  j  |  j j d	  d
  |  j  |  j j d  d  |  j  |  j j d  d  |  j  |  j j d  d  d S(   s   format_filesize().i    s   0.0 KBi   s   2.0 KBi 
  s   2.6 KBi?B s	   1000.0 KBi@B s   1.0 MBg@s   2.7 MBi   s   1.0 GBs   2.6 GBNg    pDAi  	=l     -1 (   R  R@   R   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_format_filesize  s    c         C   s%  |  j  j |  j j  t j j |  j j  } t |  j  j    | } |  j	 | d k ob | d k  |  j  j
   } |  j	 | d k  |  j	 | d k   d d |  j  j d <|  j  j   } |  j	 | | d k  |  j	 | | d	 k   |  j  j
   } |  j	 | d
 k  |  j	 | d	 k   d S(   s>   get_complete_size() and get_reduced_size() for loaded Reports.gGz?g)\(?i  i'  R  iP  t	   ExtraInfoi  i`  i8  N(   R@   Rm   RL   R  R   R   t   getsizeR   R   t
   assertTrueR   R=   (   RT   t   fsizet   complete_ratiot   rst   s(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_get_size_loaded  s    c         C   sw   t  j d  |  j _ d |  j j d <|  j j   } |  j | d k  |  j | d k   |  j | |  j j    d S(   sB   get_complete_size() and get_reduced_size() for on-the-fly Reports.R   t   Worldt   Helloi   id   N(   R   R   R@   R=   R   R  R  R   (   RT   R  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_get_size_constructed6  s    c         C   sz  |  j  j |  j j  |  j |  j  j |  j  |  j |  j  j d	  |  j d =|  j d =|  j d =|  j   |  j  j |  j j  |  j	 |  j  j d	 k  |  j |  j  j t
 d   |  j |  j  j d  |  j  j   |  j j d  |  j j   |  j j d  |  j j   |  j  j |  j j  |  j	 |  j  j d	 k  |  j |  j  j t
 d   |  j |  j  j d  d	 S(
   s   load_report().R   R   R   s   Invalid problem reportR  i    s5   Type: test
Package: foo 1-1
CoreDump: base64
 bOgUs=
R   N(   R@   Rm   RL   R  R  R=   R  RK   R  R  R1   R  R  R  R  R9   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_load_reportB  s*    



	c         C   s  t  j j t j j d  } t  j j t j j d  } d | |  j d <|  j   |  j j	 |  j
 j  |  j j   t j d  |  j t  j j |   |  j t  j j |   t  j |  d | |  j d <|  j   |  j j	 |  j
 j  |  j j   t j d  |  j t  j j |   |  j t  j j |   t  j |  |  j d =d |  j d <|  j   |  j j	 |  j
 j  d S(   s
   restart().R   t   Customs   touch i   R   s   /nonexistingN(   R   R   R5   R   R'   R   R=   R  R@   Rm   RL   R  Rg   t   timet   sleepR  R   R  (   RT   R   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_restartf  s,    



c         C   sv   t  j   |  j _ |  j j   |  j t d d d d g  j t |  j j j      |  j	 |  j j
 d d  d S(   s:   collect_info() on report without information (distro bug).R   t   UnameR   R   i    s1   no progress dialog for distro bug info collectionN(   R   R   R@   R=   Rw   R  R}  t   issubsett   keysR  R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_collect_info_distro  s    c      
   C   s   t  j   |  _ d |  j d <|  j   |  j j |  j j  d t f |  j j d <t	 j
 d  |  j j d <|  j j   |  j t d d d	 d
 d d d d g  j t |  j j j      |  j |  j j d k d  |  j |  j j t d  d S(   s2   collect_info() on report with only ExecutablePath.s	   /bin/bashR   s
   /etc/fstabt   Fstabt   Testt   CompressedValueR   R   R   R  Rh   R   R   i    s/   progress dialog for package bug info collections8   progress dialog for package bug info collection finishedN(   R   R   R=   R  R@   Rm   RL   R  R:   t   problem_reportR  Rw   R  R}  R  R  R  R  R  RV   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_collect_info_exepath  s    
(c      	   C   s   t  j   |  j _ d |  j _ |  j j   |  j t d d d d d d d g  j t |  j j j	      |  j |  j j
 d	 k d
  |  j |  j j t d  d S(   s(   collect_info() on report with a package.t   bashR   R   R   R  Rh   R   R   i    s/   progress dialog for package bug info collections8   progress dialog for package bug info collection finishedN(   R   R   R@   R=   RM   Rw   R  R}  R  R  R  R  R  RV   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_collect_info_package  s    	(c         C   s   |  j  j |  j j  |  j |  j  j   t  |  j |  j  j d  |  j |  j  j	 d  d } | |  j
 d <|  j   |  j  j |  j j  |  j |  j  j   t  |  j |  j  j d  |  j |  j  j	 |  d S(   s   handle_duplicate().s   http://example.com/1R  R  N(   R@   Rm   RL   R  R  R|   RV   R  RK   R  R=   R  R:   R  (   RT   t   demo_url(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_handle_duplicate  s    
c         C   s2   g  t  _ t   |  _ |  j |  j j   t  d S(   s1   running the frontend without any pending reports.N(   R"   R   R  R@   R  R   RV   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_nopending  s    	c         C   sN   d d g t  _ t   |  _ |  j |  j j   t  |  j |  j j d  d S(   s.   run_report_bug() without specifying arguments.s   ui-tests   -fR   N(   R"   R   R  R@   R  R   RV   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_report_bug_noargs  s    c         C   sy   d d g t  _ t   |  _ t  j } t   t  _ |  j |  j j   t  t  j j	   } | t  _ |  j | t
 d  d S(   s7   run_report_bug() as "ubuntu-bug" with version argument.s
   ubuntu-bugs   -vs   
N(   R"   R   R  R@   R   R  R  R   R:   t   getvalueR   (   RT   t   orig_stdoutt   output(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_version  s    		c         C   sr  d d d d g t  _ t   |  _ |  j |  j j   t  |  j |  j j d  |  j |  j j	 d  |  j
 |  j j  |  j |  j j d |  j j j    |  j
 |  j j d k  |  j |  j j d d  |  j
 d |  j j j   k  |  j
 d	 |  j j j   k  |  j |  j j d
 d  d d d d g t  _ t   |  _ |  j j   |  j |  j j d  d S(   s   run_report_bug() for a package.s   ui-tests   -fs   -pR  s   http://bash.bugs.example.com/%ii    R   Rh   t   ProcEnvironR   R   t   nonexisting_gibberishR   N(   R"   R   R  R@   R  R   R:   R  RK   R  R  R  R  RN   t	   latest_idR  R=   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_report_bug_package  s     &c         C   sH  t  j   } | d k r@ t  j d d d g  t s@ t d  n  t j d  zJ d d d	 d
 d t |  g t _	 t
   |  _ |  j |  j j   t  Wd t  j | t j  t  j | d  X|  j d |  j j j   k  |  j d |  j j j   k  |  j d |  j j j   k  |  j |  j j d d  |  j |  j j j d   |  j d |  j j j   k  |  j |  j j d d  |  j d |  j j j   k  |  j d
 |  j j d k  |  j |  j j d  |  j |  j j d  |  j |  j j d |  j j j    |  j |  j j  |  j |  j j d k  d S(   s+   run_report_bug() for a pid with extra tags.i    s
   /bin/sleepR  t   10000s   Could not execute /bin/sleepg      ?s   ui-tests   -fs   --tagR  s   -PNR   Rh   t   ProcMapsR   R   R  R   R   Rb  s$   http://coreutils.bugs.example.com/%i(    R   R   t   execvRV   Rq   R  R  R   R"   R   R  R@   R  R   R:   t   killt   signalt   SIGKILLt   waitpidR  R=   R  t   assertFalseR&   R  RK   R  R  RN   R  R  R  (   RT   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_report_bug_pid_tags  s2    !&c         C   sa   d } xT t  r\ | d 7} y t j | d  Wq	 t k
 rX } | j t j k rY PqY q	 Xq	 W| S(   s   Find and return an unused PID.i   i    (   R:   R   R  Rl   R   t   ESRCH(   t   klassR   RD   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   _find_unused_pid  s    	
c         C   sD   |  j    } d d d t |  g t _ t   |  _ |  j j   d S(   s'   run_report_bug() for a nonexisting pid.s   ui-tests   -fs   -PN(   R  R   R"   R   R  R@   R   (   RT   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_report_bug_wrong_pid-  s    c         C   sc   t  j   d k s t d  d d d d g t _ t   |  _ |  j j   |  j |  j j	 d  d S(	   s:   run_report_bug() for a pid which runs as a different user.i    s!   this test must not be run as roots   ui-tests   -fs   -Pt   1R   N(
   R   R*  Rq   R"   R   R  R@   R   R  R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_report_bug_noperm_pid7  s
    c         C   s  t  j   \ } } t j | t d  j    t j |  t j | d  t j   } | d k ry t j	 | | g  n  zA d d d t
 |  g t _ t   |  _ |  j t |  j j  Wd t j | t j  t j   t j |  X|  j |  j j d  d S(	   s4   run_report_bug() for a pid of an unpackaged program.s   /bin/cati  i    s   ui-tests   -fs   -PNR   (   R  R  R   R9   R7   R   R;   R8   R   R  R   R"   R   R  R@   t   assertRaisest
   SystemExitR   R  R  R  R%  R  R  R  (   RT   R  t   exenameR   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt"   test_run_report_bug_unpackaged_pidB  s    
c         C   s   d d l  } d } x] | j  d  D]L } t |  j   j   } t | d  } | t @r" t | d  } Pq" q" W|  j | d k  d d d t |  g t	 _
 t   |  _ |  j j   |  j |  j j d	 j t j j     d S(
   s.   run_report_bug() for a pid of a kernel thread.iNs   /proc/[0-9]*/stati   i    s   ui-tests   -fs   -PR   (   R   RK   R7   R   R0   R   R   R  R   R"   R   R  R@   R   R  R=   R   R   R.   R   (   RT   R   R   R   R   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt!   test_run_report_bug_kernel_thread[  s    
c         C   s  t  j j t j j d  } t  j |  t  j j | d  } d d d d d | g t _ t	   |  _
 |  j |  j
 j   t  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j  |  j |  j
 j d k  t j   } | j t |   |  j | d	 d  |  j d
 | j   k  |  j d | j   k  |  j | d d  d d | g t _ t	   |  _
 d |  j
 _ |  j |  j
 j   t  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j  d S(   s0   run_report_bug() with saving report into a file.t   homes   bashisbad.apports   ui-tests   -fs   -pR  s   --savei    R   Rh   R  R   R   s   -cRj   N(   R   R   R5   R   R'   R   t   mkdirR"   R   R  R@   R  R   R:   R  RK   R  R  R  R  R  R  R   RW  R7   R  R  R  (   RT   t   dR>   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_report_bug_filen  s0    c         C   s:  d } t  j | t  j  s( t | d  t  j   } | d k r t j t j d  t  j t	 j
 j  t  j | | g  t s t d |  n  t j d  t	 j   } | | d <d | d	 <| j |  | j   t  j j t	 j
 j d
  } t  j | t j  t  j | d  t  j j |  s)t  | f | d <| S(   s'   Generate a Report with real crash data.s   /bin/cats    is not executablei    is   Could not execute g      ?R   t   11R_   t   coreR`   (   ii(   R   t   accesst   X_OKRq   R   t   resourcet	   setrlimitt   RLIMIT_COREt   chdirR   R'   R   R  RV   R  R  R   R   R   R   R5   R  R  t   SIGSEGVR  R   (   RT   t   test_executableR   R   t   coredump(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   _gen_test_crash  s(    "


c         C   s  |  j    } t j j t j j d  } | j t | d   t	   |  _
 i d d 6t d 6|  j
 _ |  j
 j |  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j  | j t | d   t	   |  _
 i d d 6t d 6|  j
 _ d |  j
 _ |  j
 j |  |  j |  j
 j d d |  j
 j t |  j
 j  t |  j
 j  f  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j  | j t | d   t	   |  _
 i d d 6t d 6|  j
 _ d	 |  j
 _ |  j
 j |  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d
 |  j
 j j    |  j |  j
 j d  |  j |  j
 j  |  j d |  j
 j j   k  |  j d |  j
 j j   k  |  j d |  j
 j j   k  |  j d |  j
 j j   k  |  j |  j
 j d d  |  j t |  j
 j d  d k  |  j |  j
 j d j  d   | j t | d   t	   |  _
 i d d 6t d 6|  j
 _ d |  j
 _ |  j
 j |  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d
 |  j
 j j    |  j |  j
 j d  |  j |  j
 j  |  j d |  j
 j j   k  |  j d |  j
 j j   k  |  j d |  j
 j j   k  |  j |  j
 j d d  |  j |  j
 j j! d   |  j |  j
 j j"    | j t | d   t	   |  _
 i d d 6t# d 6|  j
 _ |  j
 j |  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j j"    d S(   s   run_crash().s
   test.crashR   Rb   Re   Rf   i    R=   s   has %s message: %s: %sRj   s$   http://coreutils.bugs.example.com/%iR   Rh   Ra   R  R   R   R`   i'  R   s   cat crashed with SIGSEGVRi   N($   R  R   R   R5   R   R'   R   R9   R7   R  R@   RV   R  RZ   R  R  RK   R  R  R  R  R  R  R   R  t   assertNotEqualR  RN   R  R=   R  R   R   R&   t   check_ignoredR:   (   RT   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash  s    /&# &c         C   s@  |  j    } d | d <t j j t j j d  } | j t | d   i d d 6t	 d 6|  j
 _ d |  j
 _ |  j
 j |  |  j d	 |  j
 j j   k  |  j d
 |  j
 j j   k  |  j d |  j
 j j   k  |  j d |  j
 j j   k  |  j |  j
 j d d  |  j |  j
 j d  |  j |  j
 j  d S(   s4   run_crash() for an abort() without assertion messaget   6R_   s
   test.crashR   R=   Re   Rf   Rj   R   Rh   Ra   R  N(   R  R   R   R5   R   R'   R   R9   R7   RV   R@   R  R  RZ   R  R=   R  R  R  RK   R  (   RT   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_abort  s    
c         C   s  d |  j  d <|  j   d d |  j j g t _ t   |  _ d |  j _ |  j	 |  j j
   t  |  j	 |  j j d  |  j	 |  j j d  |  j |  j j  d |  j  d <d |  j  d <|  j   d d |  j j g t _ t   |  _ |  j	 |  j j
   t  |  j d |  j j k d	 |  j j |  j j f  |  j	 |  j j d
  |  j |  j j  d d d g t _ t   |  _ |  j	 |  j j
   t  |  j	 |  j j d  d S(   s9   run_crash() through a file specified on the command line.R  R   s   ui-tests   -cRj   u   It stinks. ♥R   s
   It stinks.s   %s: %sR  s   /nonexisting.crashR   N(   R=   R  RL   R  R"   R   R  R@   R  R  R   R:   R  RK   R  R  R  R  R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_argv_file   s.    

c         C   s   d |  j  d <d |  j  d <d |  j  d <|  j   i d d 6t d	 6|  j _ d
 |  j _ |  j j |  j j  |  j	 d |  j j
 k d |  j j |  j j
 f  |  j |  j j d  d S(   sE   run_crash() on a crash with the UnreportableReason
            field.s
   It stinks.R   s	   /bin/bashR   s   bash 1R   R=   Re   Rf   Rj   s   %s: %sR  N(   R=   R  RV   R@   R  R  RZ   RL   R  R  R  R  R  R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_unreportableE  s    
c         C   sa   d |  j  d <d |  j  d <d |  j  d <|  j   |  j j |  j j  |  j |  j j d  d S(   s-   run_crash() on a crash with the Ignore field.R:   R^   s	   /bin/bashR   s   bash 1R   N(	   R=   R  R@   RZ   RL   R  R  R  RK   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_ignoreV  s    
c         C   s{  d } t  j | t  j  s( t | d  t  j   } | d k rs t  j   t  j | | g  t ss t d |  n  zH t j	 d  t
 j   } | | d <d | d <| j |  | j   Wd	 t  j | t j  t  j | d  Xt  j j t
 j j d
  } | j t | d   t   |  _ |  j j |  |  j |  j j d  |  j d |  j j k d |  j j |  j j f  d	 S(   s.   run_crash() for a crash dump without CoreDump.s   /bin/cats    is not executablei    s   Could not execute g      ?R   t   42R_   Ns
   test.crashR   R   t   memorys   %s: %s(    R   R  R  Rq   R   R   R  RV   R  R  R   R   R   R   R  R  R  R  R   R5   R'   R   R9   R7   R  R@   RZ   R  R  R  R  R  (   RT   R  R   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_nocorea  s.    "


c         C   s-  |  j    } | j   | d =t j j t j j d  } | j t	 | d   t
   |  _ i d d 6t d 6|  j _ d |  j _ |  j j |  |  j |  j j d
 d |  j j t |  j j  t |  j j  f  |  j |  j j d
  |  j |  j j d
  |  j |  j j d	  |  j |  j j  d
 S(   s   run_crash() pre-retraced reports.
            
            This happens with crashes which are pre-processed by
            apport-retrace.R`   s
   test.crashR   R=   Re   Rf   Rb   s   has %s message: %s: %si    N(   R  R   R   R   R5   R   R'   R   R9   R7   R  R@   RV   R  R  RZ   R  R  RK   R   R  R  R  R  R  R  (   RT   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_preretraced  s    
/c         C   s   t  j   } d | d <d | d <d | d <t j j t  j j d  } | j t | d   |  j	 j
 |  |  j |  j	 j t d   |  j |  j	 j d	  d
 S(   s(   run_crash() on various error conditions.s	   /bin/bashR   t	   foobarbazR   R   s
   test.crashR   s   Invalid problem reportR   N(   R   R   R   R   R5   R'   R   R9   R7   R@   RZ   R  R  R1   R  (   RT   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_errors  s    


c         C   s  |  j    } d | d <d | d <t j j t j j d  } | j t | d   i d d 6t	 d	 6|  j
 _ |  j
 j |  |  j |  j
 j t d
   |  j |  j
 j d  t j   } d | d <d | d <d | d <|  j
 j |  |  j |  j
 j t d
   |  j |  j
 j d  t j   } d | d <d | d <d | d <|  j
 j |  |  j |  j
 j t d
   |  j |  j
 j d  d S(   s=   run_crash() on reports with subsequently uninstalled packagess   /bin/nonexistingR   R  R   s
   test.crashR   R=   Re   Rf   s   Invalid problem reportR  s   /usr/bin/pythonRV  s5   ZeroDivisionError: integer division or modulo by zerot	   Tracebacks   /bin/shs   /usr/bin/nonexistingN(   R  R   R   R5   R   R'   R   R9   R7   RV   R@   R  RZ   R  R  R1   R  R   (   RT   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_uninstalled  s.    







c         C   sm  t  j d  } d | d <d | d <d | d <d | d <| j   t j j t  j j d  } | j t	 | d	   t
   |  _ d
 |  j _ |  j j |  |  j |  j j d  |  j |  j j d  |  j |  j j d  |  j |  j j d  |  j |  j j  | j t	 | d	   t
   |  _ d |  j _ d |  j _ |  j j |  |  j |  j j d  |  j |  j j d  |  j |  j j d |  j j j    |  j |  j j  |  j d |  j j j   k  |  j d |  j j j   k  |  j |  j j d d  |  j d |  j j j   k  |  j d |  j j j   k  |  j d |  j j j   k  d S(   s    run_crash() for a package error.R   R  R   s   It broket   ErrorMessages   foo
bart   VarLogPackagerlogs
   test.crashR   Rb   i    R=   Rj   s   http://bash.bugs.example.com/%iR   RC  R   R  N(   R   R   R   R   R   R5   R'   R   R9   R7   R  R@   R  RZ   R  R  RK   R  R  R  R  R  R  RN   R  R  R=   R  (   RT   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_package  s>    




&c         C   so  t  t j j |  j d  d  } | j d  | j   t j d  } t j	 j
   | d <d | d <t j j t j j d  } | j t  | d   t   |  _ d	 |  j _ |  j j |  |  j |  j j d d
 |  j j |  j j f  |  j |  j j d  |  j |  j j d  |  j |  j j d  |  j |  j j  | j t  | d   t   |  _ d |  j _ d |  j _ |  j j |  |  j |  j j d t |  j j  d t |  j j   |  j |  j j d  |  j |  j j d |  j j j    |  j |  j j  |  j d |  j j j    k  |  j d |  j j j    k  |  j |  j j d d  d S(   s   run_crash() for a kernel error.s   source_linux.pyR   sF   def add_info(report, ui): 
    report['KernelDebug'] = 'LotsMoreInfo'
Rc   R   R   R   s
   test.crashRb   s   error: %s - %si    R=   Rj   Rc  s    http://linux.bugs.example.com/%it   KernelDebugR   N(!   R7   R   R   R5   R  R9   R;   R   R   R.   R   R'   R   R  R@   R  RZ   R  R  RK   R  R  R  R  R  R  R  R   RN   R  R  R=   R  (   RT   RG   R   RL   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_kernel	  s>    !

'&c         C   s/  |  j    } t j j t j j d  } | j t | d   t	   |  _
 i d d 6t d 6|  j
 _ d |  j
 _ |  j
 j |  |  j d |  j
 j k  t   } |  j
 j j |  t j t j    } t j   d | d	 | d
 | d t j   g } x. | D]& } |  j | | j   k d |  qWd S(   s   run_crash() anonymization.s
   test.crashR   R=   Re   Rf   Rb   t   ProcCwdi   i    i   i   s"   dump contains sensitive string: %sN(   R  R   R   R5   R   R'   R   R9   R7   R  R@   RV   R  R  RZ   R  R=   R  R3  R4  R*  t   unamet   getcwdR  (   RT   R   RL   t   dumpR   t   bad_stringsR  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_crash_anonymity3	  s    	1c         C   s   d d d g t  _ t   |  _ t j j j d d i d d 6 |  j _	 |  j
 |  j j   t  |  j d |  j j k  |  j |  j j  d S(	   s8   run_update_report() on a nonexisting package (from bug).s   ui-tests   -uR  R   i   t
   dummy_datas$   No additional information collected.N(   R"   R   R  R@   R   t   crashdb_implR  t   CrashDatabaseRK   RN   R  R   RV   R  R  R  R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt3   test_run_update_report_nonexisting_package_from_bugI	  s    	c         C   s   d d d d d g t  _ t   |  _ t j j j d
 d i d d 6 |  j _	 |  j
 |  j j   t  |  j d	 |  j j k  |  j |  j j  d
 S(   s<   run_update_report() on a nonexisting package (CLI argument).s   ui-tests   -uR  s   -pt   barR   i   R  s$   No additional information collected.N(   R"   R   R  R@   R   R   R  R!  RK   RN   R  R   RV   R  R  R  R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt.   test_run_update_report_nonexisting_package_cliV	  s    	c         C   sj  d d d g t  _ t   |  _ t j j j d d i d d 6 |  j _	 d |  j j	 j
 d  d <d |  j j	 j
 d  d	 <|  j |  j j   t  |  j |  j j d |  j j  |  j |  j j d  |  j |  j j d  |  j |  j j  |  j |  j j d
 k  |  j |  j j d	 j d   |  j d |  j j j   k  |  j d |  j j j   k  d S(   s6   run_update_report() on an existing package (from bug).s   ui-tests   -uR  R   i   R  R  R   R   i    s   bash Rh   R  N(   R"   R   R  R@   R   R   R  R!  RK   RN   t   downloadR  R   R:   R  R  R  R  R  R  R  R=   R   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt0   test_run_update_report_existing_package_from_bugc	  s     c         C   sa  d d d d d d d g t  _ t   |  _ t j j j d d i d	 d
 6 |  j _	 |  j
 |  j j   t  |  j
 |  j j d |  j j  |  j
 |  j j d  |  j
 |  j j d  |  j |  j j  |  j |  j j d k  |  j |  j j d j d   |  j d |  j j j   k  |  j d |  j j j   k  |  j d |  j j d k  d S(   sH   run_update_report() on an existing package (CLI argument) with extra tags   ui-tests   -uR  s   -pR  s   --tagR  R   i   R  i    R   s   bash Rh   R  Rb  N(   R"   R   R  R@   R   R   R  R!  RK   RN   R  R   R:   R  R  R  R  R  R  R  R=   R   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt0   test_run_update_report_existing_package_cli_tagsx	  s     c         C   s;  d d d d g t  _ t   |  _ t j j j d d i d d 6 |  j _	 |  j
 |  j j   t  |  j
 |  j j d |  j j  |  j
 |  j j d  |  j
 |  j j d  |  j |  j j  |  j |  j j d k  |  j |  j j d	 j d
   |  j d |  j j j   k  |  j d |  j j j   k  d S(   s>   run_update_report() on an existing package (-collect program).s   apport-collects   -pR  R  R   i   R  i    R   s   bash Rh   R  N(   R"   R   R  R@   R   R   R  R!  RK   RN   R  R   R:   R  R  R  R  R  R  R  R=   R   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt3   test_run_update_report_existing_package_cli_cmdname	  s     c         C   sn  d d d g t  _ t   |  _ t j j j d d i d d 6 |  j _	 t
 t j j |  j d  d  } | j d	  | j   |  j |  j j   t |  j j  |  j |  j j d |  j j  |  j |  j j d  |  j |  j j d  |  j |  j j  |  j |  j j d
 k  |  j |  j j d d  |  j |  j j d d  |  j d |  j j j   k  d S(   sA   run_update_report() on an uninstalled package with a source hook.s   ui-tests   -uR  R   i   R  s   source_foo.pyR   s1   def add_info(r, ui):
  r["MachineType"]="Laptop"
i    R   s   foo (not installed)t   MachineTypet   LaptopR  N(   R"   R   R  R@   R   R   R  R!  RK   RN   R7   R   R   R5   R  R9   R;   R  R   R:   R=   R  R  R  R  R  R  R  R  (   RT   RG   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt,   test_run_update_report_noninstalled_but_hook	  s     !
"c         C   s   t  t j j |  j d  d  } | j d d j g  | j   D] } d | ^ q=   | j   d |  j j	 _
 |  j j   d  S(   Ns   coreutils.pyR   s   def add_info(report, ui):
%s
s   
s       t	   coreutils(   R7   R   R   R5   R  R9   t
   splitlinesR;   R@   R   R?   R   (   RT   t   codeRG   t   l(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt	   _run_hook	  s    !	.
c         C   s[   |  j  d  |  j |  j j d d  |  j |  j j d d  |  j |  j j d  d S(   s'   interactive hooks: HookUI.information()sE   report['begin'] = '1'
ui.information('InfoText')
report['end'] = '1'
t   beginR  t   endt   InfoTextN(   R0  R  R@   R=   R  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt"   test_interactive_hooks_information	  s
    c         C   s  t  |  j _ |  j d  |  j |  j j d d  |  j |  j j d d  |  j |  j j d  |  j |  j j d d  t |  j _ |  j j   |  j |  j j d d  |  j |  j j d d  d
 |  j _ |  j j   |  j |  j j d d	  |  j |  j j d d  d
 S(   s!   interactive hooks: HookUI.yesno()sU   report['begin'] = '1'
report['answer'] = str(ui.yesno('YesNo?'))
report['end'] = '1'
R1  R  R2  s   YesNo?t   answerR:   RV   RK   N(
   R:   R@   R  R0  R  R=   R  RV   R   RK   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_interactive_hooks_yesno	  s    c         C   s   d |  j  _ |  j d  |  j |  j  j d d  |  j |  j  j d d  |  j |  j  j d  |  j |  j  j d d  d	 |  j  _ |  j  j   |  j |  j  j d d  |  j |  j  j d d  d	 S(
   s    interactive hooks: HookUI.file()s
   /etc/fstabsW   report['begin'] = '1'
report['answer'] = str(ui.file('YourFile?'))
report['end'] = '1'
R1  R  R2  s	   YourFile?R5  RK   N(   R@   R  R0  R  R=   R  RK   R   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_interactive_hooks_file	  s    c         C   s   d g |  j  _ |  j d  |  j |  j  j d d  |  j |  j  j d d  |  j |  j  j d  |  j |  j  j d d  d
 |  j  _ |  j  j   |  j |  j  j d d	  |  j |  j  j d d  d
 S(   s"   interactive hooks: HookUI.choice()i   sk   report['begin'] = '1'
report['answer'] = str(ui.choice('YourChoice?', ['foo', 'bar']))
report['end'] = '1'
R1  R  R2  s   YourChoice?R5  s   [1]RK   N(   R@   R  R0  R  R=   R  RK   R   (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_interactive_hooks_choices	  s    c         C   s   |  j  t |  j d  d S(   s   interactive hooks: user cancelss>   report['begin'] = '1'
raise StopIteration
report['end'] = '1'
N(   R  R  R0  (   RT   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_interactive_hooks_cancel
  s    c         C   s  d d d g t  _ t   |  _ |  j |  j j   t  |  j d |  j j k  |  j |  j j	 d  t
 t j j t d  d  } | j d  | j   t  j } d d d	 g t  _ t   |  _ t   t  _ |  j t |  j j  t  j j   } | t  _ |  j d
 | k  t
 t j j t d  d  } | j d  | j   d d d g t  _ t   |  _ t   t  _ |  j t |  j j  t  j j   } | t  _ |  j d | k  t
 t j j t d  d  } | j d  | j   d d d g t  _ t   |  _ t   t  _ |  j t |  j j  t  j j   } | t  _ |  j d | k  |  j d | k  t
 t j j t d  d  } | j d  | j   d d d g t  _ t   |  _ |  j |  j j   t  |  j |  j j d(  |  j |  j j	 d(  |  j |  j j  |  j |  j j d d  |  j d |  j j k  |  j |  j j d d  |  j |  j j d j d   |  j |  j j d d  d d  d! d d g t  _ t   |  _ |  j |  j j   t  |  j |  j j d(  |  j |  j j	 d(  |  j |  j j  |  j |  j j d d  |  j d! |  j j d" k  t
 t j j t d  d  } | j d#  | j   d d d g t  _ t   |  _ t |  j _ |  j |  j j   t  |  j |  j j  |  j |  j j d$  |  j |  j j d d%  |  j d |  j j k  |  j |  j j d d  |  j |  j j d j d   |  j |  j j d d  |  j |  j j d& d'  d( S()   s   run_symptom()s   ui-tests   -st   foobars   foobar" is not knownR   s   nopkg.pyR   s   def run(report, ui):
    pass
t   nopkgs&   did not determine the affected packages   norun.pys"   def something(x, y):
    return 1
t   noruns   norun.py crashed:s   crash.pys$   def run(report, ui):
    return 1/0
t   crashs   crash.py crashed:s   ZeroDivisionError:s
   itching.pysB   def run(report, ui):
  report["itch"] = "scratch"
  return "bash"
t   itchingt   itcht   scratchR   R   R  R   s   bash R   R   s   --tagR  Rb  sn   def run(report, ui):
    report['itch'] = 'slap'
    report['q'] = str(ui.yesno('do you?'))
    return 'bash'
s   do you?t   slapt   qR:   N(   R"   R   R  R@   R  R   R:   R  R  R  R7   R   R   R5   R   R9   R;   R   R  R  R  R  RK   R  R=   R   R  (   RT   RG   t   orig_stderrR   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_run_symptom
  s    
		
	
	
 
 c         C   s  t  t j j t d  d  } | j d  | j   t  t j j t d  d  } | j d  | j   d d g t _ t	   |  _
 d |  j
 _ |  j |  j
 j   t  |  j |  j
 j d  |  j d |  j
 j k  |  j t |  j
 j  t d	 d
 d g   |  j |  j
 j d  |  j |  j
 j d  |  j |  j
 j  |  j
 j j d
  g |  j
 _ |  j |  j
 j   t  |  j |  j
 j d  |  j |  j
 j d k  |  j |  j
 j  |  j |  j
 j d j d   d S(   sE   run_report_bug() without specifying arguments and available symptoms.s   foo.pyR   sI   description = 'foo does not work'
def run(report, ui):
    return 'bash'
s   bar.pys*   def run(report, ui):
  return "coreutils"
s   ui-tests   -fs   kind of problemR#  s   foo does not works   Other problemi    R   R  N(   R7   R   R   R5   R   R9   R;   R"   R   R  R@   RK   R  R  R   R:   R  R  R  R}  R  R  R=   R  R  t   indexR   (   RT   RG   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt!   test_run_report_bug_list_symptomso
  s0    

c            s    f d   } | d d i	 t d 6d d 6d d 6d d 6d d 6d d 6d d	 6t d
 6g  d 6   j t | d d i   | d d i	 t d 6d d 6d d 6d d 6d d 6d d 6d d	 6t d
 6g  d 6 t t j j t	 d  d  } | j
 d  | j   | d d i	 t d 6d d 6d d 6d d 6d d 6d d 6d d	 6t d
 6g  d 6 | d d i	 t d 6d d 6d d 6d d 6d d 6d d 6d d	 6t d
 6g  d 6 xe d D]] } | d d | i	 t d 6d d 6d d 6d | d 6d d 6d d 6d d	 6t d
 6g  d 6 qW| d d i	 t d 6d d 6d d 6d d 6d d 6d d 6d d	 6t d
 6g  d 6 | d d i t d 6d d 6d d 6d d 6d d 6g  d 6 | d d i t d 6d d 6d d 6d d 6d d 6g  d 6 d S(   s3   parse_args() option inference for a single argumentc            s   |  g t  _ | r% t  j j |  n  t  j } t d d  t  _ z t   } Wd  t  j j   | t  _ Xd  | d <  j | j	 g     j | j
 |  d  S(   Ns	   /dev/nullR   R   (   R"   R   R   R   R7   RI   R;   RK   R  R   R   (   t   program_namet   argt   expected_optsRC  R@   (   RT   (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   _chk
  s    	

s
   apport-gtkR   R?   R   R   R   R   R   R   Rd  s   apport-collects
   apport-kdeR,  s   coreutils.pyR   sI   description = 'foo does not work'
def run(report, ui):
    return 'bash'
s
   apport-clit   1234s   .crashs   .apports	   /tmp/f oos   /usr/bin/taili  s   apport-update-bugN(   s   .crashs   .apport(   RK   RV   R  R  R:   R7   R   R   R5   R   R9   R;   (   RT   RJ  RG   t   suffix(    (   RT   s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_parse_argv_single_arg
  sN    
c            sb    f d   } | g  i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6g  d
 6 | d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6g  d
 6 t t j j t d  d  } | j d  | j	   | d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6g  d
 6 t j
 t j j t d   | d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6g  d
 6 xe d D]] } | d | g i	 t d 6d d 6d d 6d | d 6d d 6d d 6d d 6t d	 6g  d
 6 qW| d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6g  d
 6 | d d d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6g  d
 6 | d d d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6d g d
 6 | d d d d d g i	 t  d 6d d 6d d 6d d 6d d 6d d 6d d 6t d	 6d d g d
 6 d S(   s3   parse_args() option inference when invoked as *-bugc            s   d g |  t  _ t  j } t d d  t  _ z t   } Wd  t  j j   | t  _ Xd  | d <  j | j g     j | j	 |  d  S(   Ns
   apport-bugs	   /dev/nullR   R   (
   R"   R   R   R7   RI   R;   RK   R  R   R   (   R   RI  RC  R@   (   RT   (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRJ  
  s    	

R   R?   R   R   R   R   R   R   Rd  R,  s   coreutils.pyR   sI   description = 'foo does not work'
def run(report, ui):
    return 'bash'
RK  s   .crashs   .apports	   /tmp/f oos   /usr/bin/tails   --saves
   foo.apports   --tagR  R#  N(   s   .crashs   .apport(   R:   RK   RV   R7   R   R   R5   R   R9   R;   R  (   RT   RJ  RG   RL  (    (   RT   s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   test_parse_argv_apport_bug
  sX    
(7   Rm  Rn  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  t   classmethodR  R  R  R  R  R  R  R  R  R	  R
  R  R  R  R  R  R  R  R  R"  R$  R&  R'  R(  R+  R0  R4  R6  R7  R8  R9  RD  RF  RM  RN  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR    sh   	'						$	!									%	
				%		U		%			$			&	-	/															b	$	I(6   Ro  R   R   R"   t   os.pathR   R   R  R$   R   RQ   R,  R3  R   t   urllibRy   R   Rp  R6  R   t   apport.fileutilsR  t   apport.crashdbR    R   R   R1   R3   Rn   R   R   R
   RK   RV   RH   RI   R  Rm  t   unittestR  R  R  R  t	   cStringIOR  RO   t   iot   apport.reportR  t   apport.crashdb_impl.memoryR  t   TestCaseR  t   main(    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   <module>   sH   l0$$		^    ue<l     i