
    !f(7             	       l   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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 ddlmZ ddlm Z  ddl!Z"ddl#Z"ddl$Z"ddl%Z"ddl&m'Z( ddl)m*Z* dZ+ejX                  j[                  d	d
      Z.dZ/d Z0d%de1de2dz  de2dz  fdZ3de1de2de2dz  fdZ4de2de5e1e1f   fdZ6ddde7e1   de8de ddfdZ9d Z:	 d&dZ;ejx                   G d d             Z= G d d       Z> G d! d"      Z? G d# d$e?      Z@y)'zAbstract Apport user interface.

This encapsulates the workflow and common code for any user interface
implementation (like GTK, Qt, or CLI).
    N)Sequence)gettext)Any)impl)get_process_user_and_groupz2.28.1APPORT_SYMPTOMS_DIRz/usr/share/apport/symptomsi    c                     	 t        j                  d| j                  dd            j                  d      }t	        |      S # t
        t        f$ r Y yw xY w)zExtract process ID from report.z
Pid:	(.*)

ProcStatus    N)researchgetgroupint
IndexErrorAttributeError)reportpids     +/usr/lib/python3/dist-packages/apport/ui.pyget_pidr   ?   sM    ii

<(DEKKAN3x' s   ?A AAkeydefaultreturnc                 j    	 t        t        j                  |          S # t        t        f$ r |cY S w xY w)zGet an environment variable as integer.

    Return None if it doesn't exist or failed to convert to integer.
    The optional second argument can specify an alternate default.
    )r   osenvironKeyError
ValueError)r   r   s     r   _get_env_intr    H   s3    2::c?##j! s    22nameuidc           	          t        j                  ddddt        |      | gddd      }|j                  dk7  s|j                  sy t        |j                  j                               S )	Npgrepz-nz-x-uTF)capture_outputchecktextr   )
subprocessrunstr
returncodestdoutr   strip)r!   r"   processs      r   _get_newest_process_for_userr0   T   s^    nn	$dCHd3	G Qgnnw~~##%&&    c                    t        d|       }|i S t        j                  d| t        j                  t        j                  z  t        j
                  z        }	 t        j                  j                  |      }	 t        j                  |       dD ci c]  }||v r|||    c}S # t        $ r i cY t        j                  |       S w xY w# t        j                  |       w xY wc c}w )zFind D-BUS address and XDG_DATA_DIRS for the given user.

    The D-BUS address and XDG_DATA_DIRS is needed for xdg-open. It is
    incredibly hard, or alternatively, unsafe to funnel it through
    pkexec/env/sudo, so grab it from gvfsd.
    gvfsd/proc/)DBUS_SESSION_BUS_ADDRESSXDG_DATA_DIRS)r0   r   openO_RDONLYO_PATHO_DIRECTORYapport	fileutilsget_process_environOSErrorclose)r"   	gvfsd_pidgvfsd_pid_fd	gvfsd_envr   s        r   _get_users_environrC   `   s     -Wc:I	77
