HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/apport/__pycache__/ui.cpython-38.pyc
U

��8d�&�@shdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZejjdkr�ddlmZedZnddl mZdZd	Z!d
d�Z"ej#�$dd
�Z%dZ&dd�Z'ddd�Z(dd�Z)dd�Z*ddd�Z+Gdd�d�Z,Gdd�d�Z-dS)z�Abstract Apport user interface.

This encapsulates the workflow and common code for any user interface
implementation (like GTK, Qt, or CLI).
�N)�unicode_gettext)�get_process_user_and_group�)�ConfigParserFTz2.20.11cCs(tjjdkr t|��t��d�St|�S)z$Return exception message as unicode.r�replace)�sys�version_info�major�str�decode�locale�getpreferredencoding)Z	exception�r�+/usr/lib/python3/dist-packages/apport/ui.py�excstr(srZAPPORT_SYMPTOMS_DIRz/usr/share/apport/symptomsi c	CsDz$t�d|�dd���d�}t|�WSttfk
r>YdSXdS)Nz
Pid:	(.*)
Z
ProcStatus��)�re�search�get�group�int�
IndexError�AttributeError)�report�pidrrr�get_pid5s

rc	Cs2zttj|�WSttfk
r,|YSXdS)z�Get 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.
    N)r�os�environ�KeyError�
ValueError)�key�defaultrrr�_get_env_int=sr#cKsltdtd��}|dks t���s:tj|fddi|��dSdddd	t|�g}tj||fddi|��dS)
z�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.
    �SUDO_UID�
PKEXEC_UIDNZcheckF�sudo�-H�-u�#)r#rZis_root�
subprocess�runr
)�args�kwargs�uid�sudo_prefixrrr�run_as_real_userIsr0c
CsRzt�t|�d�Wn8tk
rL}z|jtjkr<WY�dSW5d}~XYnXdS)NrFT)r�killr�OSError�errno�ESRCH)r�errr�
still_runningXsr6c
Cs`z|��Wntk
r YnX|��|r�i}znt|��}tt|��|d�|�W5QRX|d||�}|s�t�d|�WdSt	j
�t	j
�|��d|d<WnNt
k
r�t�d�Yn2tk
r�t�d|�t��t�d�YnX|�sd|k�rtj�|d�}ntd	��tj�|�}|�r6|�|�z|�|�WnVtk
�rl|�shd
|k�rh�Yn0tk
�r�}	zt|	�|d<W5d}	~	XYnXd|k�rr|�|��r�t�d�z�d|k�rFd
t	jk�rFd|k�r�d
|k�r�td�|d<nPtj� |d�!�d��sFtj�"|d�!�d��sFtd�|d�!�d|d<Wn(tk
�rp|�sld
|k�rl�YnXd|k�r�|�#�}
|
�r�|
|d<|�$d�dk�r�dt	jk�r�|�%�}|�r�td�d�&|�|d<|�r\z4t|d�� }t	�'|d�|j(|dd�W5QRXWn6t)k
�rB}	zt�d||	f�W5d}	~	XYnXtj�*|�t	�'|d�dS)ayCollect 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()).
    �execr+z8symptom script %s did not determine the affected packageNrZSymptomzsymptom script %s crashed:�ExecutablePathzAcalled without a package, and report does not have ExecutablePath�Snap�UnreportableReason�CrashDBZAPPORT_DISABLE_DISTRO_CHECK�Packagez4This package does not seem to be installed correctlyzXThis is not an official %s package. Please remove any third party package and try again.Z
DistroReleaseZTitle�ProblemType�CrashZAPPORT_IGNORE_OBSOLETE_PACKAGESz�You have some obsolete package versions installed. Please upgrade the following packages and check if the problem still occurs:

%sz, ZabT)Zonly_newzCannot update %s: %si�)+Zadd_gdb_infor2�add_os_info�openr7�compile�read�apport�errorr�path�splitext�basename�
StopIterationr�exit�	Exception�	traceback�	print_exc�	fileutils�find_file_packager�	find_snapZ
add_snap_info�add_package_infor �SystemErrorrZadd_hooks_infor�_�	packagingZis_distro_package�splitZis_native_origin_packageZstandard_titlerZobsolete_packages�join�chmod�write�IOError�mark_report_seen)rZ
reportfile�package�ui�symptom_script�ignore_uninstalled�symb�f�snapr5�titleZold_pkgsrrr�thread_collect_infoas�

  



���
�$rbc@s�eZdZdZdd�Zdd�Zd_dd�Zd	d
�Zdd�Zd
d�Z	dd�Z
d`dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zdad1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dbdAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dMdN�Z(dOdP�Z)dQdR�Z*dSdT�Z+dUdV�Z,dWdX�Z-dYdZ�Z.d[d\�Z/d]d^�Z0dS)c�
UserInterfaceaApport 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
Cs�d|_d|_d|_d|_d|_d|_ztj�d�|_WnNt	k
rh}zt�
dt|��W5d}~XYntk
r�t�
d�YnXt
�|j�|��dS)z8Initialize program state and parse command line options.rCNFzDCould not import module, is a package upgrade in progress? Error: %sz8/etc/apport/crashdb.conf is damaged: No default database)Zgettext_domainr�report_file�cur_package�
offer_restart�specified_a_pkgrC�crashdb�get_crashdb�ImportError�fatalr
r�gettext�
textdomain�
parse_argv)�selfr5rrr�__init__�s zUserInterface.__init__cCsd}d|_t��dkr&tj��}d}nPtj��}tsFtj�	t�
��}n0t�dt�
�tjtj
BtjB�}tjj	|d�}|D]�}|�|�s�qz|r�d|jkr�d|jkr�|j��s�qz|d|jdksz|d	|j��kr�qz|jd
dkr�|�|�n
|�|�d}qz|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.
        FTrN�/proc/%s)�proc_pid_fdZ_LogindSession�Daterr=�Hang)rfr�geteuidrCrMZget_new_system_reportsZget_new_reports�PY3�ReportZget_logind_session�getpidr@�O_RDONLY�O_PATH�O_DIRECTORY�load_reportrZ
