File: //proc/self/root/lib/python3/dist-packages/apport/__pycache__/fileutils.cpython-38.pyc
U
$�/h�G � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
mZ z&ddlm
Z
mZmZmZ e
eef W n, ek
r� ddl
m
Z
mZmZmZ Y nX ddlmZ ddlmZ ej�dd�Zd Zd
ZdZdd
� Zdd� Zdd� Zdd� Z dd� Z!dd� Z"dd� Z#dd� Z$dd� Z%dd� Z&d d!� Z'd"d#� Z(d$d%� Z)d&d'� Z*d(d)� Z+d*d+� Z,dGd,d-�Z-d.d/� Z.dHd1d2�Z/de/_0d3d4� Z1d5d6� Z2d7d8� Z3d9d:� Z4dId;d<�Z5dJd=d>�Z6d?d@� Z7dAdB� Z8dCdD� Z9dEdF� Z:dS )Kz0Functions to manage apport problem report files.� N)�
itemgetter)�ConfigParser�
NoOptionError�NoSectionError�MissingSectionHeaderError)�
ProblemReport)�impl�APPORT_REPORT_DIRz
/var/crashz/var/lib/apport/coredump� z~/.config/apport/settingsc C sF t �dt j�sdS zt�ddddg�dkW S tk
r@ Y dS X d S )
z)Check whether crash reporting is enabled.z/usr/bin/whoopsieTz/bin/systemctlz-qz
is-enabledzwhoopsie.servicer FN)�os�access�X_OK�
subprocess�call�OSError� r r �2/usr/lib/python3/dist-packages/apport/fileutils.py�allowed_to_report$ s r c C s\ | sdS | � d�sdS d| kr"dS dD ]}|| kr& dS q&| �d�}t|�dkrTdS |d S )z'Extract the socket from a DBus address.Nzunix:path=/run/user/z../)�%�,�;�=� � )�
startswith�split�len)Z dbus_addr�search�partsr r r �get_dbus_socket0 s
r c
C st | dkrdS d}t �| �D ]T}|�d�r|�d�s>|�d�s>q|rH dS t|d��}d|�� krd|}W 5 Q R X q|S )z�Return a package's .desktop file.
If given package is installed and has a single .desktop file, return the
path to it, otherwise return None.
Nz.desktopz/etc/xdg/autostartz/usr/share/applications/�rbs NoDisplay=true)� packagingZ get_files�endswithr �open�read)�packageZdesktopfile�line�fr r r �find_package_desktopfileK s
r( c C sR ddddddddd g }d
}|D ]}| � |�rd} q6q|oP| � d� oP| � d
� S )a2 Check whether the given file is likely to belong to a package.
This is semi-decidable: A return value of False is definitive, a True value
is only a guess which needs to be checked with find_file_package().
However, this function is very fast and does not access the package
database.
z/bin/z/bootz/etc/z/initrdz/libz/sbin/z/optz/usr/z/varFTz/usr/local/z /var/lib/)r )�fileZ
pkg_whitelistZwhitelist_match�ir r r �likely_packagedg s �
�r+ c C sL t j�| �\}}t j�|�}t j�|�r6t j�||�} t| �sBdS t�| �S )z[Return the package that ships the given file.
Return None if no package ships it.
N) r �pathr �realpath�isdir�joinr+ r! Zget_file_package)r) �dir�nameZresolved_dirr r r �find_file_package{ s r2 c C sT t �� }z0|�d�| ��}|jdkr6|�� }|d W S W n tk
rN Y dS X dS )zbReturn the data of the given snap.
Return None if the snap is not found to be installed.
z-http+unix://%2Frun%2Fsnapd.socket/v2/snaps/{}�� �resultN)�requests_unixsocketZSession�get�formatZstatus_codeZjson� Exception)ZsnapZsession�r�jr r r � find_snap� s
r; c C s t �| �}|j|jkp|jdkS )zACheck whether the report file has already been processed earlier.r )r �stat�st_atime�st_mtime�st_size)�report�str r r �seen_report� s
rB c C s� d| � dd�d }d| � dd�d }tj�|�rjtj�|�rjt�| �}t�|�}|j|jk rjt�|� t|d�� W 5 Q R X d S )Nz %s.upload�.r r z%s.uploaded�a)�rsplitr r, �existsr<