bkkBII5FL$$88F	 	 A) 	Ys^   	
 	s*   B( C((C3C 
CC C%Fget_user_envargsrE   kwargsc                <   t        dt        d            }|t               j                         st        j                  | fddi| yt        j                  |      }t        d      }||j                  }t        j                  j                         D ci c]  \  }}|j                  d      s|dk7  r||  }}}|r|t        |      z  }|j                  |d<   t        j                  | fd|||t        j                  |j                  |      d	| yc c}}w )
a`  Call subprocess.run as real user if called via sudo/pkexec.

    If we are called through pkexec/sudo, determine the real user ID and
    run the command with it to get the user's web browser settings.
    If get_user_env is set to True, the D-BUS address and XDG_DATA_DIRS
    is grabbed from a running gvfsd and added to the process environment.
    SUDO_UID
PKEXEC_UIDNr'   FSUDO_GIDSUDO_HOME)r'   envuserr   extra_groups)r    r   is_rootr)   r*   pwdgetpwuidpw_gidr   r   items
startswithrC   pw_dirgetgrouplistpw_name)	rF   rE   rG   r"   pwuidgidkvrN   s	            r   run_as_real_userr^   |   s    z<#=
>C
{46>>@t353F3LLE
z
"C
{ll JJ$$&Aq||G$l): 	
1C 
 !#&&,,CKNN__U]]C8 s   #Dc                     	 t        j                  t        |       d       y# t        $ r,}|j                  t        j
                  k(  rY d}~yY d}~yd}~ww xY w)z8Check if the process with the given ID is still running.r   NFT)r   killr   r>   errnoESRCHr   errors     r   still_runningre      sK    
C!   ;;%++% &s   " 	AAAc                    t        |t              sJ 	 | j                          | j	                          |ri }	 t        |d      5 }t        t        |j                         |d      |       ddd        |d   | |      }|s!t        j                  j                  d|       yt        j                  j                  t        j                  j                  |            d   | d<   |s2d
| v r#t        j,                  j/                  | d
         }nt1        d      t        j,                  j3                  |      }|r| j5                  |       	 | j7                  |       d| vr| j?                  |      rt#        j$                  d       	 d| vrdt        j@                  vrd| vrd| vrtC        d      | d<   nwtE        jF                  | d   jI                         d         sNtE        jJ                  | d   jI                         d         s%tC        d      | d   jI                         d   z  | d<   d| vr| jM                         }
|
r|
| d<   | jO                  d      dk(  rDdt        j@                  vr2| jQ                         }|r tC        d      djS                  |      z  | d<   |ru	 t        |d      5 }t        jT                  |d       | jW                  |d       ddd       t        j,                  jY                  |       t        jT                  |d       yy# t        $ r Y w xY w# 1 sw Y   xY w# t         $ r t#        j$                  d       Y pt&        $ rM t        j                  j                  d	|       t)        j*                          t#        j$                  d       Y w xY w# t8        $ r |sd| vr Y ct:        $ r}	t=        |	      | d<   Y d}	~	d}	~	ww xY w# t8        $ r |sd| vr Y w xY w# 1 sw Y   %xY w# t        $ r,}	t        j                  j                  d||	       Y d}	~	Xd}	~	ww xY w)ay  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()).
    utf-8encodingexecNr*   z8symptom script %s did not determine the affected packager   Symptomzsymptom script %s crashed:ExecutablePathzAcalled without a package, and report does not have ExecutablePathSnapUnreportableReasonCrashDBAPPORT_DISABLE_DISTRO_CHECKPackagez4This package does not seem to be installed correctlyzThis does not seem to be an official %s package. Please retry after updating the indexes of available packages, if that does not work then remove related third party packages and try again.DistroReleaseTitleProblemTypeCrashAPPORT_IGNORE_OBSOLETE_PACKAGESzYou have some obsolete package versions installed. Please upgrade the following packages and check if the problem still occurs:

%sz, abT)only_newzCannot update %s: %si  )-
isinstanceHookUIadd_gdb_infor>   add_os_infor7   rj   compilereadr;   loggingrd   r   pathsplitextbasenameStopIterationsysexit	Exception	traceback	print_excr<   find_file_packager   	find_snapadd_snap_infoadd_package_infor   SystemErrorr+   add_hooks_infor   _	packagingis_distro_packagesplitis_native_origin_packagestandard_titler   obsolete_packagesjoinchmodwritemark_report_seen)r   
reportfilepackageuisymptom_scriptignore_uninstalledsymbfsnaprd   titleold_pkgss               r   thread_collect_infor      s     b&!!!
 	nw7 F1WQVVX~v>EF "d5k&"-G$$N"  " 0 01A1A.1Q RST UF9 v%&&88@P9QRGS 
 %%g.DT"
2( 6)  $HHQK	'1CF*vV/C34N4F/0 #449%++-a0#<<9%++-a0
 . !1779!<= /0& f%%'#F7O 	

=!W,-RZZ?++-+,@, 		(#	,$F'( 		Lj$' /1Q'Q./ 	))*5
U# ]   	F F  	HHQK 	NN  !=~N!HHQK	(  
 "fF&: 2'*5z#$2D  	
 &&*>	:/ /  	L
 NN  !7UKK	Ls   L L4 &L',6L4 #AL4 N- B$O$ "P .*O;P 	L$#L$'L1,L4 4N*AN*)N*-O! O!OO!$O87O8;P P 	P=!P88P=c                   X    e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   y)	ActionzAction to take on a problem report.

    Possible actions: examine the crash ('examine'), report the crash
    ('report'), restart the crashed application ('restart'), or ignore further
    crashes ('ignore').
    Fexamineignorerememberr   restartN)__name__
__module____qualname____doc__r   bool__annotations__r   r   r   r    r1   r   r   r   @  s;     GTFDHdFDGTr1   r   c                      e Zd ZdZdee   fdZd Zd Ze	d        Z
d Ze	d        Ze	d	        Zd8ded
z  defdZdefdZd Zd Zd Ze	dee   dej,                  fd       Zdee   dej,                  fdZe	d        Zd Zd Zd Zd Zd Zdedd
fdZd Z 	 d9dZ!d Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(d% Z)	 d:d&ed'e*d
z  de+fd(Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2d/e3d
z  dd
fd0Z4d1 Z5d2 Z6d3 Z7d4 Z8d5 Z9d6 Z:d7 Z;y
);UserInterfacea  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.
    argvc                    d| _         d| _        d| _        d| _        d| _        d| _        d| _        	 t        j                  j                  d      | _        t        j                   | j                          | j#                  |      | _        y# t        $ r3}t        j                  j                  dt        |             Y d}~md}~wt        $ r" t        j                  j                  d       Y w xY w)z8Initialize program state and parse command line options.r;   NFzDCould not import module, is a package upgrade in progress? Error: %sz8/etc/apport/crashdb.conf is damaged: No default database)gettext_domainr   report_filecur_packageoffer_restartspecified_a_pkgupload_progressr;   crashdbget_crashdbImportErrorr   fatalr+   r   r   
textdomain
parse_argvrF   )selfr   rd   s      r   __init__zUserInterface.__init__[  s    &37'+"$#	!>>55d;DL 	4../OOD)	  	NN  E
 
  	NN  J	s   $B 	C2)C+C21C2c                 |   d}d| _         t        j                         dk(  rt        j                  j                         }nt        j                  j                         }|D ]Y  }| j                  |      s| j                  sJ | j                  d   dk(  r| j                  |       n| j                  |       d}[ |S )a  Present all currently pending crash reports.

        Ask the user what to do about them, and offer to file bugs for them.

        Crashes that occurred in a different desktop (logind) session than the
        one that is currently running are not processed. This skips crashes
        that happened during logout, which are uninteresting and confusing to
        see at the next login.

        Return True if at least one crash report was processed, False
        otherwise.
        FTr   rt   Hang)r   r   geteuidr;   r<   get_new_system_reportsget_new_reportsload_reportr   finish_hang	run_crash)r   resultreportsr   s       r   run_crasheszUserInterface.run_crashesz  s      "::<1&&==?G&&668G 		A##A&;;;{{=)V3  #q!F		 r1   c                 P   || _         	 	 t        j                  j                  |       | j
                  s| j                  |      sy| j
                  sJ d| j
                  v ry| j
                  j                  d      dk(  rd| j
                  v rd| j
                  vrd| j
                  vrt        j                  j                  | j
                  j                  dt        d	                  }t        d
      |z  }t        d      }| j                  t        d      |z  | d|        yt        j                  j                         }| j                  |      }|j
                  s|j                  rd| j
                  vr| j!                          | j
                  y|j                  r| j                          y|j"                  r| j#                          |j$                  r| j
                  j'                          	 |j(                  r| j+                  |j
                         |j
                  syd| j
                  v r1| j
                  d   dk7  rt        j                  j/                  |       | j0                  j3                  | j
                        r3| j5                         ry| j7                         ry| j9                          yy# t        $ r Y w xY w# t,        $ r Y w xY w# t:        $ r< | j                  t        d      t        d             t=        j>                  d       Y yt        $ r}|j@                  t@        jB                  k(  r t        jD                  jG                  d        |j@                  t@        jH                  k(  r:| j                  t        d      t        d             t=        j>                  d        |j@                  t@        jJ                  k(  r:| j                  t        d      |jL                         t=        j>                  d        d}~ww xY w)zPresent 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.
        NIgnorert   ru   SignalCoreDump
Stacktracerl   zunknown programz+Sorry, the program "%s" closed unexpectedlyzxYour computer does not have enough free memory to automatically analyze the problem and send a report to the developers.Problem in %s

_MarkForUploadFalseInvalid problem reportz2You are not allowed to access this problem report.r   zOut of memory, abortingErrorz@There is not enough disk space available to process this report.)'r   r;   r<   r   r>   r   r   r   r   r   r   r   ui_error_messageallowed_to_reportui_present_report_detailsr   collect_infor   r   mark_ignorer   remember_send_reportr   mark_report_uploadr   acceptshandle_duplicatecheck_unreportablefile_reportPermissionErrorr   r   ra   ENOMEMr   r   ENOSPCEIOstrerror)r   r   subjectheadingfooterr   responserd   s           r   r   zUserInterface.run_crash  sq    'j	  11+>
 ;;t'7'7'D;;;4;;& .'9+dkk1 3''**KKOO$4a8I6JK IJWT;
 %%o&0WIT&2J  & 0 0 B B D556GHH("2"2#4;;6%%'{{"'')$$--hoo> ?? !DKK/KK 01W<  33K@ ||##DKK0 ((***,  " 1O   n  6  	!!*+FG HHQK 	{{ell*$$%>?  ,%%gJ=   		)%%a(@&A5>>R	s   K	 K( K( $CK( +A1K( K( :AK( ='K $K( 1A4K( &K( 7K( 		KK( KK( 	K%"K( $K%%K( (AP%,P%4C,P  P%c                     t         j                  j                  |        t         j                  j                  |        y)zFinish processing a hanging application after the core pipe handler
        has handed the report back.

        This will signal to whoopsie that the report needs to be uploaded.
        N)r;   r<   r   r   )r   s    r   r   zUserInterface.finish_hang  s,     	++A.))!,r1   c                 
   t        j                  d      | _        | j                  j                  s%| j                  t        d      t        d             y	 | j                  j                  |       | j                  j                          | j                  j                  dd      }t         j                  j                  |      | _        | j                  j#                          t         j                  j%                         }| j'                  |t)        |            }|j                  rXt         j                  j+                  | j                  |       t-        j.                  t)        |      t0        j2                         n-t-        j.                  t)        |      t0        j4                         |j6                  r!| j9                  |       | j7                          y# t        $ r}t        |      dk(  r:| j                  t        d      t        d             t        j                  d       nGt        |      d	k(  r9| j                  t        d
      t        d             t        j                  d       Y d}~d}~ww xY w)a  Report an application hanging.

        This will first present a dialog containing the information it can
        collect from the running application (everything but the trace) with
        the option of terminating or restarting the application, optionally
        reporting that this error occurred.

        A SIGABRT will then be sent to the process and a series of
        noninteractive processes will collect the remaining information and
        mark the report for uploading.
        r   zNo PID specifiedz;You need to specify a PID. See --help for more information.Fzinvalid processInvalid PIDz(The specified process ID does not exist.r   znot accessiblezNot your PIDz0The specified process ID does not belong to you.Nrl   r   )	modal_forT)r;   Reportr   rF   r   r   r   add_proc_infor   r+   r   r   r   r   r<   r   r   r|   r   r   r   mark_hanging_processr   r`   signalSIGABRTSIGKILLr   wait_for_pid)r   r   rd   r   r   r   s         r   run_hangzUserInterface.run_hang"  s    mmF+yy}}!!$%OP 	KK%%c* 	$$&{{/4!++==dC!",,>>@112CsSVx1X??11$++sCGGCHfnn-GGCHfnn-c"LLN7  	5z..%%m$a(R&S U//%%n%HI 	s   G 	J(BI==Jc                     	 	 t        j                  t        |       d       t        j                  d       6# t        $ r(}|j                  t        j
                  k(  rY d}~y d}~ww xY w)zwaitpid() does not work for non-child processes. Query the process
        state in a loop, waiting for "no such process."
        r   Nr   )r   r`   r   r>   ra   rb   timesleeprc   s     r   r   zUserInterface.wait_for_pidV  sX    
 C!$
 JJqM   ;;%++-s   8 	A)A$#A$$A)c                 ^    t        j                  t        |       t        j                         y)z!Kill process with signal SIGSEGV.N)r   r`   r   r   SIGSEGV)r   s    r   	kill_segvzUserInterface.kill_segvd  s     	C&..)r1   Nr   r   c                 
   | j                   j                  sN| j                   j                  s8|s6| j                         ry| j	                  t        d      t        d             yt        j                  d      | _        | j                   j                  r	 t        j                  d| j                   j                   t        j                  t        j                  z  t        j                  z        }t        j                  dt        j                  |      }t        j                  |d	
      5 }|j                         j!                         }ddd       t#        d         }|t$        z  rd| j                   _        n1| j                  j'                  | j                   j                  |       n| j                  j5                          | j                   j                  r3| j                   j                  j7                         | j                   _        | j                   j                  dk(  rt9        j:                         | _        n| j                   j                  | _        	 | j?                  |       | jC                         ry| jE                          | jG                         ry	 | j                  d= | j                   jJ                  r	 t        jL                  jO                  | j                   jJ                        }|jQ                  d      r;tS        j                  |d      5 }| j                  jU                  |       ddd       nat        t        jL                  jO                  | j                   jJ                        d      5 }| j                  jU                  |       ddd       yd}	| jW                  |	      }
