
qxPXc           @   sC  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 m Z m Z d d l m Z e j j d d  Z d Z d	   Z e e d
  Z d f  d     YZ d f  d     YZ  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   2.0.1iN(   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         B   s,  |  j    |  j   | r i  } y} e e |  j   | d  | f d U| d |  |  } | sv e j d |  d Se j j	 e j j
 |   d |  d <Wq e k
 r e j d  q e j d |  e j   e j d  q Xn  | s(d |  k re j j |  d  } q(e d	   n  y |  j |  Wn@ e k
 rX| s|  q|n$ e k
 r{} e |  |  d
 <d SX|  j |  re j d  n  y d |  k r d e j k r d |  k re d  |  d
 <q e j j |  d j   d  s e d  |  d j   d |  d
 <q n  Wn e k
 r@| sA  qAn Xd |  k ro|  j   } | ro| |  d <qon  |  d d k rd e j k r|  j   }	 |	 re d  d j |	  |  d
 <qn  | r(e | d  }
 e j  | d  |  j! |
 d e" |
 j#   e j j$ |  e 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   execNt   runs8   symptom script %s did not determine the affected packagei    t   Symptoms   symptom script %s crashed:t   ExecutablePathsA   called without a package, and report does not have ExecutablePatht   UnreportableReasont   CrashDBt   APPORT_DISABLE_DISTRO_CHECKt   Packages4   This package does not seem to be installed correctlysX   This is not an official %s package. Please remove any third party package and try again.t   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   compilet   opent   readt   apportt   errort   ost   patht   splitextt   basenamet   StopIterationt   syst   exitt	   tracebackt	   print_exct	   fileutilst   find_file_packaget   KeyErrort   add_package_infot
   ValueErrort   SystemErrorR
   t   add_hooks_infot   environt   _t	   packagingt   is_distro_packaget   splitt   standard_titlet   obsolete_packagest   joint   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$   sv    

&*
	 #
 
t   UserInterfacec           B   s  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   Z d   Z d( e d( 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, 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 |  _ t |  _ y t d  |  _ WnF t	 k
 rk } 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_packaget   Falset   offer_restartR    t   crashdbt   ImportErrorR   t   fatalR   R,   t   gettextt
   textdomaint
   parse_argv(   t   selfRE   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   __init__   s    					c         C   sj   t  } t |  _ t j   d k r3 t j j   } n t j j   } x! | D] } |  j	 |  t } qI 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    (
   RO   R;   RP   R!   t   geteuidR   R*   t   get_new_system_reportst   get_new_reportst	   run_crash(   RW   t   resultt   reportsRH   (    (    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 St j j   } |  j |  } | d s6| d rIy  d |  j k rU|  j   n  WqIt t j f k
 r} d |  _ |  j t d  d t d  t |  f  |  j   d St k
 r|  j t d  t d   |  j   d St k
 rE} t j t |   |  j t d  t d  d t |   |  j   d SXn  |  j d k r\d S| d rt|  j   d S| d r|  j   n  | d r|  j j   n  | d sd Sd |  j k r|  j d d k rt j j |  n  |  j j |  j  r*|  j   rd S|  j    rd S|  j!   n  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   examinet   Dependenciess   Invalid problem reports7   This problem report is damaged and cannot be processed.s6   The report belongs to a package that is not installed.sB   An error occurred while attempting to process this problem report:s   