get_timestamp�finish_hang�	run_crash)ro�resultZreportsZlogind_sessionrrr_rrr�run_crashes�s6


"
�
�
zUserInterface.run_crashesTc
Cs�||_�z�ztj�|�Wntk
r.YnX|jsF|�|�sFWdSd|jkrVWdS|j�d�dkr�d|jkr�d|jkr�d|jkr�tj	�
|j�dtd	���}td
�|}|�td�|d|td
�f�WdStj�
�}|�|�}|ds�|d�r
d|jk�r
|��|jdk�rWdS|d�r4|��WdS|d�rF|��|d�rZ|j��z|d�rt|�|d�Wntk
�r�YnX|d�s�WdSd|jk�r�|jddk�r�tj�|�|j�|j��r�|���r�WdS|���r�WdS|��Wn�tk
�r�}z�|jtjtjfk�rH|�td�td��t� d�nJ|jtj!k�rv|�td�td��t� d�n|�td�|j"�t� d�W5d}~XYn@tk
�r�}z |jtj#k�r�t�$d�n�W5d}~XYnXdS)z�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.
        N�Ignorer=r>ZSignal�CoreDump�
Stacktracer8zunknown programz+Sorry, the program "%s" closed unexpectedly�
Problem in %s�%s

%szxYour computer does not have enough free memory to automatically analyze the problem and send a report to the developers.r�examine�Dependencies�restartZ	blacklistZremember�_MarkForUpload�False�Invalid problem reportz2You are not allowed to access this problem report.r�Errorz@There is not enough disk space available to process this report.zOut of memory, aborting)%rdrCrMrYr2rr|rrrErGrR�ui_error_message�allowed_to_report�ui_present_report_details�collect_infor�r�Zmark_ignore�remember_send_reportr�mark_report_uploadrh�accepts�handle_duplicate�check_unreportable�file_reportrXr3ZEPERM�EACCESrrIZENOSPC�strerrorZENOMEMrk)rordZconfirmZsubjectZheadingr��responser5rrrr~.s�	
.
�







�


�
�zUserInterface.run_crashcCstj�|�tj�|�dS)z�Finish 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)rCrMr�rY)ror_rrrr}�szUserInterface.finish_hangc
Cs^t�d�|_|jjs,|�td�td��dSz|j�|�Wnxtk
r�}zZt	|�dkrz|�td�td��t
�d�n*t	|�d	kr�|�td
�td��t
�d�W5d}~XYnX|j��|j�
d
d�}tj�|�|_|j��tj��}|j||d�}|d�r,tj�|j|�t�t|�tj�nt�t|�tj�|d�rZ|�|�|��dS)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.
        rtzNo PID specifiedz;You need to specify a PID. See --help for more information.Fzinvalid process�Invalid PIDz(The specified process ID does not exist.rznot accessiblezNot your PIDz0The specified process ID does not belong to you.Nr8r)�	modal_forrr�)rCrwr�optionsrr�rR�
add_proc_infor r
rrIrPrrMrNrer?r�r�Zmark_hanging_processrr1r�signal�SIGABRT�SIGKILL�wait_for_pidr�)rorr5rEr�r�rrr�run_hang�sD
�
�
�


�


zUserInterface.run_hangc
Cs`zt�t|�d�Wn:tk
rN}z|jtjkr<WY�
q\n�W5d}~XYnXt�d�qdS)z�waitpid() does not work for non-child processes. Query the process
        state in a loop, waiting for "no such process."
        rNr)rr1rr2r3r4�time�sleep)rorr5rrrr��s
zUserInterface.wait_for_pidcCst�t|�tj�dS�N)rr1rr��SIGSEGV)rorrrr�	kill_segv�szUserInterface.kill_segvNc
Cs�|jjs8|jjs8|s8|��r dS|�td�td��dSt�d�|_|jj�r�z�d}t	r�t
�d|jjt
jt
j
Bt
jB�}t
jdt
j|d	�}nd
|jj}t�|��}|����}W5QRXt|d�}|t@r�d|j_n|jj|jj|d
�Wn�tttfk
�r�}znt|d��rZ|jtjk�r.WY�NdS|jtjk�rZ|�td�td��WY�"dS|�td�td��WY�dSd}~XYnXn
|j��|jj�r�|jj��|j_|jjdk�r�tj��|_ n
|jj|_ z|�!|�Wn�tk
�rh}zhdt"|�k�rVdt"|�k�rV|j �s2|�td�td�|�n|�td�td�|j �WY�
dS�W5d}~XYnX|�#��rxdS|�$�|�%��r�dSz|jd=Wnt&k
�r�YnX|jj'�rpztt
j(�)|jj'�}|�*d��rt+�|d��}|j�,|�W5QRXn.tt
j(�)|jj'�d��}|j�,|�W5QRXWn<ttfk
�rl}z|�td�t-|��W5d}~XYnXn d}	|�.|	�}
|
d�r�|�/�dS)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()).
        TzNo package specifiedzHYou need to specify a package or a PID. See --help for more information.F�BugNrq�stat)�dir_fdz
/proc/%s/stat�Zlinux)rrrr3zPermission deniedzfThe specified process does not belong to you. Please run this program as the process owner or as root.r�z6The specified process ID does not belong to a program.rZzdoes not existr�z7Symptom script %s did not determine an affected packagezPackage %s does not exist�ProcCmdlinez.gz�wb�Cannot create reportr)0r�rZr�run_symptomsr�rRrCrwrrvrr@ryrzr{�iorBrTr�
PF_KTHREADr�r rXr2�hasattrr3ZENOENTr��add_proc_environ�striprSZget_kernel_packagerer�r
r��add_extra_tagsr�r�saverE�
expanduser�endswith�gziprWrr�r�)ror\rrZ	stat_filer_r��flagsr5Zsavefiler�r�rrr�run_report_bug�s�
�
�
"


�

�




�
�



(

zUserInterface.run_report_bugcCs�|j�|jj�s(|�td�td��dS|j�|jj�}|sR|�td��}|sRdSt�	d�|_
|jjrv|jj��g}n|j�
|jj�}d}|D]�}||_||j
d<||j
d<ztj�|�WnBtk
r�tj�tj�tj
jd|��s�td	|�Yq�YnX|jd
d�d
}q�|�s0|�td�td��dS|j
��|j
��|��|j
d
=z|j
d=Wntk
�rvYnXt|j
�dk�r�|�td�td��dSd
}|�|�}|d�r�|jj |jj|j
d|dd�d
SdS)z:Update an existing bug with locally collected information.zUpdating problem reportz�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".FaHYou 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��
SourcePackager<zsource_%s.pyz8Package %s not installed and no hook available, ignoringT)r]z$No additional information collected.rsrrzapport information)Zchange_descriptionZattachment_comment)!rhZ
can_updater��
update_reportr�rR�is_reporter�ui_question_yesnorCrwrrZr�Zget_affected_packagesrerSZget_versionr rrE�existsrUZ	_hook_dir�printr��ui_info_message�
add_user_infor�r�r�lenr��update)ror��rZpkgsZinfo_collected�pr�r�rrr�run_update_reportKsr
��



�


�

�zUserInterface.run_update_reportc	
Csvt�tj�td��}g}g}|D]�}tj�|��d�r8q i}z.t|��}tt	|�
�|d�|�W5QRXWn,tk
r�t�
d|�t��Yq YnXd|kr�t�
d|�q |�tj�tj�|��d�|�|�d|d	��q |s�d
Sttt||���\}}t|�}t|�}|�d�|�d�|�td
�|d
�}|dk	�rr||d}|�rn|�tj�t|d��nd
SdS)zlReport a bug from a list of available symptoms.

        Return False if no symptoms are available.
        z*.pyrRr7zsymptom script %s is invalidr+z0symptom script %s does not define run() functionrZdescription���FNz
Other problemz+What kind of problem do you want to report?�.pyT)�globrrErU�symptom_script_dirrG�
startswithr@r7rArBrJrCrDrKrL�appendrFr�zip�sorted�list�ui_question_choicerRr�)	roZscriptsZ
symptom_namesZsymptom_descriptions�scriptr^r_Zch�symptomrrrr��sJ
$
�


�
zUserInterface.run_symptomscCsPtj�t|jjd�}tj�|�sB|�td�td�|jj�dS|�	|�dS)z#Report a bug with a symptom script.r�zUnknown symptomzThe symptom "%s" is not known.N)
rrErUr�r�r�r�r�rRr�)ror�rrr�run_symptom�s
�zUserInterface.run_symptomc
Cs�|jjr|��dS|jjr.|�|jj�dS|jjr>|��S|jjdk	rR|�	�S|jj
rftt�dS|jj
r�z|�|jj
d�Wn6tk
r�}z|�td�t|��W5d}~XYnXdS|jj�r�t�d�dk�r�|�td�td��dS|�d	td
��tjddgtjtjd
�}|��\}}|jdk�r~zt|��d�|j_Wn,tk
�rt|�td�td��YdSX|��S|�td�td�d|�dSn|��SdS)z�Call appopriate run_* method according to command line arguments.

        Return True if at least one report has been processed, and False
        otherwise.
        TNFr�ZXDG_SESSION_TYPEZwaylandr�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.rz^After closing this message please click on an application window to report a problem about it.�xpropZ_NET_WM_PID��stdout�stderrrr�z2xprop failed to determine process ID of the window�

) r�r�r��hangingr�r�filebugr�r�r��versionr��__version__�
crash_filer~r2r�rRr�windowr�getenvr�r*�Popen�PIPEZcommunicate�
returncoderrTr r�)ror5r��out�errrrr�run_argv�sZ&

�

�
�
�zUserInterface.run_argvcCs�t�td��}|jddtd�d�|jddgtd�d	�|��\|_|_t|j�d
ksd|jd��sx|�	d�t
�d
�t|jd�|j_
d
|j_d|j_d
|j_d
|j_d|j_g|_d
S)zgParse command line options when being invoked in update mode.

        Return (options, args).
        z%prog <report number>�-p�	--packagezSpecify package name.��help�--tagr��@Add an extra tag to the report. Can be specified multiple times.��actionr"r�rrz-You need to specify a report number to updateNF)�optparse�OptionParserrR�
add_option�
parse_argsr�r,r��isdigitrDrrIrr�r�r�r�r�r�)ro�	optparserrrr�parse_argv_updates$�
�

zUserInterface.parse_argv_updatecCs:ttj�dkrrdtjkrHtj�tj�tjd�tj�tjd��tjd<tjd}|�	d�sf|�	d�rr|�
�dSt�t
d��}|jddd	d
dt
d�d
�|jddd	dt
d�d�|jddddt
d�d�|jdddt
d�d�|jddt
d�d �|jd!d"dt
d#�d$�|jd%d	dt
d&�d�|jd'd(d)t
d*�tjjd�|jd+d)t
d,�d�|jd-d.gt
d/�d�|jd0d1d	t
d2�d3�ttj�dk�r�|�	d4��r�d5D]}tj|�|�_�q�|��\|_|_|jj�r|jj�s
|jj�s
|jj�s
|jj�s
|jj�s
|jj�r|�d6�ttj�dk�r(dSttj�d7k�rP|�	d4��rPd8|j_dSt|j�d7k�rddStj� tj�t!|jdd9���r�d8|j_|jd|j_g|_�n�|jd�	d:��s�|jd�	d;��r�|jd|j_g|_�nT|jd�"��rd8|j_|jd|j_g|_�n$d<|jdk�r|jd�#d=��r�tj�$|jd�%d<�d>�}|�sl|�d?|jd�nN|�&d@dA��r�|�dB|jd|dC|d@f�n|�dD|jd|dCf�t�'d7�n6tj(�)|jd�}|�s�|�dE|jd�t�'d7�g|_d8|j_||j_*n"d8|j_d8|_+|jd|j_*g|_dS)Fz�Parse command line options.

        If a single argument is given without any options, this tries to "do
        what I mean".
        rZAPPORT_INVOKED_ASz-update-bugz-collectNzF%prog [options] [symptom|pid|package|program path|.apport/.crash file]�-fz
--file-bug�
store_truer�Fz�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.))r��destr"r�z-wz--windowz7Click a window as a target for filing a problem report.r�r(z--update-bugrr�z;Start in bug updating mode. Can take an optional --package.)�typer�r��-sz	--symptomZSYMPTOMzWFile a bug report about a symptom. (Implied if symptom name is given as only argument.))�metavarr�r�r�z�Specify package name in --file-bug mode. This is optional if a --pid is specified. (Implied if package name is given as only argument.)r��-Pz--pidz�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.))r�r�z	--hangingz*The provided pid is a hanging application.�-cz--crash-file�PATHz�Report the crash from given .apport or .crash file instead of the pending ones in %s. (Implied if file is given as only argument.)z--savez�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.r�r�r�z-vz	--versionz Print the Apport version number.)r�r�z-bug)r�r(r�r�r�r�zL-u/--update-bug option cannot be used together with options for a new reportrTr�z.crashz.apport�/z	/snap/binr�zx%s is provided by a snap. No contact address has been provided; visit the forum at https://forum.snapcraft.io/ for help.�contactr�G%s is provided by a snap published by %s. Contact them via %s for help.�	developer��%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.z %s does not belong to a package.),r�r�argvrrrErU�dirnamerGr�r�r�r�rRr�rCrMZ
report_dirZ
SUPPRESS_HELPZ
get_optionr�r�r�r,r�r�r�r�rr�r�rDr�r�r�r�rOrTrrIrSZget_file_packagerZrg)ro�cmdr��or`�pkgrrrrn0s�
�


���
��
�
�
��
�
�
���
"
$

$

zUserInterface.parse_argvcCsP|dkrt�d|d�dS|dkr8t�d|d�dSt�d|td��dS)	zCFormat the given integer as humanly readable and i18n'ed file size.i@Bz%.1fg@�@z KBiʚ;g��.Az MBz GB)r�format�float)ro�sizerrr�format_filesize�s
zUserInterface.format_filesizec	Csfd}|jD]V}|j|r
z |t|j|j�dd7}Wq
tk
r^|t|j|�7}Yq
Xq
|S)z'Return the size of the complete report.rr���rr�Z	gzipvaluer�ror�krrr�get_complete_size�s

 zUserInterface.get_complete_sizec	Csnd}|jD]^}|dkr
|j|r
z |t|j|j�dd7}Wq
tk
rf|t|j|�7}Yq
Xq
|S)z&Return the size of the reduced report.rr�r�rrrrrr�get_reduced_size�s

 zUserInterface.get_reduced_sizecCsz|jrd|jkrdSz&tjddgtjtjd�dkr8WdSWntk
rPYdSXz|�d�WStk
rtYdSXdS)z�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()).
        r�FZwhichzapport-retracer�rN)rr*�callr�ZSTDOUTr2�ui_run_terminal�NotImplementedError�rorrr�can_examine_locally�s 