|
j                  r| jY                          y# 1 sw Y   xY w# t(        $ r' | j	                  t        d      t        d             Y yt*        t,        f$ rQ}t/        |dd      t0        j2                  k(  rY d}~y| j	                  t        d      t        d             Y d}~yd}~ww xY w# t*        $ r}dtA        |      v rwdtA        |      v rj| j<                  s(| j	                  t        d      t        d      |z         n1| j	                  t        d      t        d      | j<                  z         Y d}~y d}~ww xY w# tH        $ r Y hw xY w# 1 sw Y   xY w# 1 sw Y   xY w# t,        $ r.}| j	                  t        d      tA        |             Y d}~yd}~ww xY w)a@  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()).
        TzNo package specifiedzHYou need to specify a package or a PID. See --help for more information.FBugr4   stat)dir_fdrg   rh   N   linux)r   proc_pid_fdzPermission deniedzfThe specified process does not belong to you. Please run this program as the process owner or as root.ra   r   z6The specified process ID does not belong to a program.r   zdoes not existr   z7Symptom script %s did not determine an affected packagezPackage %s does not existProcCmdlinez.gzwbCannot create report)-rF   r   r   run_symptomsr   r   r;   r   r   r   r7   r8   r9   r:   ior~   r   r   
PF_KTHREADr   r   r   r>   getattrra   ENOENTadd_proc_environr.   r   get_kernel_packager   r   r+   r   add_extra_tagsr   r   saver   
expanduserendswithgzipr   r   r   )r   r   r  	stat_filer   r  flagsrd   savefiler   r   s              r   run_report_bugzUserInterface.run_report_bugi  s\    yy  ~  "!!()8 mmE* 99==! ggTYY]]O,bkkBII.E.V GGFBKKL	WWY9 ,Q668>>+D,DG:%(/DII%KK-- IIMM{ . . KK((*99 $		 1 1 7 7 9DII99'(;;=D#yy00D	n-" ""$  "	M* 99>>	M77--diinn=$$U+8T2 -a))!,- - bgg00@$G -1))!,-  !%556GHH  "u, , # %%)*M ( 	5'40ELL@ !%%m$NO 	.  	CJ&+;s5z+I''))23ST() ))23569I9II 	6  		- -- - M%%a(>&?ULL Ms   BO+ 1OA"O+ %Q< )T AT< 'T"AT< 	T/%T< O(#O+ +-Q9Q9(Q4$Q44Q9<	TA?T
	T

T	TT"T,'T< /T94T< <	U3$U..U3c           
      Z   | j                   j                  | j                  j                        s%| j	                  t        d      t        d             y| j                   j                  | j                  j                        }|s| j                  t        d            }|syt        j                  d      | _
        | j                  j                  r&| j                  j                  j                         g}n/| j                   j                  | j                  j                        }d}|D ]Q  }|| _        || j                  d<   || j                  d<   	 t        j                   |       | j1                  d       d}S |s%| j3                  t        d      t        d             y| j                  j5                          | j                  j7                          | j9                          | j                  d= 	 | j                  d= t=        | j                        dk(  r%| j3                  t        d      t        d             yd}| j?                  |      }|j                  r?| j                   jA                  | j                  j                  | j                  d|d       yy# t"        $ ro t$        j&                  j)                  t$        j&                  j+                  t        j                  j,                  d| d	            st/        d
| d       Y Y w xY w# t:        $ r Y #w xY w)z:Update an existing bug with locally collected information.zUpdating problem reportzYou 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".FaH  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  SourcePackagerq   source_.pyzPackage z. not installed and no hook available, ignoringT)r   z$No additional information collected.Dater   zapport information)change_descriptionattachment_comment)!r   
can_updaterF   update_reportr   r   is_reporterui_question_yesnor;   r   r   r   r.   get_affected_packagesr   r   get_versionr   r   r   existsr   PACKAGE_HOOK_DIRprintr   ui_info_messageadd_user_infor  r  r   lenr   update)r   r#  rpkgsinfo_collectedpr   r   s           r   run_update_reportzUserInterface.run_update_report  s    ||&&tyy'>'>?!!+,P ll..tyy/F/FG&&P	A  mmE*99II%%++-.D<<55dii6M6MND 	"A D+,DKK(%&DKK	"%%a( 6!N#	"&   +,a0V.W !!#$$& KK	O, t{{q   +,a0V.W  !112CD??LL		''$#.#7    [  ww~~GGLL!?!?71#SAQR HQC'UVW	.  		s%   J"9L "A1LL	L*)L*c           	      N   t        j                   t        j                  j                  t        d            }g }|D ]  }t        j                  j                  |      j                  d      r2i }	 t        |d      5 }t        t        |j                         |d      |       ddd       d|vr!t        j                  j                  d	|       t        j                  j#                  t        j                  j                  |            d
   }|j%                  |j'                  d|      |f        |sy|j)                          |j%                  d       | j+                  t-        d      |D cg c]  \  }}|	 c}}d      }	|	E||	d
      d   }