t   restartt	   blacklistt   MarkForUploadRO   s2   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(+   RM   R   R*   R=   t   OSErrort   load_reportR>   t   getR!   R"   R$   R2   t   ui_error_messaget   allowed_to_reportt   ui_present_report_detailst   collect_infot   IOErrort   zlibR    RL   t   reprt   ui_shutdownR.   t	   ExceptionR   Rd   Rf   t   mark_ignoret   mark_report_uploadRQ   t   acceptst   handle_duplicatet   check_unreportablet   file_reportt   errnot   EPERMt   EACCESR&   R'   t   ENOSPCt   strerrort   ENOMEMRS   (   RW   RM   t   confirmt   subjectt   headingRn   t   responseRE   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR\      s    				







c         C   so  |  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'   Wqkt t f k
 r2} |  j t d  t( |   qkXn5 t j) j*   } |  j+ |  } | d rk|  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 reportR>   (-   t   optionsR@   t   pidt   run_symptomsR;   Rm   R2   RO   R   t   ReportR>   R   R   R5   t   intt
   PF_KTHREADt   add_proc_infoR.   Rq   Rj   R|   t   ENOENTR~   t   add_proc_environt   stripR3   t   get_kernel_packageRN   Rp   R   Rz   t   add_extra_tagsRy   R,   t   saveR!   R"   t
   expanduserR:   R<   R
   R*   Rn   Ro   R{   (   RW   RB   t   statt   flagsRE   RH   Rn   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_report_bug1  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 St	 j  j!   } |  j" |  } | d r|  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, ignoringRC   s$   No additional information collected.R   t   Datei    R>   s   apport informationt   change_descriptiont   attachment_comment($   RQ   t
   can_updateR   t   update_reportRm   R2   RO   t   is_reportert   ui_question_yesnoR   R   R>   R@   R   t   get_affected_packagesRN   R3   t   get_versionR.   R!   R"   t   existsR8   t	   _hook_dirRp   R;   t   ui_info_messaget   add_user_infoR   R   R,   t   lenR*   Rn   Ro   t   update(   RW   R   t   rt   pkgst   info_collectedt   pRn   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   run_update_report  sh    	+	





c         B   s  e  j  e j j e d   } g  } g  } x | D] } e j j |  j d  rX q1 n  i  } y* e e |  j	   | d  | f d UWn$ e
 j d |  e j   q1 n Xd | k r e
 j d |  q1 n  | j e j j e j j |   d  | j | j d	 | d
   q1 W| s%e Se e e | |     \ } } e |  } e |  } | j d  | j d  |  j e d  | e  } | d k r| | d } | r|  j e j j e | d   qe Sn  e S(   sl   Report a bug from a list of available symptoms.

        Return False if no symptoms are available.
        s   *.pyR2   R   Ns   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   .py(   t   globR!   R"   R8   t   symptom_script_dirR$   t
   startswithR   R   R   R   R    R(   R)   t   appendR#   Rl   RO   t   zipt   sortedt   listRL   t   ui_question_choiceR2   R   R;   (   RW   t   scriptst   symptom_namest   symptom_descriptionst   scriptRD   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"   R8   R   R   R   R   Rm   R2   R   (   RW   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 d k	 rL |  j   S|  j  j	 ra 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
 rw|  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   RL   R   t   versiont   __version__t
   crash_fileR\   RO   Rj   Rm   R2   R
   t   windowR   t
   subprocesst   Popent   PIPEt   communicatet
   returncodeR   R5   R   R.   R_   (   RW   RE   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   --tagt   actionR   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   OptionParserR2   t
   add_optiont
   parse_argsR   t   argsR   t   isdigitR    R&   R'   R   R   RL   R   RO   R   R   R   (   RW   t	   optparser(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   parse_argv_updateS  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-bugR   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!   R1   R"   R8   t   dirnameR$   t   endswithR   R   R   R2   R   RO   R   R*   t
   report_dirt   SUPPRESS_HELPt
   get_optionR   R   R   R   R;   R   R   R   R   R   R   R   R3   t   get_file_packageR    R'   R@   (   RW   t   cmdR   t   ot   pkg(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRV   j  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(   RW   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(   RW   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    Rb   i   i   (   R>   R   R   R   (   RW   R   R   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   get_reduced_size  s    &%c         C   s   |  j  s d |  j  k r t Sy5 t j d d g d t j d t j d k rQ t SWn t k
 rf t SXy |  j d  SWn t	 k
 r t SXd S(   s   Check whether to offer the "Examine locally" button.

        This will be true if the report has a core dump, apport-retrace is
        installed and a terminal is available (see ui_run_terminal()).
        Rb   s   apport-retraces   --helpR   R   i    N(
   R>   RO   R   t   callR   t   STDOUTRj   t   ui_run_terminalRL   t   NotImplementedError(   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   can_examine_locally  s    c         C   sq   d |  j  k s t  t j   d k rm 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>   t   AssertionErrorR!   t   forkt   setsidt   execlpRl   R&   R'   (   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRf     s
    
,c         C   s   |  j  t d  t d  t d  t d  |  j g t  } | d k rM d Sd t j j d  } d } d	 |  j j d	 d
  d	 } i | d | d 6| d | d 6| d | d | d 6} |  j	 | | d  d S(   s   Locally examine crash report.sJ   This will launch apport-retrace in a terminal window to examine the crash.s   Run gdb sessions1   Run gdb session without downloading debug symbolss)   Update %s with fully symbolic stack traceNs"   apport-retrace -S system -C %s -v s   ~/.cache/apport/retraces   apport-retrace t   's   '\''s   --gdb i    i   s	   --output t    i   (
   R   R2   RM   RO   RL   R!   R"   R   R   R   (   RW   R   t   retrace_with_downloadt   retrace_no_downloadt   fileargt   cmds(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRd     s"    				
c         C   s1  d |  j  d <d |  j  k r d |  j  k r t |  j  d  } |  j  d =t t j |  j  d  j  } | | k r d |  j  d <t d  |  j  d |  j  d <d Sn  |  j r d |  j  k r | r |  j  j   nH|  j  j d	  d
 k r d |  j  k s#|  j  j d	  d
 k r7d |  j  k r7| r3|   n  d S|  j	   t
 |   } d |  j  k r1t j j   } t j 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  d |  j  k r\t d |  j  d  |  _ n  |  j  d	 d k s|  j  d	 d k sd |  j  k rFt j j d |  j  j d |  j j    f  }	 |	 j   xL |	 j   r|  j   y |	 j d  Wqt k
 rt j d  qXqW|	 j   |	 j!   rF|	 j!   |  j  d <qFn  |  j  d	 d k r*t j j d |  j j" d |  j  f  }
 |
 j   xL |
 j   r|  j   y |
 j d  Wqt k
 rt j d  qXqW|
 j   |
 j!   } | d k	 r*| t# k rd |  j  d <q'| |  j  d <q*n  t j j d |  j  j$  } | j   xL | j   r|  j   y | j d  WqRt k
 rt j d  qRXqRW| j   |  j%   d |  j  k s|  j  d	 j& d  rd |  j  k r|  j' t d  t d   |  j(   t j d  n  | r-|   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;   Rh   R   t   ExecutableTimestampRO   sP   The problem happened with the program %s which changed since the crash occurred.R   NR   R   Rc   Re   t   targett   nameRI   R   i   R   t   KernelCrasht
   KernelOopsR   g?t   KnownReportR   t   1R   t   Kernels   Invalid problem reports7   Could not determine the package or source package name.()   R>   R   R!   R   t   st_mtimeR2   RN   R   Rl   t!   ui_start_info_collection_progresst   HookUIR1   t   copyR   t   REThreadRI   RM   t   startt   isAlivet!   ui_pulse_info_collection_progresst   process_eventt   KeyboardInterruptR&   R'   R8   t   clearR   t	   exc_raiseR    RL   RQ   t   search_bug_patternst   get_bugpattern_baseurlt   return_valuet   knownR;   t	   anonymizet    ui_stop_info_collection_progressR   Rm   Rt   (   RW   RB   RC   t   on_finishedt	   orig_timet   cur_timet   hookuit   orig_envt   icthreadt   bpthreadt   known_threadt   valt   anonymize_thread(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRp   +  s    
	''















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 |  y5 t t  j d   }	 d d d	 d
 t |	  g }
 Wn t k
 r2g  }
 n Xy[ y t j |
 d | g  Wn9 t	 k
 r} t j | d t d t t j d  n XWn6 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   sudos   -Hs   -ut   #s   xdg-opent   newt	   autoraisei   (   R!   t   pipeR   R<   t   waitR2   t   fdopent   readlineRm   Rj   R  R   t   getenvR   t	   TypeErrorR   R   t
   webbrowserR   R;   R&   R'   Ru   R:   (   RW   t   urlR   R   R   t   statusRF   R    t   messaget   uidt   sudo_prefixRE   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   open_url  s@    
 