��
z!UserInterface.can_examine_locallyc
CsPd|jkst�t��dkrLt��t�ddd|j�d|jd��t�d�dS)zReopen the crashed application.r�rZshr�ZRespawnCommandrN)	r�AssertionErrorr�fork�setsid�execlprrrIrrrrr��s
 zUserInterface.restartcCs�|�td�td�td�td�|jgd�}|dkr6dSdtj�d�}d	}d
|j�d
d�d
}|d||d||d
|d|d�}|�||d�dS)zLocally examine crash report.zJThis will launch apport-retrace in a terminal window to examine the crash.zRun gdb sessionz1Run gdb session without downloading debug symbolsz)Update %s with fully symbolic stack traceFNz"apport-retrace -S system -C %s -v z~/.cache/apport/retracezapport-retrace �'z'\''z--gdb z	--output � )rrrr)r�rRrdrrEr�rr)ror�Zretrace_with_downloadZretrace_no_downloadZfileargZcmdsrrrr��s(��	�

�zUserInterface.examinecCs�|r
d}nd}z@t�ddddddd	d
d|g
�t�ddddddd	d
ddg
�WnHttjfk
r�}z$|�td
�dtd�t|�f�W5d}~XYnXdS)z"Put whoopsie in auto or never mode�trueZfalsez/usr/bin/gdbusrz-yz-dzcom.ubuntu.WhoopsiePreferencesz-oz/com/ubuntu/WhoopsiePreferencesz-mz/com.ubuntu.WhoopsiePreferences.SetReportCrashesz<com.ubuntu.WhoopsiePreferences.SetAutomaticallyReportCrashesz*Can't remember send report status settingsr�zLSaving crash reporting state failed. Can't set auto or never reporting mode.N)r*�check_outputr2�CalledProcessErrorr�rRr)roZsend_reportr5rrrr�s6
�
�
�z"UserInterface.remember_send_reportc
Cs&d|jkrdS|jd���d�r�z.t�|jd�}t|t�sBt�d|ksNt�Wn@tk
r�}z"d|jd|f|jd<WY�dSd}~XYnXzt	j
�d|�|_
Wn,tt
fk
r�d	|jd|jd<YnXnLzt	j
�d|jd�|_
Wn0tt
fk
�r d	|jd|jd<YdSXdS)
z*Process reports' CrashDB field, if presentr;T�{�implzBA package hook defines an invalid crash database definition:
%s
%sr:FNzYA package hook wants to send this report to the crash database "%s" which does not exist.)r�lstripr��astZliteral_eval�
isinstance�dictrrJrCrhZload_crashdbrjrri)ro�specr5rrr�check_report_crashdbs(
z"UserInterface.check_report_crashdbFc
Csd|jd<|j�d�dkr$d|jks>|j�d�dkrLd|jkrL|rH|�dS|j�d�dkr�|j�dd	�}tj�|�s�td
�}|r�d||jdf}||jd<|r�|�dSd
|jkr�tj�|jd
�s�td
�}d||jd
f|jd<|r�|�dSd|jk�rjd|jk�rjt|jd�}|jd=tt�|jd�j�}||k�rjd|jd<td�|jd|jd<dS|j	�s�d|jk�r�|�s�|j�
��nn|��|j�
|j��r�t|�}nd}d|jk�rLtj��}	tjjtd|j|j|j	|||fd�}
|
��|
���rD|��|�r�z|��Wn tk
�r>t�d�YnX�q�|
��tj��tj�|	�z|
��Wn�t t!t"j#fk
�r�}z(dtd�t$|�f|jd<d|jd<W5d}~XYn�t%k
�r�d|jk�r�td�|jd<d|jd<YnVt&k
�rJ}z6t�#t$|��td�dt'|�|jd<d|jd<W5d}~XYnXd|jk�r@d|jk�r@d|jdk�r|dg}n2|�(td�td�|jdtd�|jdgd �}|dgk�r�|jd=d!|jk�r�|jd!=d"|jk�r@|jd"=nT|dgk�r*|jd=d#|jk�r|jd#=d$|jk�r@|jd$=n|�)�t�d�dSd|jk�r�d$|jk�r�|j�d%d	�}
|
�rt|
d&7}
|
|jd$|jd%<|jd$=d|jk�r&d#|jk�r&d|jk�r&|j*�r&tj+�,|j	�}|�d'd	��r�td(�|d)|d*|d'f|jd<ntd+�|d)|d*f|jd<d|jd<d|jk�s<|�-��sT|�)�|�rP|�dS|j�d�d,k�s�|j�d�d-k�s�d|jk�rZtjj|jj.|j�/�fd.�}|��|���r�|��z|�d/�Wn tk
�r�t�d�YnX�q�z|��WnFt t!t"j#fk
�r@}zdtd�t$|�f|jd<W5d}~XYnX|�0��rZ|�0�|jd0<|j�d�d1k�rtjj|jj1|jfd.�}|��|���r�|��z|�d/�Wn tk
�r�t�d�YnX�q�|��|�0�}|dk	�r|d2k�rd3|jd0<n
||jd0<tjj|jj2d4�}|��|���rl|��z|�d/�Wn tk
�rft�d�YnX�q&|��|�)�d|jk�rd"|jk�r�d|jk�s�|j�dd	��3d5��sd|jk�rd#|jk�rd|jk�r|�4td6�td7��|�5�t�d�|�r|�dS)8aHCollect 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�r=r>r�r�Nr8rzIThis problem report applies to a program which is not installed any more.z%s (%s)r:ZInterpreterPath�ExecutableTimestampr�zPThe problem happened with the program %s which changed since the crash occurred.rb)�target�namer,rr��7This problem report is damaged and cannot be processed.z5This report is about a package that is not installed.zBAn error occurred while attempting to process this problem report:r�r9r<z(not installed)rzcYou have two versions of this application installed, which one do you want to report a bug against?z%s snapz%s deb packageF�PackageArchitecturer�Z
SnapSourceZSnapTags�Tagsrrrr-rrZKernelCrashZ
KernelOops�r,r,皙�����?�_KnownReportr�T�1)r,ZKernelr�z7Could not determine the package or source package name.)6rrrrEr�rRrr��st_mtimerer?�!ui_start_info_collection_progressrhr��HookUIr�copyrC�REThreadrbrd�start�is_alive�!ui_pulse_info_collection_progress�
process_event�KeyboardInterruptrrIrU�clearr��	exc_raiserX�EOFError�zlibrD�reprr rJr
r�� ui_stop_info_collection_progressrgrMrOr)Zsearch_bug_patternsZget_bugpattern_baseurl�return_valueZknownZ	anonymizer�r��ui_shutdown)ror\r]Zon_finishedZexe_path�msgZ	orig_timeZcur_timeZhookuiZorig_envZicthreadr5�resZcurrent_tagsr`ZbpthreadZknown_thread�valZanonymize_threadrrrr�8sv
4



���

��

���

��


,&
0
�
�
�




����
�
zUserInterface.collect_infoc
CsHt��\}}t��dkr�t�|�t��\}}|rptd�}td|�}t�|���}|rd|d|7}|�||�zt�|�Wnt	k
r�YnXdSt�
�t�|�z�tt�dt�d���}	dd	d
dt
|	�g}
z�t�dd
dd
t
|	�dg��d�}|��d��d}td|d��}|���d�}
W5QRX|
D]6}|�d��r8|
�d|�dd�d����qp�q8Wntjtfk
�r�YnXWntk
�r�g}
YnXzLzt�|
d|g�Wn0t	k
�r�tj|ddd�t�d�YnXWn>tk
�r8}zt�|t
|��t�d�W5d}~XYnXt� d�dS)zjOpen the given URL in a new browser window.

        Display an error dialog if everything fails.
        rzUnable to start web browserz'Unable to start web browser to open %s.�
Nr%r$r&r'r(r)Zpgrepz-az-xZgvfsd�UTF-8z/proc/%s/environ�rb�sDBUS_SESSION_BUS_ADDRESS=zDBUS_SESSION_BUS_ADDRESS=�=rzxdg-openT)�newZ	autoraise)!r�piper�close�waitrR�fdopen�readliner�r2rrr�r
r*r r�
splitlinesrTr@rBr�r�r!rX�	TypeErrorr�
webbrowserrrIrJrW�_exit)ro�urlr��wrZstatusrarD�messager.r/r�r_�envr5rrr�open_url s`