|
r7| j/                  t        j                  j                  t        |
dz                yyy# 1 sw Y   .xY w# t        $ r8 t        j                  j                  d|       t        j                           Y w xY wc c}}w )zlReport a bug from a list of available symptoms.

        Return False if no symptoms are available.
        z*.pyr   rg   rh   rj   Nzsymptom script %s is invalidr*   z0symptom script %s does not define run() functionr   descriptionF)zOther problemNz+What kind of problem do you want to report?r   r  T)globr   r   r   symptom_script_dirr   rV   r7   rj   r}   r~   r   r;   r   rd   r   r   r   appendr   sortui_question_choicer   r  )r   scriptssymptomsscriptr   r   symptom_namer4  r!   chsymptoms              r   r
  zUserInterface.run_symptomsG  s   
 ))BGGLL);VDE  	SFww'2237D&73 Bq66:DAB D $$F 77++BGG,<,<V,DEaHLOOTXXm\BLQR'	S* /0$$;<2:;.[$[;
 >r!uoa(G##BGGLL1CWu_$UV  EB B  $$%CVL##%( <s0   1G>&G$G3H!G	G=HHc                 R   t         j                  j                  t        | j                  j
                  dz         }t         j                  j                  |      s<| j                  t        d      t        d      | j                  j
                  z         y| j                  |       y)z#Report a bug with a symptom script.r  zUnknown symptomzThe symptom "%s" is not known.N)
r   r   r   r6  rF   r?  r'  r   r   r  )r   r<  s     r   run_symptomzUserInterface.run_symptomz  sx    0$))2C2Ce2KLww~~f%!!#$23dii6G6GG F#r1   c                    | j                   j                  r| j                          y| j                   j                  r&| j	                  | j                   j
                         y| j                   j                  r| j                         S | j                   j                  | j                         S | j                   j                  rt        t               y| j                   j                  r'	 | j                  | j                   j                         y| j                   j&                  r't)        j*                  d      dk(  r%| j!                  t#        d      t#        d             y| j-                  dt#        d	             t/        j0                  d
dgdt.        j2                  t.        j2                        }|j4                  dk(  rF	 t7        |j8                  j;                         d         | j                   _        | j                         S | j!                  t#        d      t#        d      dz   |j>                  jA                         z          y| jC                         S # t        $ r.}| j!                  t#        d      t%        |             Y d}~yd}~ww xY w# t<        $ r' | j!                  t#        d      t#        d             Y yw xY w)zCall appropriate run_* method according to command line arguments.

        Return True if at least one report has been processed, and False
        otherwise.
        TNr   XDG_SESSION_TYPEwaylandr	  a<  The window option cannot be used on Wayland.

Please find the window's process ID and then run 'ubuntu-bug <process ID>'.

The process ID can be found by running the System Monitor application. In the Processes tab, scroll until you find the correct application. The process ID is the number listed in the ID column.r   z^After closing this message please click on an application window to report a problem about it.xprop_NET_WM_PIDF)r'   r-   stderrr   z2xprop failed to determine process ID of the windowr   )"rF   r?  rA  hangingr   r   filebugr  r"  r2  versionr)  __version__
crash_filer   r>   r   r   r+   windowr   getenvr*  r)   r*   PIPEr,   r   r-   r   r   rG  decoder   )r   rd   rE  s      r   run_argvzUserInterface.run_argv  sZ    9999MM$))--(99&&((99"".))++99+99Otyy334 99yy+,	9%%,-D
   H NN-(!!	E 1$ $'(:(:(<R(@$ADIIM **,,!!()FG,,%%'( !!k  O%%a(@&A3u:NNOJ "  ))01NO   s*   -%I! 	5J !	J*$JJ-K
Kc           	      Z   t        j                  t        d            }|j                  ddt        d             |j                  ddg d	t        d
             |j                  ddt               |j                  | dd       }d|_        d|_        d|_        d|_	        d|_
        |S )z=Parse command line options when being invoked in update mode.z%(prog)s <report number>usage-p	--packagezSpecify package name.help--tagr7  tags@Add an extra tag to the report. Can be specified multiple times.actionr   destrY  r"  report_number)metavartyper   NF)argparseArgumentParserr   add_argumentr   
parse_argsr?  rJ  rM  rK  rI  )r   parserrF   s      r   parse_argv_updatezUserInterface.parse_argv_update  s     ((q1K/LMD+A6M4NOUV 	 	
 	O_3O  ab*r1   c           	      
   t        |      dkD  rdt        j                  v rqt        j                  j	                  t        j                  j                  |d         t        j                  j                  t        j                  d               |d<   |d   }|j                  d      s|j                  d      r| j                  |      S t        |      dkD  r"j                  d      rt        j                  }nd}t        j                  t        d            }|j                  d	d
dd|xs t        d             |j                  dddt        d             |j                  ddt        d|xs t        d             |j                  ddd|xs t        d             |j                  dd|xs t        d              |j                  d!d"t        |xs t        d#      $       |j                  d%dt        d&             |j                  d'd(d)|xs& t        d*      t        j                   j"                  z         |j                  d+d)t        d,             |j                  d-d.g d/t        d0      1       |j                  d2d3dt        d4             |j                  d5d6t        j                  7       |j%                  |d8d       }|j&                  }|`|j(                  r`|j*                  |j,                  |j.                  |j0                  |j2                  |j4                  g}t7        |      r|j9                  d9       t        |      d8k(  rj                  d      r	d:|_        |S ||S t        j                  j;                  t        j                  j	                  t<        |d;z               rd:|_        ||_        |S |j                  d<      s|j                  d=      r	||_        |S |j?                         rd:|_        ||_        |S d>|v r|jA                  d?      rt        j                   jC                  |jE                  d>      d@         }|s|j9                  | dA       nM|jG                  dBdC      r!|j9                  | dD|dE    dF|dB    dG       n|j9                  | dD|dE    dH       tI        jJ                  d8       n@tM        jN                  |      }	|	s)|j9                  | dI       tI        jJ                  d8       d:|_        	|_(        |S d:|_        d:| _)        ||_(        |S )JzParse command line options.

        If a single argument is given without any options, this tries to "do
        what I mean".
        r   APPORT_INVOKED_ASz-update-bugz-collectz-bugNzI%(prog)s [options] [symptom|pid|package|program path|.apport/.crash file]rT  z-fz
