File: //lib/python3/dist-packages/apport/__pycache__/fileutils.cpython-312.pyc
�
j�8d�K � �H � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddl
mZ ddlmZ ddlmZmZmZmZ eeef ddlmZ ddlmZ ej8 j; dd � Zd
ZdZ dZ!d
Z" G d� dejF jH e%� Z&d� Z'd� Z(d� Z)d� Z*d� Z+d� Z,d� Z-d� Z.d� Z/d� Z0d� Z1d� Z2d� Z3d� Z4d� Z5d� Z6d0d �Z7d!� Z8d1d"�Z9de9_: d#� Z;d$� Z<d%� Z=d&� Z>d'e?d(e@eAeAf fd)�ZBd0d*�ZCd2d+�ZDd,� ZEd-� ZFd.� ZGd/� ZHy# e$ r ddlmZmZmZmZ Y ��w xY w)3z0Functions to manage apport problem report files.� N)�closing)�
itemgetter)�ConfigParser�
NoOptionError�NoSectionError�MissingSectionHeaderError)�
ProblemReport)�impl�APPORT_REPORT_DIRz
/var/crashz/var/lib/apport/coredump� z~/.config/apport/settingsz/run/snapd.socketc � � e Zd Zd� Zd� Zy)�UHTTPConnectionc �f � t j j j | d� || _ y )N� localhost)�http�client�HTTPConnection�__init__�path)�selfr s �2/usr/lib/python3/dist-packages/apport/fileutils.pyr zUHTTPConnection.__init__, s# � ����"�"�+�+�D�+�>��� � c � � t j t j t j � }|j | j � || _ y �N)�socket�AF_UNIX�SOCK_STREAM�connectr �sock)r r s r r zUHTTPConnection.connect0 s3 � ��}�}�V�^�^�V�-?�-?�@�����T�Y�Y���� r N)�__name__�
__module__�__qualname__r r � r r r r * s � ��r r c � � t j dt j � sy t j g d�� dk( S # t
$ r Y yw xY w)z)Check whether crash reporting is enabled.z/usr/bin/whoopsieT)z/bin/systemctlz-qz
is-enabledz
whoopsie.pathr F)�os�access�X_OK�
subprocess�call�OSErrorr# r r �allowed_to_reportr+ 6 sG � � �9�9�(�"�'�'�2������V�W�[\�\�\��� ���s �A � A
�A
c � � | sy| j d� syd| v rydD ] }|| v s� y | j d� }t |� dk7 ry|d S )z'Extract the socket from a DBus address.Nzunix:path=/run/user/z../)�%�,�;�=� � )�
startswith�split�len)� dbus_addr�search�partss r �get_dbus_socketr9 B si � � �� ��� 6�7��
� ��� "���Y��� "�
�O�O�C� �E�
�5�z�Q�����8�Or c � � | �yd}t j | � D ]d }|j d� s�|j d� s|j d� s�8|r yt |d� 5 }d|j � vr|}ddd� �f |S # 1 sw Y �rxY w)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)� packaging� get_files�endswithr3 �open�read)�package�desktopfile�line�fs r �find_package_desktopfilerE ] s� � � ����K��#�#�G�,���=�=��$��?�?�#7�8����Qk�Al���� �$��%��(�����8�&*�� &�%� -� �� &�%�s �#B�B
c � � g d�}d}|D ] }| j |� s�d} n |xr& | j d� xr | j 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/)r3 )�file�
pkg_whitelist�whitelist_match�is r �likely_packagedrK y sb � �.�M� �O�
���?�?�1��"�O�� � � %�4�?�?�=�#A�A� %�����$�G%� %r c �D � t j j | � \ }}t j j |� }t j j |� r t j j ||� } t
| � syt j | � S )z[Return the package that ships the given file.
Return None if no package ships it.
N) r% r r4 �realpath�isdir�joinrK r<