��

zUserInterface.open_urlc
Cs6|j�|j�sdS|j�d�|j�d�krLz|jd=Wntk
rJYnXz|jd=Wntk
rlYnXdadd�}t|j�D]}|�d�r�|j|=q�|��t	j
j
|jj|j|fd�}|��|�
��r�|�t�z|�d	�|��Wq�tk
�rt�d
�Yq�t	jjk
�r�}z`td�}|�|t|��}|dk	�r�|\}}|j�||�t	j
j
|jj|j|fd�}|��W5d}~XYq�tttfk
�r��Yq�tk
�r�}z*|�td�d
td�t|�f�WY�dSd}~XYq�Xq�|��|��}	|��|j� |j|	�}
|
�r2|�!|
�dS)zGUpload the current report and guide the user to the reporting web page.Nr/ZArchitectureZStacktraceAddressSignaturecSst|�|adSr�)r�_UserInterface__upload_progress)ZsentZtotalrrr�progress_callbackzsz4UserInterface.file_report.<locals>.progress_callbackrRr1r2rzDPlease enter your account information for the %s bug tracking systemzNetwork problemr�zHCannot connect to crash database, please check your Internet connection.)"rhr�rrrr^r�r��ui_start_upload_progressrCr9Zuploadr:r;�ui_set_upload_progressrUr@r>rrIZNeedsCredentialsrR�ui_question_userpassrZset_credentialsrV�SyntaxErrorr rJr�rE�ui_stop_upload_progressZget_comment_urlr])ror_rZupthreadr5r[�data�userZpasswordZticketrYrrrr�`sl