--file-bug
store_truerJ  zStart 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.))r^  r_  rY  z-wz--windowz7Click a window as a target for filing a problem report.)r^  rY  r%   z--update-bugr"  z;Start in bug updating mode. Can take an optional --package.)rb  r_  rY  z-sz	--symptomSYMPTOMzWFile a bug report about a symptom. (Implied if symptom name is given as only argument.))ra  rY  rV  rW  zSpecify package name in --file-bug mode. This is optional if a --pid is specified. (Implied if package name is given as only argument.)rX  z-Pz--pidzSpecify 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.))rb  rY  z	--hangingz*The provided pid is a hanging application.-cz--crash-filePATHzReport the crash from given .apport or .crash file instead of the pending ones in %s. (Implied if file is given as only argument.)z--savezIn 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.rZ  r7  r[  r\  r]  z-vz	--versionz Print the Apport version number.issue?)nargsrY  r   zL-u/--update-bug option cannot be used together with options for a new reportTr  z.crashz.apport/z	/snap/binrH  zv is provided by a snap. No contact address has been provided; visit the forum at https://forum.snapcraft.io/ for help.contactr   z$ is provided by a snap published by 	developerz. Contact them via z
 for help.z`. No contact address has been provided; visit the forum at https://forum.snapcraft.io/ for help.z does not belong to a package.)*r,  r   r   r   r   dirnamer   r  rh  rc  SUPPRESSrd  r   re  r   r;   r<   
report_dirrf  ro  r"  rJ  rN  r?  r   rM  r  anyrd   r'  r6  isdigitrV   r   r   r   r   r   r   get_file_packager   r   )
r   r   cmdsuppressrg  rF   ro  args_only_for_new_reportsr   pkgs
             r   r   zUserInterface.parse_argv  s{    t9q="bjj0'',,GGOODG,GG$$RZZ0C%DEQ q'C||M*cll:.F--d33t9q=S\\&1((HH((J
 	 O 	 	
 	LM	 	 	
 	  PNO 	 	
 	 / 	 		
 	 /	 	 		
 	 @ 	 
	
 	?@ 	 	

 	 *@
 ))* 	 	
 	? 	 	
 	UV 	 	
 	56	 	 	
 	G3X5F5FG  ab*

J 		)% ,-5 t9>cll62DLK =K 77>>"'',,'955=IJDL DLd _ ^^H%	)B#DO\ W ]]_DLDHR M E\,''11%++c2B22FGLL ' "A B
 XXi,LL ' " -. /  $Y0
< LL ' " -. /DE 007LLE7*H!IJHHQKDLDL 	  DL#'D  DLr1   c                     | dk  rt        j                  d| dz        S | dk  rt        j                  d| dz        S t        j                  d| t        d      z        S )zKFormat the given integer as humanly readable and i18n'ed file
        size.i@B z%.1f KBg     @@i ʚ;z%.1f MBg    .Az%.1f GB)localeformat_stringfloat)sizes    r   format_filesizezUserInterface.format_filesize  s_     '>''	4&=AA*''	4)3CDD##IteJ6G/GHHr1   c                     | j                   sJ d}| j                   D ]3  }| j                   |   s	 || j                   |   j                         z  }5 |S # t        $ r |t        | j                   |         z  }Y ^w xY w)z'Return the size of the complete report.r   r   get_on_disk_sizer   r,  r   r  r\   s      r   get_complete_sizezUserInterface.get_complete_size  s    {{{ 	0A{{1~0DKKN;;==D	0  & 0CA//D0s    A$A<;A<c                 
   | j                   sJ d}| j                   D ]9  }|dk7  s	| j                   |   s	 || j                   |   j                         z  }; |S # t        $ r |t        | j                   |         z  }Y dw xY w)z&Return the size of the reduced report.r   r   r  r  s      r   get_reduced_sizezUserInterface.get_reduced_size  s    {{{ 	4AJ;;q>4A ? ? AA		4  * 4DKKN 334s    A$BBc                     | j                   rd| j                   vryt        j                  d      y| j                         S )zCheck 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_has_terminal()).
        r   Fzapport-retrace)r   shutilwhichui_has_terminalr   s    r   can_examine_locallyz!UserInterface.can_examine_locally  s;     {{j;<<()1##%%r1   c           
      <   | j                   rd| j                   v sJ t        j                         dk(  rit        j                          t        j                  ddd| j                   j                  d| j                   d                t        j                  d       yy)zReopen the crashed application.r  r   shrm  RespawnCommandr   N)r   r   forksetsidexeclpr   r   r   r  s    r   r   zUserInterface.restart  ss    {{};;;779>IIKII 0$++m2LM	 HHQK r1   c                    | j                   sJ | j                  t        d      t        d      t        d      t        d      | j                   z  gd      }|yt        j                  j                  d      }d| d	}d
}d| j                   j                  dd      z   dz   }|dz   |z   |dz   |z   |dz   |z   dz   |z   d}| j                  ||d             y)zLocally examine crash report.zJThis will launch apport-retrace in a terminal window to examine the crash.zRun gdb sessionz1Run gdb session without downloading debug symbolsz)Update %s with fully symbolic stack traceFNz~/.cache/apport/retracezapport-retrace -S system -C z -v zapport-retrace 'z'\''z--gdb z	--output  )r   r      r   )r   r9  r   r   r   r  replaceui_run_terminal)r   r   	cache_dirretrace_with_downloadretrace_no_downloadfileargcmdss          r   r   zUserInterface.examine  s
   **)
 #$EF=>AQAQQ	 
 GG&&'@A	">yk N/((00g>>D %x/'9"X-7${2W<sBWL
 	T(1+./r1   send_reportc                 T   	 t        j                  ddddddddd	t        |      j                         g
       t        j                  g d
       y# t        t         j
                  f$ r>}t        d      }| j                  t        d      | dt        |              Y d}~yd}~ww xY w)z#Put whoopsie in auto or never mode./usr/bin/gdbuscall-y-dcom.ubuntu.WhoopsiePreferences-o/com/ubuntu/WhoopsiePreferences-mz/com.ubuntu.WhoopsiePreferences.SetReportCrashes)
r  r  r  r  r  r  r  r  z<com.ubuntu.WhoopsiePreferences.SetAutomaticallyReportCrashestruezLSaving crash reporting state failed. Can't set auto or never reporting mode.z*Can't remember send report status settingsr   N)r)   check_outputr+   lowerr>   CalledProcessErrorr   r   )r   r  rd   msgs       r   r   z"UserInterface.remember_send_report(  s    %	##$45E$**, ## 667 	;C !!>?%tCJ<( 	s   AA B')4B""B'c                    | j                   d| j                   vry| j                   d   j                         j                  d      rc	 t        j                  | j                   d         }t        |t              sJ d|v sJ 	 	 t        j                  j                  d|      | _        y	 t        j                  j                  d| j                   d         | _        y# t        t        t        f$ r,}d| j                   d    d| | j                   d<   Y d}~y	d}~ww xY w# t        t        f$ r# d
| j                   d    d| j                   d<   Y yw xY w# t        t        f$ r# d
| j                   d    d| j                   d<   Y y	w xY w)z+Process reports' CrashDB field, if present.Nro   T{r   z=A package hook defines an invalid crash database definition:

rn   Fz@A package hook wants to send this report to the crash database "z" which does not exist.)r   lstriprV   astliteral_evalry   dictAssertionErrorSyntaxErrorr   r;   r   load_crashdbr   r   r   )r   specrd   s      r   check_report_crashdbz"UserInterface.check_report_crashdbQ  s   ;;)4;;"> ;;y!((*55c:	''I(>?!$---~%~%~~::4F( %~~99$I@VW 7 #K< %%)[[%;$<BugG 01   * ""&++i"8!9 :-. 01$ '  * ""&++i"8!9 :-. 01
 s<   	:C %D" ,2E D3"DD"/EE/F	F	c           
      .   | j                   sJ d| j                   d<   | j                   j                  d      dk(  rd| j                   v s,| j                   j                  d      dk7  rd| j                   v r
|r |        y| j                   j                  d      dk(  r| j                   j                  dd	      }t        j                  j	                  |      s;t        d
      }|r| d| j                   d    d}|| j                   d<   |r |        yd| j                   v rct        j                  j	                  | j                   d         s7t        d
      }| d| j                   d    d| j                   d<   |r |        yd| j                   v rd| j                   v rt        | j                   d         }| j                   d= t        t        j                  | j                   d         j                        }||k7  r8d| j                   d<   t        d      | j                   d   z  | j                   d<   y| j                  s,d| j                   vr|s| j                   j                          n| j                          | j                  j                  | j                         rt        |       }n
t               }d| j                   vrt        j                   j#                         }	t$        j&                  j'                  t(        d| j                   | j*                  | j                  |||f      }
|
j-                          |
j/                         r2| j1                          	 |j3                          |
j/                         r2|
j;                          t        j                   j=                          t        j                   j?                  |	       	 |
jA                          d| j                   v r-d| j                   v rd| j                   d   v rdg}nP| jU                  t        d      t        d      | j                   d   z  t        d       | j                   d   z  gd!      }|dgk(  rD| j                   d= d"| j                   v r| j                   d"= d#| j                   v r}| j                   d#= no|dgk(  rD| j                   d= d$| j                   v r| j                   d$= d%| j                   v r3| j                   d%= n%| jW                          t7        j8                  d       d| j                   v rQd%| j                   v rC| j                   jY                  | j                   j[                  d%      j]                  d&             d| j                   v rd$| j                   vrd'| j                   vrd| j                   vr| j^                  rt$        j`                  jc                  | j                        }|j                  d(d	      r(t        d)      |d*   |d+   |d(   fz  | j                   d<   n#t        d,      |d*   |d+   fz  | j                   d<   d| j                   d<   d| j                   v s| je                         s| jW                          |r |        y| j                   j                  d      d-k(  s,| j                   j                  d      d.k(  sd| j                   v rt$        j&                  j'                  | j                   jf                  | j                  ji                         f/      }|j-                          |j/                         r3| j1                          	 |j;                  d0       |j/                         r3	 |jA                          |jk                         r|jk                         | j                   d1<   | j                   j                  d      d2k7  rt$        j&                  j'                  | j                  jl                  | j                   f/      }|j-                          |j/                         r3| j1                          	 |j;                  d0       |j/                         r3|jA                          |jk                         }|#|d3u rd4| j                   d1<   n|| j                   d1<   t$        j&                  j'                  | j                   jn                  5      }|j-                          |j/                         r3| j1                          	 |j;                  d0       |j/                         r3|jA                          | jW                          d| j                   vrd#| j                   vrd| j                   vs9| j                   j                  dd	      jq                  d6      sgd| j                   vrY| js                         sI| ju                  t        d7      t        d8             | jw                          t7        j8                  d       |r |        yy# t4        $ r t7        j8                  d       Y w xY w# tB        tD        tF        jH                  f$ rB}t        d      }| dtK        |       | j                   d<   d| j                   d<   Y d}~d}~wtL        $ r9 d| j                   vr't        d      | j                   d<   d| j                   d<   Y tN        $ rj}t$        jP                  jI                  dtK        |             t        d      dz   tS        |      z   | j                   d<   d| j                   d<   Y d}~jd}~ww xY w# t4        $ r t7        j8                  d       Y w xY w# tB        tD        tF        jH                  f$ r3}t        d      }| dtK        |       | j                   d<   Y d}~;d}~ww xY w# t4        $ r t7        j8                  d       Y w xY w# t4        $ r t7        j8                  d       Y w xY w)9aH  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()).
        Truer   rt   ru   r   DependenciesNrl   r   zIThis problem report applies to a program which is not installed any more.z ()rn   InterpreterPathExecutableTimestampr   zPThe problem happened with the program %s which changed since the crash occurred.r   )targetr!   rF   r   7This problem report is damaged and cannot be processed.r   z5This report is about a package that is not installed.z%szBAn error occurred while attempting to process this problem report:rm   rq   z(not installed)r   zcYou have two versions of this application installed, which one do you want to report a bug against?z%s snapz%s deb packageFPackageArchitecturer  
SnapSourceSnapTagsr  SnapGitNamers  zG%s is provided by a snap published by %s. Contact them via %s for help.r!   rt  z%s is provided by a snap published by %s. No contact address has been provided; visit the forum at https://forum.snapcraft.io/ for help.KernelCrash
KernelOopsr  rF   皙?_KnownReportr  T1)r  Kernelr   z7Could not determine the package or source package name.)<r   r   r   r   r'  r   r   r  st_mtimer   r|   !ui_start_info_collection_progressr   r   rz   NoninteractiveHookUIr   copyr;   REThreadr   r   startis_alive!ui_pulse_info_collection_progressprocess_eventKeyboardInterruptr   r   r   clearr-  	exc_raiser>   EOFErrorzlibrd   reprr   r   r   r+   r9   ui_stop_info_collection_progressadd_tagspopr   r   r<   r   r  search_bug_patternsget_bugpattern_baseurlreturn_valueknown	anonymizerV   _is_snapr   ui_shutdown)r   r   r   on_finishedexe_pathr  	orig_timecur_timehookuiorig_envicthreadrd   resr   bpthreadknown_threadvalanonymize_threads                     r   r   zUserInterface.collect_infoy  sa
     {{{(.$% KKOOM*g5,$++:UKKOOM*g5.DKK:W ;;??=)W4{{'7<H77>>(+8  EDKK0@$A#B!DC4701M DKK/ww~~dkk2C&DE<C
 %r$++.?"@!AC KK 45 ## t{{*/D/SDKK(=>?I122774;;/?#@AJJKHH$07,-C kk"23	4 01     3" KK##% 224 ||##DKK0-/4;;.::??,!??33..((((&* 4   '')::<$,,. '')  

  "

!!(+<&&(2 $dkk)A$I(>> #C11. iL4;;v+>>./$++i2HH C 1#:I.,; KK(=>&$++5 KK8QCZF+#t{{2 KK5!T[[0 KK
399;HHQK $t{{)B$$T[[__Z%@%F%Fs%KL $++% 3T[[8X(;((''11$2B2BC88Ir*8999 ftK'8$y/J9KDKK 45
 9:D9 ftK'89	9:DKK 45
 18,-#t{{2$:S:S:U557M .-?;;??=1\A+!??33;;::,,==?A 4   '')::<$ c* '')R&&(
 ((*2:2G2G2IDKK/ {{}-6%77<<--T[[N  8   ""$"++-::<$$))#. #++- &&("//1?d{69N369N3  &77t{{?T?T7U""$"++-668 $))#. #++- &&(113 $4;;6 (t{{:*$++= !KKOOM2>II(S%T[[8--/))23ST $$&HHQKM s - $$  4::6 <UVC;>%tDK=8QDKK 454;DKK 01! @+4;;><=S=$89 9@$45  
<NN((tE{;; !	!
 e*% KK 45 5<DKK 01
<B - $$  4::6 RUVC;>%tDK=8QDKK 45R" - $$$ )  HHQK s   #h i  m :m9 o o2 h=<h= m7jAmm'Ammm65m69o
(oo
o/.o/2ppc                 Z    | j                   sJ d| j                   v xs d| j                   v S )Nr  rm   )r   r  s    r   r  zUserInterface._is_snap  s+    {{{t{{*Cf.CCr1   c                    	 	 t        d|gd       y# t        $ r t        j                  |dd      rY yd}Y nw xY wn# t        $ r}d| }Y d}~nd}~ww xY wt        d	      }t        d
      |z  }| j                  |||z          y)zjOpen the given URL in a new browser window.

        Display an error dialog if everything fails.
        zxdg-openTrD   Nr   )new	autoraiser   r  zUnable to start web browserz'Unable to start web browser to open %s.)r^   r>   
webbrowserr7   r   r   r   )r   urlerror_detailsrd   r   messages         r   open_urlzUserInterface.open_url  s    

	)# *c!2F #??3A> "	#  	) LM	) /0=>DeW}%<=s-    !;? ;? ;? 	AAAc           	           j                   sJ  j                  j                   j                         sy j                   j                  d       j                   j                  d      k(  r	  j                   d= 	  j                   d= d _         fd}t        j                         fd}t         j                         D ]!  }|j                  d      s j                   |= #  j                          t        j                  j                   j                  j                   j                   ||f      }|j                          	 |j                         rv j!                   j
                         	 j                  d	d
      \  }}} j#                  ||       |j%                          |j'                          |j                         rv|j'                          |jA                         }
 jC                           j                  jE                   j                   |
      }|r jG                  |       yy# t        $ r Y w xY w# t        $ r Y w xY w# t        j(                  $ r Y w xY w# t*        $ r t-        j.                  d       Y t0        j2                  t4        j6                  j8                  f$ r>}t;        d      }	 j=                  t;        d      |	 dt?        |              Y d}~yd}~ww xY w)zOUpload the current report and guide the user to the reporting
        web page.Nr  ArchitectureStacktraceAddressSignaturec                 ,    t        |       |z  _        y N)r  r   )senttotalr   s     r   progress_callbackz4UserInterface.file_report.<locals>.progress_callback  s    #(;#6D r1   c                 v    t        j                         }j                  | ||f       |j                          y r  )	threadingEventputwait)r   r(   message_displayedmessage_queues      r   message_callbackz3UserInterface.file_report.<locals>.message_callback  s2     ) 1ud,=>?""$r1   r   r  Tr  )blocktimeoutr   zHCannot connect to crash database, please check your Internet connection.zNetwork problemr   )$r   r   r   r   r   r   queueSimpleQueuelistrV   ui_start_upload_progressr;   r  uploadr  r  ui_set_upload_progressr*  setr  Emptyr  r   r   smtplibSMTPConnectErrorurllibrd   URLErrorr   r   r+   r  ui_stop_upload_progressget_comment_urlr  )r   r  r  r\   upthreadr   r(   msg_displayedrd   r  ticketr  r  s   `           @r   r   zUserInterface.file_report  s    {{{ ||##DKK0;;??01T[[__^5TTKK 56	89  $	7 ))+	% dkk" 	#A||C KKN	# 	%%'??++<<&&++02BC , 
 		##%++D,@,@A1>1B1B"C 2C 2.E4 ((5!%%'&&( ##%   &&($$&ll**4;;?MM# {    		H {{  ! 	HHQK((&,,*?*?@ 	:C !!!$5"63%tCJ<8PQ	sm   /H< =I +I5 7A	I  I5 I5 <	I	I		III2/I5 1I22I5 5K?,K?4K::K?c           	         	 t        j                         | _        t        |d      5 }| j                  j	                  |d       ddd       d| j                  vrt        d      	 d| j                  v r&| j                  d   j!                         d   | _        yt         j$                  j'                  | j                  j)                  dd            | _        y# 1 sw Y   xY w# t        $ r. d| _        | j                  t        d      t        d             Y y	t        $ r6}d| _        | j                  t        d
      |j                         Y d}~y	d}~wt        t
        t        t        j                  f$ rE}d| _        t        d      }| j                  t        d
      | dt        |              Y d}~y	d}~ww xY w)zLoad 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.
        rb
compressed)binaryNrt   z+Report does not contain "ProblemType" fieldzMemory exhaustionzEYour system does not have enough memory to process this crash report.Fr   r  r   rq   r   rl   r   T)r;   r   r   r7   loadr   MemoryErrorr   r   r>   r   	TypeErrorr  r  rd   r  r   r   r<   r   r   )r   r   r   rd   r  s        r   r   zUserInterface.load_report  s   	 --/DKdD! 9Q  < 89DKK/ !NOO 00 ##{{95;;=a@D 	  &//AA 0"5 D C9 9  		DK!!%&5  	DK!!!$<"=u~~N:~tzzB 	DKMNC!!*+uDe-F 	s@   %C& C!C& C#C& &4G G $,E&G ;;F;;G c                    | j                   sJ | j                  j                  | j                         syd| j                   v rt        | j                   d   t              r+| j                   d   j                  d      | j                   d<   d| j                   v r-t        d      | j                   d   j                         d   z  }nd}| j                  |t        d      | j                   d   z         y	y)
znCheck if the current report is unreportable.

        If so, display an info message and return True.
        Frn   UTF-8rq   r   r   r   z#The problem cannot be reported:

%sT)	r   r   r   ry   bytesrQ  r   r   r*  )r   r   s     r   r   z UserInterface.check_unreportable:  s    
 {{{||##DKK04;;.$++&:;UC48KK(5&/ 01 DKK'/*T[[-C-I-I-KA-NN  9:++234
 r1   c           	         | j                   sJ d| j                   v r<t        j                  j                  | j                   d         r| j                   d   }n*	 t        j
                  j                  | j                        }|syt        j                  dd      }	 |j                  |d       |j#                  d
      syt%        |j'                  d
            }d|vry|S # t        $ r Y yw xY w# t        j                  $ r9}t        j                  j                  d| dt!        |       d	       Y d}~yd}~ww xY w)zReturn a .desktop info dictionary for the current report.

        Return None if report cannot be associated to a .desktop file.
        DesktopFileNF)interpolationstrictr*  rh   z	Warning! z is broken: r  zDesktop Entryr!   )r   r   r   r'  r;   r<   find_package_desktopfiler   r   configparserConfigParserr~   r   r   rG  r   r+   has_sectionr  rU   )r   desktop_filecprd   r   s        r   get_desktop_entryzUserInterface.get_desktop_entryS  s   
 {{{DKK'BGGNN4;;};U,V;;}5L%//HH$$  &&T%H	GGL7G3 ~~o.bhh/0#   !! 	JJyl3u:,bQR	s*   )C$ C3 $	C0/C03D?/D::D?c                    | j                   sJ | j                  j                  | j                         syd| j                   vry| j                   d   j                  d      rC| j	                  t        d      t        d             | j                  | j                   d          y| j	                  t        d      t        d             y)zCheck if current report matches a bug pattern.

        If so, tell the user about it, open the existing bug in a browser, and
        return True.
        Fr  httpzProblem already knownzThis 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.z;This problem was already reported to developers. Thank you!T)r   r   r   rV   r*  r   r  r  s    r   r   zUserInterface.handle_duplicates  s     {{{||##DKK0, ;;~&11&9  )*A MM$++n56    )*OP
 r1   c                     | j                   sJ | j                  j                  r0| j                   j                  | j                  j                         yy)z6Add extra tags to report specified with --tags on CLI.N)r   rF   r[  r  r  s    r   r  zUserInterface.add_extra_tags  s8    {{{99>>KK  0 r1   r   r   c                     t        d      )a	  Show details of the bug report.

        Return the action and options as an Action object:

        - Valid attributes are: report the crash ('report'), restart
          the crashed application ('restart'), or ignore further crashes
          ('ignore').
        .this function must be overridden by subclassesNotImplementedError)r   r   r   s      r   r   z'UserInterface.ui_present_report_details  s     ""RSSr1   c                     t        d      )z:Show an information message box with given title and text.r;  r<  r   r   r(   s      r   r*  zUserInterface.ui_info_message      !"RSSr1   c                     t        d      )z4Show an error message box with given title and text.r;  r<  r?  s      r   r   zUserInterface.ui_error_message  r@  r1   c                     t        d      )zOpen a indefinite progress bar for data collection.

        This tells the user to wait while debug information is being
        collected.
        r;  r<  r  s    r   r  z/UserInterface.ui_start_info_collection_progress       ""RSSr1   c                     t        d      )zaAdvance the data collection progress bar.

        This function is called every 100 ms.
        r;  r<  r  s    r   r  z/UserInterface.ui_pulse_info_collection_progress      
 ""RSSr1   c                     t        d      )z,Close debug data collection progress window.r;  r<  r  s    r   r  z.UserInterface.ui_stop_info_collection_progress  r@  r1   c                     t        d      )z{Open progress bar for data upload.

        This tells the user to wait while debug information is being uploaded.
        r;  r<  r  s    r   r  z&UserInterface.ui_start_upload_progress  rE  r1   progressc                     t        d      )zUpdate 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.
        r;  r<  )r   rH  s     r   r  z$UserInterface.ui_set_upload_progress  s     ""RSSr1   c                     t        d      )z(Close debug data upload progress window.r;  r<  r  s    r   r  z%UserInterface.ui_stop_upload_progress  r@  r1   c                      y)zdCalled right before terminating the program.

        This can be used for for cleaning up.
        Nr   r  s    r   r  zUserInterface.ui_shutdown  s    r1   c                     t        d      )zpCheck for a terminal window.

        Check if a terminal application is available and can be launched.
        r;  r<  r  s    r   r  zUserInterface.ui_has_terminal  rE  r1   c                     t        d      )zRun command in a terminal window.

        Run given command in a terminal window; raise an
        exception if terminal cannot be opened.
        r;  r<  )r   commands     r   r  zUserInterface.ui_run_terminal  rC  r1   c                     t        d      )Show a yes/no question.

        Return True if the user selected "Yes", False if selected "No" or
        "None" on cancel/dialog closing.
        r;  r<  r   r(   s     r   r$  zUserInterface.ui_question_yesno  rC  r1   c                     t        d      )m  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;  r<  r   r(   optionsmultiples       r   r9  z UserInterface.ui_question_choice  s     ""RSSr1   c                     t        d      )mShow a file selector dialog.

        Return path if the user selected a file, or None if cancelled.
        r;  r<  rQ  s     r   ui_question_filezUserInterface.ui_question_file
  rE  r1   r  )NFN)TN)<r   r   r   r   r  r+   r   r   r   staticmethodr   r   r   r   r   r  r2  r
  rA  rR  r   rc  	Namespacerh  r   r  r  r  r  r   r   r   r  r   r  r  r   r   r   r6  r   r  r   r   r   r*  r   r  r  r  r  r  r  r  r  r  r  r$  r9  rY  r   r1   r   r   r   P  s   *T#Y *>"Hxt - -2h   * *}S4Z }4 }~]4 ]~1f