c   
      C   sW  |  j  j |  j  s d S|  j j d  |  j j d  k rb y |  j d =Wqb t k
 r^ qb Xn  y |  j d =Wn t k
 r n Xd a d   } |  j   t j	 j	 d |  j  j
 d |  j | f  } | j   x1| 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	 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 |  }	 |	 rS|  j |	  n  d S(   sG   Upload the current report and guide the user to the reporting web page.Nt   PackageArchitecturet   Architecturet   StacktraceAddressSignaturec         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.(   RQ   Rx   R>   Rl   R,   RL   RB  t   ui_start_upload_progressR   R  t   uploadR  R  t   ui_set_upload_progressR8   R  R  R&   R'   R   R2   t   ui_question_userpassR
   t   set_credentialsRu   Rm   R  t   ui_stop_upload_progresst   get_comment_urlR>  (
   RW   RE  t   upthreadRE   R;  t   datat   usert   passwordt   ticketR9  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR{     s\    $	

		

c         C   sU  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
 SXd
 |  j k r?|  j d
 j   d |  _ n$ t  j j |  j j d d   |  _ |  j d d k rQ|  j j d d  } t j j |  st	 d  } | rd | |  j d f } n  d |  _ |  j t	 d  |  t
 Sd |  j k rQt j j |  j d  sNt	 d  } |  j t	 d  d | |  j d f  t
 SqQ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   loadR   R.   t   MemoryErrorRL   Rm   R2   RO   Rq   R   R7  R   Rr   R    Rs   R5   RN   R*   R+   Rl   R!   R"   R   R   R;   (   RW   R"   RE   t   exe_patht   msg(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRk   !  sP    				$	
c         C   s   |  j  j |  j  s t Sd |  j k r t |  j d t  r^ |  j d j d  |  j d <n  d |  j k r t d  |  j d j   d } n d } |  j	 | 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-8R   s   Problem in %si    R   s#   The problem cannot be reported:

%s(   RQ   Rx   R>   RO   t
   isinstanceR   R   R2   R5   R   R;   (   RW   RF   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRz   W  s     $c         C   s   d |  j  k r8 t j j |  j  d  r8 |  j  d } n3 y t j j |  j  } Wn t k
 rj d } n X| 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*   t   find_package_desktopfileRN   R.   RL   t   xdg.DesktopEntryt   DesktopEntry(   RW   t   desktop_filet   xdg(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   get_desktop_entryj  s    (
c         C   s   |  j  j |  j  s t Sd |  j k r, t S|  j d j d  ru |  j t d  t d   |  j |  j d  n |  j t d  t 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  t   https   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.s;   This problem was already reported to developers. Thank you!(	   RQ   Rx   R>   RO   R   R   R2   R>  R;   (   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRy   ~  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   R  N(   R>   R   R   t   tagRl   R8   (   RW   t   tags(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     s    c         C   s   t  d   d S(   s  Show details of the bug report.

        Return the action and options as a dictionary:

        - Valid keys are: report the crash ('report'), restart
          the crashed application ('restart'), or blacklist further crashes
          ('blacklist').
        s.   this function must be overridden by subclassesN(   R   (   RW   Rn   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRo     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(   R   (   RW   RF   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(   R   (   RW   RF   Re  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRm     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(   R   (   RW   (    (    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(   R   (   RW   (    (    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(   R   (   RW   (    (    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(   R   (   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRF    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(   R   (   RW   t   progress(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRH    s    c         C   s   t  d   d S(   s(   Close debug data upload progress window.s.   this function must be overridden by subclassesN(   R   (   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRK    s    c         C   s   d S(   sd   Called right before terminating the program.

        This can be used for for cleaning up.
        N(    (   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRt     s    c         C   s   t  d   d S(   s  Run command in, or check for a terminal window.

        If command is given, run command in a terminal window; raise an exception
        if terminal cannot be opened.

        If command is None, merely check if a terminal application is available
        and can be launched.
        s.   this function must be overridden by subclassesN(   R   (   RW   t   command(    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR     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(   R   (   RW   Re  (    (    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(   R   (   RW   Re  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(   R   (   RW   Re  (    (    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(   R   (   RW   R;  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRI    s    N(-   t   __name__t
   __module__t   __doc__RX   R_   R;   R\   RL   R   R   R   R   R   R   RV   R   R   R   R   Rf   Rd   RO   Rp   R>  R{   Rk   Rz   R`  Ry   R   Ro   R   Rm   R  R  R"  RF  RH  RK  Rt   R   R   R   Ri  RI  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRJ      sR   		we	S	0		/		^						
		,	C	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(	   RA   t	   threadingt   Eventt   _request_eventt   _response_eventRL   t   _request_fnt   _request_argst	   _response(   RW   RA   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRX   )  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(   RW   Re  (    (    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   (   Rt  (   RW   Re  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   yesnoC  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   (   Rt  (   RW   Re  R   Rh  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   choiceK  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.
        Ri  (   Rt  (   RW   Re  (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   fileW  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(   Ro  t   is_setR   Rp  Rq  RL   Rs  Rr  t   setR3  R  (   RW   t   fnR   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyRt  b  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(   Ro  R3  Ry  Rp  R   R  t   getattrRA   Rq  Rr  Rs  Rz  (   RW   (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR  u  s    !(   Rj  Rk  Rl  RX   Ru  Rv  RO   Rw  Rx  Rt  R  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyR  !  s   					(!   Rl  R   R   R&   t   os.pathR!   R   R(   R   RT   R|   Rr   R   Rm  R8  R   t   apport.fileutilst   apport.REThreadt   apport.crashdbR    R   R   R2   R1   Rl   R   R   R
   RL   RO   RI   RJ   R  (    (    (    s-   /usr/lib/python2.7/dist-packages/apport/ui.pyt   <module>   s&   T$$		^    