�



�
��zUserInterface.file_reportcCsLzFt��|_t|d��}|jj|dd�W5QRXd|jkrDtd��Wn�tk
rvd|_|�td�td��Yd	St	k
r�}z"d|_|�td
�|j
�WY�d	Sd}~XYnZtttt
jfk
�r}z0d|_|�td
�dtd�t|�f�WY�d	Sd}~XYnXd
|jk�r0|jd
��d|_ntj�|j�dd��|_dS)z�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.
        rLZ
compressed)�binaryr=z+Report does not contain "ProblemType" fieldNzMemory exhaustionzEYour system does not have enough memory to process this crash report.Fr�r�r.r<rr8rT)rCrwrr@�loadr �MemoryErrorr�rRrXr�rVrrBrDrCrTrerMrNr)rorEr_r5rrrr|�s:


�
��zUserInterface.load_reportcCs�|j�|j�sdSd|jkr�t|jd�tkrD|jd�d�|jd<d|jkrjtd�|jd��d}nd}|�|td�|jd�d	SdS)
znCheck if the current report is unreportable.

        If so, display an info message and return True.
        Fr:rKr<r�rrz#The problem cannot be reported:

%sT)	rhr�rr��bytesrrRrTr�)rorarrrr��s

�z UserInterface.check_unreportablec
Cs$d|jkr(tj�|jd�r(|jd}n*ztj�|j�}Wntk
rPYdSX|sZdSt	rtt
ddd�}ddi}n
t
�}i}z|j|f|�Wnbtk
r�}zDdt
|j�kr�dt
|j�kr�tj�d	|t
|�f�WY�
dS�W5d}~XYnX|�d
��sdSt|�d
��}d|k�r dS|S)z�Return a .desktop info dictionary for the current report.

        Return None if report cannot be associated to a .desktop file.
        ZDesktopFileNF)�
interpolation�strict�encodingrKZonfigZarserzWarning! %s is broken: %s
z
Desktop Entryr-)rrrEr�rCrMZfind_package_desktopfilerer rvrrBrJr
�	__class__rr�rWZhas_sectionr'�items)roZdesktop_file�cpr-r5rrrr�get_desktop_entry�s4


zUserInterface.get_desktop_entrycCsn|j�|j�sdSd|jkr dS|jd�d�rV|�td�td��|�|jd�n|�td�td��dS)z�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.
        Fr3ZhttpzProblem already knownz�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.z;This problem was already reported to developers. Thank you!T)rhr�rr�r�rRr]rrrrr�s