$M"f  (2D2D  *UtCy UX-?-? Un I I&0B' ' 'R&R JNkZ	D>*M^*X2@ D1 GKT!%T9<tT	TTTTTTTTut| T TTTTT
TTr1   r   c                   <    e Zd ZdZd Zd Zd Zd
dZd Zd Z	d Z
y	)rz   ag  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                     || _         t        j                         | _        t        j                         | _        d| _        d| _        d| _        y)zSCreate a HookUI object.

        ui is the UserInterface instance to wrap.
        N)r   r  r	  _request_event_response_event_request_fn_request_args	_response)r   r   s     r   r   zHookUI.__init__  sB    
  (oo/(0!r1   c                 (    | j                  dd|      S )zShow 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   _trigger_ui_requestrQ  s     r   informationzHookUI.information-  s     ''(92tDDr1   c                 &    | j                  d|      S )rP  r$  rd  rQ  s     r   yesnozHookUI.yesno5  s     ''(;TBBr1   c                 *    | j                  d|||      S )rS  r9  rd  rT  s       r   choicezHookUI.choice=  s     ''(<dGXVVr1   c                 &    | j                  d|      S )rX  rY  rd  rQ  s     r   filezHookUI.fileI  s    
 ''(:DAAr1   c                 z   | j                   j                         rJ | j                  j                         rJ | j                  J d| _        || _        || _        | j                   j                          | j                  j                          d| _        | j                  j                          | j                  S )z5Called by HookUi functions in info collection thread.N)	r^  is_setr_  r`  rb  ra  r  r  r  )r   fnrF   s      r   re  zHookUI._trigger_ui_requestT  s     &&--///''..000'''!!!!#""$~~r1   c                 t   | j                   j                  d       | j                   j                         sy| j                  j                         rJ | j                   j	                           t        | j                  | j                        | j                   | _	        | j                  j                          y)z;Called by GUI thread to check and process hook UI requests.r  N)r^  r  rn  r_  r  r  r   r`  ra  rb  r  r  s    r   r  zHookUI.process_eventf  s     	  %""))+''..000!!#;$*:*:;T=O=OP  "r1   NF)r   r   r   r   r   rf  rh  rj  rl  re  r  r   r1   r   rz   rz     s.    $EC
WB$
#r1   rz   c                   N     e Zd ZdZ fdZdefdZd Zd Zd
dZ	d Z
d	 Z xZS )r  z8HookUI variant that does not ask the user any questions.c                 $    t         |   d        y r  )superr   )r   	__class__s    r   r   zNoninteractiveHookUI.__init__v  s    r1   r   c                 4    | j                   j                   dS )Nz())ru  r   r  s    r   __repr__zNoninteractiveHookUI.__repr__y  s    ..))*"--r1   c                      y r  r   rQ  s     r   rf  z NoninteractiveHookUI.information|      r1   c                      y r  r   rQ  s     r   rh  zNoninteractiveHookUI.yesno  ry  r1   c                      y r  r   rT  s       r   rj  zNoninteractiveHookUI.choice  ry  r1   c                      y r  r   rQ  s     r   rl  zNoninteractiveHookUI.file  ry  r1   c                 .    t        j                  d       y )Nr  )r   r   r  s    r   r  z"NoninteractiveHookUI.process_event  s    

3r1   rq  )r   r   r   r   r   r+   rw  rf  rh  rj  rl  r  __classcell__)ru  s   @r   r  r  s  s0    B.# .r1   r  r  )NF)Ar   rc  r  r1  dataclassesra   r   r5  r  r  r  os.pathr   rR   r  r   r  r   r  r)   r   r  r   r   urllib.errorr  r  r  collections.abcr   r   typingr   apport.crashdbr;   apport.fileutilsapport.loggingapport.REThreadapport.packaging_implr   r   apport.user_groupr   rL  r   r   r6  r  r   r+   r   r    r0   r  rC   r  r   r^   re   r   	dataclassr   r   rz   r  r   r1   r   <module>r     s~  &  
       	   
  	     
       $        3 8 ZZ^^$9;WX 
	c 	C$J 	#* 		's 	' 	't 	'C DcN : .3&
s)&&*&>A&	&R NSN$b   T TD6^# ^#B6 r1   