�
�zUserInterface.handle_duplicatecCsH|js
t�|jjrD|j�dd�}|r,|d7}|d�|jj�|jd<dS)z6Add extra tags to report specified with --tags on CLI.r0rrN)rrr��tagrrU)roZtagsrrrr� s
zUserInterface.add_extra_tagscCstd��dS)aShow 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').
        �.this function must be overridden by subclassesN�r)ror�r�rrrr�.s	z'UserInterface.ui_present_report_detailscCstd��dS)z:Show an information message box with given title and text.rsNrt�rora�textrrrr�9szUserInterface.ui_info_messagecCstd��dS)z4Show an error message box with given title and text.rsNrtrurrrr�>szUserInterface.ui_error_messagecCstd��dS)z�Open a indefinite progress bar for data collection.

        This tells the user to wait while debug information is being
        collected.
        rsNrtrrrrr6Csz/UserInterface.ui_start_info_collection_progresscCstd��dS)zaAdvance the data collection progress bar.

        This function is called every 100 ms.
        rsNrtrrrrr<Ksz/UserInterface.ui_pulse_info_collection_progresscCstd��dS)z,Close debug data collection progress window.rsNrtrrrrrDRsz.UserInterface.ui_stop_info_collection_progresscCstd��dS)z{Open progress bar for data upload.

        This tells the user to wait while debug information is being uploaded.
        rsNrtrrrrr`Wsz&UserInterface.ui_start_upload_progresscCstd��dS)z�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.
        rsNrt)roZprogressrrrra^sz$UserInterface.ui_set_upload_progresscCstd��dS)z(Close debug data upload progress window.rsNrtrrrrrdhsz%UserInterface.ui_stop_upload_progresscCsdS)zdCalled right before terminating the program.

        This can be used for for cleaning up.
        NrrrrrrFmszUserInterface.ui_shutdowncCstd��dS)aRun 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.
        rsNrt)roZcommandrrrrts	zUserInterface.ui_run_terminalcCstd��dS)��Show a yes/no question.

        Return True if the user selected "Yes", False if selected "No" or
        "None" on cancel/dialog closing.
        rsNrt�rorvrrrr��szUserInterface.ui_question_yesnocCstd��dS)�mShow 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.
        rsNrt�rorvr�Zmultiplerrrr��s
z UserInterface.ui_question_choicecCstd��dS)�mShow a file selector dialog.

        Return path if the user selected a file, or None if cancelled.
        rsNrtrxrrr�ui_question_file�szUserInterface.ui_question_filecCstd��dS)z�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.
        rsNrt)ror[rrrrb�sz"UserInterface.ui_question_userpass)T)N)NFN)TN)1�__name__�
__module__�__qualname__�__doc__rpr�r~r}r�r�r�r�r�r�r�r�r�rnr
rrrr�r�r�r)r�r]r�r|r�rqr�r�r�r�r�r6r<rDr`rardrFrr�r�r|rbrrrrrc�sb6
f	/
nR1?r	
�
i@I%%

rcc@sJeZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dS)r7agInteractive 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.
    cCs0||_t��|_t��|_d|_d|_d|_dS)zSCreate a HookUI object.

        ui is the UserInterface instance to wrap.
        N)r[�	threadingZEvent�_request_event�_response_event�_request_fn�
_request_args�	_response)ror[rrrrp�s

zHookUI.__init__cCs|�dd|�S)z�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��_trigger_ui_requestrxrrr�information�szHookUI.informationcCs|�d|�S)rwr�r�rxrrr�yesno�szHookUI.yesnoFcCs|�d|||�S)ryr�r�rzrrr�choice�s
z
HookUI.choicecCs|�d|�S)r{r|r�rxrrr�file�szHookUI.filecGsf|j��rt�|j��rt�|jdks*t�d|_||_||_|j��|j��d|_|j�	�|jS)z5Called by HookUi functions in info collection thread.N)
r��is_setrr�r�r�r��setrRr?)ro�fnr,rrrr��s


zHookUI._trigger_ui_requestcCsV|j�d�|j��sdS|j��r(t�|j��t|j|j�|j	�|_
|j��dS)z;Called by GUI thread to check and process hook UI requests.r2N)r�rRr�r�rr?�getattrr[r�r�r�r�rrrrr=�s

zHookUI.process_eventN)F)r}r~rr�rpr�r�r�r�r�r=rrrrr7�s
r7)N)NF).r�r�r�os.pathrr�rKrrlrr�r3rBr�r*r�rWr�r�r%rC�apport.fileutilsZapport.REThreadZapport.crashdbrrRZapport.user_grouprrr	rrv�configparserr�rrrr�r�rr#r0r6rbrcr7rrrr�<module>sTH�
	�
v^