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: //proc/thread-self/root/usr/lib/python3/dist-packages/apport/__pycache__/hookutils.cpython-38.pyc
U

��8dw��@sldZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlZddlZe�d�Zdadd�Zdkd	d
�Zdldd�Zdmd
d�Zdndd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"dd �Z#dej$ddfd!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(dej$dfd)d*�Z)d+d,�Z*d-d.�Z+dod/d0�Z,dpd1d2�Z-d3Z.d4Z/d5Z0d6Z1d7Z2d8Z3d9Z4d:Z5d;Z6d<Z7d=Z8d>Z9d?d@�Z:dAdB�Z;dqdCdD�Z<dEdF�Z=dGdH�Z>dIdJ�Z?drddK�dLdM�Z@dNdO�ZAdPdQ�ZBdRdS�ZCdsdTdU�ZDdVdW�ZEdXdY�ZFdZd[�ZGd\d]�ZHdtd_d`�ZIdadb�ZJdcdd�ZKdedf�ZLdudgdh�ZMdidj�ZNejOjPZPejOjQZQdS)vz/Convenience functions for use in package hooks.�N)�implz[^0-9a-zA-Z_.-]cCsLtjddkr$t|t�r8|�d�}nt|t�s8|�d�}t�d|�dd��S)z{Generate a valid report key name from a file path.

    This will replace invalid punctuation symbols with valid ones.
    r�3�UTF-8�.� �_)	�sys�version�
isinstance�bytes�decode�encode�_invalid_key_chars_re�sub�replace)�path�r�2/usr/lib/python3/dist-packages/apport/hookutils.py�path_to_key's


rTFcCs8d|krdS|st|�}tj�|�r4t|||||�dS)a�Attach file contents if file exists.

    If key is not specified, the key name will be derived from the file
    name with path_to_key().

    If overwrite is True, an existing key will be updated. If it is False, a
    new key with '_' appended will be added instead.

    If the contents is valid UTF-8, or force_unicode is True, then the value
    will be a string, otherwise it will be bytes.
    �../N)r�osr�exists�attach_file��reportr�keyZ	overwrite�
force_unicoderrr�attach_file_if_exists5src
Cs&z�d|krWdSt�|tjtjBtjB�}t�|�}tj�|�}|jt�	|�jksZ||krjt�
|�WdSt	�|j�r�t�
|d��}|����}W5QRXnt�
|�WdS|r�|jddd�WSz|�d�WWStk
r�|YWSXWn4tk
�r }zd	t|�WY�Sd
}~XYnXd
S)aReturn the contents of the specified path.

    If the contents is valid UTF-8, or force_unicode is True, then the value
    will a string, otherwise it will be bytes.

    Upon error, this will deliver a text representation of the error,
    instead of failing.
    rzError: invalid path.zError: path contained symlinks.�rbz#Error: path was not a regular file.rr��errors�Error: N)r�open�
O_NOFOLLOW�O_RDONLY�
O_NONBLOCK�fstatr�realpath�st_ino�stat�close�S_ISREG�st_mode�fdopen�read�stripr�UnicodeDecodeError�	Exception�str)rr�fd�stZ	real_path�f�contents�errr�	read_fileMs,	


r8cCs6|st|�}|s"||kr"|d7}qt||d�||<dS)a�Attach a file to the report.

    If key is not specified, the key name will be derived from the file
    name with path_to_key().

    If overwrite is True, an existing key will be updated. If it is False, a
    new key with '_' appended will be added instead.

    If the contents is valid UTF-8, or force_unicode is True, then the value
    will a string, otherwise it will be bytes.
    r)rN)rr8rrrrrrs
rc
Cs�t�|�}|��D]�\}}|r(||kr(qdt|�}t|�tkr\|dksR|�d�r\|||<q|r�|�d|�}|r||||<q�d||<nd||<tj�	t
�|�j�}	|	�
�|dt|�<qdS)a(Attach information about any modified or deleted conffiles.

    If conffiles is given, only this subset will be attached. If ui is given,
    ask whether the contents of the file may be added to the report; if this is
    denied, or there is no UI, just mark it as "modified" in the report.
    zmodified.conffile.z	[deleted]z
[inaccessibleznIt seems you have modified the contents of "%s".  Would you like to add the contents of it to your bug report?z
[modified]zmtime.conffile.N)�	packagingZget_modified_conffiles�itemsr�typer2�
startswithZyesno�datetimeZ
fromtimestamprr)�st_mtimeZ	isoformat)
r�packageZ	conffilesZuiZmodifiedrr6rZresponse�mtimerrr�attach_conffiles�s 


rAcCstztj�|�}Wntk
r&YdSX|D]B}tj�|�r,|�d�r,|�dd�}d|�dd�}t	|||�q,dS)z3Attach information about any Upstart override filesNz
/etc/init/�.confz	.override�upstart.�)
�apportr9�	get_files�
ValueErrorrrrr<rr)rr?�files�file�overriderrrr�attach_upstart_overrides�srKcCs�ztj�|�}Wntk
r&YdSX|D�]`}tj�|�s@q,|�d�r�tj�|��	dd�}d|}ztj�
tjdd|�}WnLtk
r�ztj�
tjdd	d|�}Wntk
r�YYq,YnXYnXt
|||�|�d
�r,|�d�r,tj�tj�|��d}d
|}d|}ztj�
tjdd|�}WnPtk
�r�ztj�
tjdd	d|�}Wntk
�rzYYq,YnXYnXt
|||�q,dS)z9Attach information about a package's session upstart logsNz/usr/share/upstart/sessions/rBz.logrCZXDG_CACHE_HOMEZupstart�HOMEz.cachez/usr/share/applications/z.desktoprzupstart.application.zapplication-%s.log)rEr9rFrGrrrr<�basenamer�join�environ�KeyErrorr�endswith�splitext)rr?rHr5�logrZdesktopnamerrr�attach_upstart_logs�s<

rTcCs"|�dd���stdg�|d<dS)zwAttach information from the kernel ring buffer (dmesg).

    This will not overwrite already existing information.
    ZCurrentDmesgrD�dmesgN)�getr/�command_output�rrrr�attach_dmesg�srYc
Cs�d}tj�|�r�t�|�D]�}tj�d||f�}t�|�}t�|j�r|jd@dkrXq|dkrbqzt|�}Wnt	t
fk
r�YqYnX|r||d|�dd�<qdS)	Nz/sys/class/dmi/idz%s/%s�r)Z	subsystem�ueventzdmi.rr)rr�isdir�listdirr'r)r+r,r8�OSError�IOErrorr)rZdmi_dirr5�pr4�valuerrr�
attach_dmi�s

rbcCs�t|�t|dd�t|dd�t|dd�tj�d�rXtdd	g�|d
<tddg�|d<td
g�|d<td
dg�|d<td
dg�|d<tddg�|d<tdddg�|d<tdg�|d<|d}t�dd|�}t�dd|�}t�d d!|�}t�dd|�}t�dd|�}t�d d!|�}||d<t	|�d"|k�rNd#|k�rNd$|d"|d#f|d%<t
d&��rftd&g�|d'<t
d(��r�td(d)g���}|�r�||d*<td(d+g���}|�r�||d,<d-S).a~Attach a standard set of hardware-related data to the report, including:

    - kernel dmesg (boot and current)
    - /proc/interrupts
    - /proc/cpuinfo
    - /proc/cmdline
    - /proc/modules
    - lspci -vvnn
    - lscpi -vt
    - lsusb
    - lsusb -v
    - lsusb -t
    - devices from udev
    - DMI information from /sys
    - prtconf (sparc)
    - pccardctl status/ident
    z/proc/interruptsZProcInterrupts�
/proc/cpuinfo�ProcCpuinfo�
/proc/cmdlineZProcKernelCmdLinez/sys/bus/pci�lspci�-vvnnZLspciz-vtzLspci-vt�lsusbZLsusb�-vzLsusb-vz-tzLsusb-t�sort�
/proc/modulesZProcModulesZudevadm�infoz--export-dbZUdevDbz%/usr/share/apport/dump_acpi_tables.pyZacpidumpzID_FS_LABEL=(.*)zID_FS_LABEL=<hidden>zID_FS_LABEL_ENC=(.*)zID_FS_LABEL_ENC=<hidden>z
by-label/(.*)zby-label/<hidden>zdmi.sys.vendorzdmi.product.namez%s %sZMachineTypeZprtconfZPrtconfZ	pccardctlZstatusZPccardctlStatusZidentZPccardctlIdentN)rYrrrrrW�root_command_output�rerrb�command_availabler/)r�labels�outrrr�attach_hardware�sH��


rrc	Cs�t|tj�d�d�t|tj�d�d�t|d�t|dd�t|dd	�td
ddg�|d
<tddg�|d<tddg�|d<tt�|d<g}tj�d�r�t	d��6}|D]*}d|kr�|�
���}|�t
|d��q�W5QRX|D]�}d|}tddt|�dg�||<d|}tddt|�g�||<t�d|�D]�}tj�|��rntj�|�}d|t|�f}t|||d�n\tj�|��r0tj�|�}t�|�D]6}	tj�||	�}
d|t|�t|	�f}t||
|��q��q0q�dS) z� (loosely based on http://www.alsa-project.org/alsa-info.sh)
    for systems where alsa-info is not installed (i e, *buntu 12.04 and earlier)
    z~/.asoundrcZUserAsoundrcz~/.asoundrc.asoundconfZUserAsoundrcAsoundconfz/etc/asound.confz/proc/asound/versionZAlsaVersionrcrdZlsz-lz	/dev/snd/ZAlsaDevicesZaplayZAplayDevicesZarecordZArecordDevicesZ
PciMultimediaz/proc/asound/cardsz]:rzCard%d.Amixer.infoZamixerz-crlzCard%d.Amixer.valuesz/proc/asound/card%d/codec*zCard%d.Codecs.%s�rzCard%d.Codecs.%s.%sN)rrr�
expanduserrrW�pci_devices�PCI_MULTIMEDIArr"�lstrip�split�append�intr2�glob�isfilerMrr\r]rN)rZcardsr3�line�fieldsZcardrZ	codecpath�codec�namerrrr�attach_alsa_old:sH��

r�cCs�tj�d�r tdddg�|d<nt|�tddgt�d�t�d�t�d	��|d
<tj�d�rrtdd
g�|d<t|�t|�dS)z5Attach ALSA subsystem information to the report.
    z!/usr/share/alsa-base/alsa-info.shz--stdoutz--no-uploadZAlsaInfoZfuserriz	/dev/dsp*z
/dev/snd/*z	/dev/seq*ZAudioDevicesInUsez/usr/bin/pacmdZpacmd�listZ	PulseListN)rrrrWr�r{rbrYrXrrr�attach_alsags$�r�cCsbdtjkrdStjd}|�tj�D]8}|s.q$tj�||�}tj�|�r$t�|tj�r$dSq$dS)z/Is given command on the executable search path?�PATHFT)	rrOrx�pathseprrNr|�access�X_OK)�commandr�element�filenamerrrroys

roc

Cs�tj��}|sd|d<z$tj|tj||r.tjp0d|d�}Wn2tk
rl}zdt|�WY�Sd}~XYnX|�|�d}|j	dkr�|�
�}	n*dt|���dt|j	���d	|}	|r�|	jd
dd�}	|	S)
a;Try to execute given command (list) and return its stdout.

    In case of failure, a textual error gets returned. This function forces
    LC_MESSAGES to C, to avoid translated output in bug reports.

    If decode_utf8 is True (default), the output will be converted to a string,
    otherwise left as bytes.
    �C�LC_MESSAGESN)�stdout�stderr�stdin�envr!rsError: command s failed with exit code s: rrr)
rrO�copy�
subprocess�Popen�PIPEr^r2�communicate�
returncoder/r
r)
r��inputr��keep_locale�decode_utf8r��spr7rq�resrrrrW�s0


�
"

���rWc	Cs�tdk	rdSt��dkrdStj��s*dStj�d�s:dSzt�d�\}}Wnt	k
rbYdSXt
jddt|�dgdt
j
t
j
d�at�|�t���P}|�|tj�|��}|D],\}}|tj@r�t�|�W5QR�dSq�q�W5QRXdS)Nrz/usr/bin/pkttyagentZ
pkttyagentz--notify-fdz
--fallbackF)Z	close_fdsr�r�)�_AGENTr�geteuidrr��isattyrr�pipe2r^r�r�r2r�r*�select�epoll�registerZEPOLLIN�pollZEPOLLHUP)�r�wr�Zeventsr3Z
event_typerrr�_spawn_pkttyagent�s4
�



r�cCs$tdkrdSt��t��dadS)N)r�Z	terminate�waitrrrr�kill_pkttyagent�s
r�cCs0t��dkrgStj�d�r(t�dgSgSdS)Nrz/usr/bin/pkexecZpkexec)r�getuidrrr�rrrr�_root_command_prefix�sr�cCs.t|t�std��tt�|||d|d�}|S)a=Try to execute given command (list) as root and return its stdout.

    This passes the command through pkexec, unless the caller is already root.

    In case of failure, a textual error gets returned.

    If decode_utf8 is True (default), the output will be converted to a string,
    otherwise left as bytes.
    zcommand must be a listT)r�r�)r
r��AssertionErrorrWr�)r�r�r�r��outputrrrrm�s
�rmc
CsLtj�tj�tj�dd��d�}t��}�ztj�|d�}t
|d�}|��D]6\}}t|d�sft
d��|�d|tj�||�f�qL|��t�t�||g�}|��|D]�}z0t
tj�||�d	��}	|	����}
W5QRXWntk
r�Yq�YnXz|
�d
�}
Wntk
�rYnX|
�r.|
||<|	��q�W5t�	|�XdS)a*Execute multiple commands as root and put their outputs into report.

    command_map is a keyname -> 'shell command' dictionary with the commands to
    run. They are all run through /bin/sh, so you need to take care of shell
    escaping yourself. To include stderr output of a command, end it with
    "2>&1".

    Just like root_command_output, this passes the command through pkexec,
    unless the caller is already root.

    This is preferrable to using root_command_output() multiple times, as that
    will ask for the password every time.
    ZAPPORT_DATA_DIRz/usr/share/apportZroot_info_wrapperz:script:r�r/z(command must be a string (shell command)z%s | cat > %s
rrN)rrrN�abspathrOrV�tempfileZmkdtemp�shutilZrmtreer"r:�hasattrr��writer*r�r�r�r�r.r/r_rr0)rZcommand_mapZwrapper_pathZworkdirZscript_pathZscriptZkeynamer�r�r5Zbufrrr�attach_root_command_outputs�s:��

r�cCsbd}|��dkr>|jD]$}|jddd�}|�|�r||7}qq|j��|��|jdkr^|SdS)NrDrrrr)r�r�r�searchr*r�r�)�patternZprocess�linesr}rrr�__filter_re_process&s



r�cCsv|rtjddd|gtjd�}nNtj�d�rFtjdddd	d
gtjd�}n&t�dtj�rltjddddgtjd�}t||�S)z�Extract recent system messages which match a regex.

    pattern should be a "re" object. By default, messages are read from
    the systemd journal, or /var/log/syslog; but when giving "path", messages
    are read from there instead.
    �tailz-nZ10000�r��/run/systemd/system�
journalctlz--systemz--quiet�-bz-az/var/log/syslog)	r�r�r�rrrr��R_OKr�)r�rr`rrr�
recent_syslog4s���r�c	Cs�tj�d�}tj�|�r&t�|tj�s*dS|s8t�d�}d}t|d��0}|D]$}|j	ddd�}|�
|�rL||7}qLW5QRX|S)alExtract messages from ~/.xsession-errors.

    By default this parses out glib-style warnings, errors, criticals etc. and
    X window errors.  You can specify a "re" object as pattern to customize the
    filtering.

    Please note that you should avoid attaching the whole file to reports, as
    it can, and often does, contain sensitive and private data.
    z~/.xsession-errorsrDz�^(\(.*:\d+\): \w+-(WARNING|CRITICAL|ERROR))|(Error: .*No Symbols named)|([^ ]+\[\d+\]: ([A-Z]+):)|([^ ]-[A-Z]+ \*\*:)|(received an X Window System error)|(^The error was \')|(^  \(Details: serial \d+ error_code)rrrr)rrrtrr�r�rn�compiler"rr�)r�rr�r5r}rrr�xsession_errorsGs
�

r����rZ�����	�
��c

Gs�|stddg�Sd}tddg�}|�d�D]�}d}d}|�d�D]v}z|�dd	�\}}Wntk
rpYq@YnX|��}|��}|d
kr�t|dd�d
�}	|	d@d?}q@|dkr@|}q@|r*|r*||kr*|r�|d7}|tdd|g���7}q*|S)z9Return a text dump of PCI devices attached to the system.rfrgrDz-vvmmnnz

N�
�:r�ZClass�������i�r�ZSlotz-vvnns)rWrxrGr/rz)
Zpci_classes�resultr�Z	paragraphZ	pci_classZslotr}rra�nrrrrups0
rucCstddg�S)z9Return a text dump of USB devices attached to the system.rhri)rWrrrr�usb_devices�sr�cs*t�|�}�r"�fdd�|D�}n|}|S)zFRetrieve a list of files owned by package, optionally matching globpatcsg|]}tj�|��r|�qSr)r{Zfnmatch)�.0r5��globpatrr�
<listcomp>�sz$files_in_package.<locals>.<listcomp>)r9rF)r?r�rHr�rr�r�files_in_package�s

r�cCsdS)ZObsoleteNr)rr?rrr�attach_gconf�sr�c
	Cs6|�dd�}i}tj��}d|d<tjdd|g|tjd�}|jD]L}z|�dd	�\}}}	|	�	�}	Wnt
k
rzYq@YnX|	|�|i�|<q@tjdd|gtjd
�}|jD]~}z|�dd	�\}}}	|	�	�}	Wnt
k
r�Yq�YnX|	|�|i��|d�kr�|dk�r|dk�rd
}	|d|||	f7}q�||d<dS)z0Attach user-modified gsettings keys of a schema.ZGsettingsChangesrDz/nonexistingZXDG_CONFIG_HOME�	gsettingszlist-recursively)r�r�Nr�r�sorg.gnome.shell)scommand-historys
favorite-appszredacted by apportz	%s %s %s
)rVrrOr�r�r�r�r�rx�rstriprG�
setdefault)
r�schemaZ	cur_value�defaultsr�r�r}Zschema_namerrarrr�attach_gsettings_schema�s>
�

�


�r�cCs2t|d�D]"}tj�|�dd�}t||�q
dS)z@Attach user-modified gsettings keys of all schemas in a package.z)/usr/share/glib-2.0/schemas/*.gschema.xmlNi�)r�rrrMr�)rr?Zschema_filer�rrr�attach_gsettings_package�sr�)�returncCsbtj�d�sdS|��}|rB||}||}d|��d|��g}nddg}tddg|�|d	<dS)
z�Attach journal warnings and errors.

    If the report contains a date, get the journal logs around that
    date (plus/minus the time_window in seconds). Otherwise attach the
    latest 1000 journal logs since the last boot.
    r�Nz	--since=@z	--until=@r�z--lines=1000r�z--priority=warningZ
JournalErrors)rrrZ
get_timestamprW)rZtime_windowZcrash_timestampZbefore_crashZafter_crash�argsrrr�attach_journal_errors�s
�r�cCs`tddg�|d<tddg�|d<tt�|d<t|ddd	�d
D]}|tjkr>tj|||<q>dS)z5Attach generic network-related information to report.ZipZrouteZIpRouteZaddrZIpAddrZ
PciNetworkz/etc/network/interfacesZIfupdownConfigrs)Z
http_proxyZ	ftp_proxyZno_proxyN)rWru�PCI_NETWORKrrrO)r�varrrr�attach_network�s
r�cCs�tt�d��|d<t�ddt�ddt�ddtd	g����|d
<tddg�|d
<tj�d�rjtdddg�}nd}||d<t|ddd�dS)z5Attach wireless (WiFi) network information to report.zH(NetworkManager|modem-manager|dhclient|kernel|wpa_supplicant)(\[\d+\])?:Z
WifiSyslogz
ESSID:(.*)zESSID:<hidden>zEncryption key:(.*)zEncryption key: <hidden>zAccess Point: (.*)zAccess Point: <hidden>ZiwconfigZIwConfigZrfkillr�ZRfKillz/sbin/iwZiwZregrV�N/AZCRDAz/var/log/wpa_supplicant.logZWpaSupplicantLogrsN)	r�rnr�rrWrrrr)rZ	iw_outputrrr�attach_wifi�s ���r�c!Cs�t|dd�t|dd�tdg�|d<tddg�|d	<t�d
�}|rhtddd
g|�}t�dd|�|d<tdddddddddddddddd d!d"d#d$d%d&d'd(dd)d*d+d,d-d.d/� |d0<d1S)2zkAttach printing information to the report.

    Based on http://wiki.ubuntu.com/PrintingBugInfoScript.
    z/etc/papersizeZ	Papersizez/var/log/cups/error_logZCupsErrorLog�localeZLocaleZlpstatriZLpstatz/etc/cups/ppd/*.ppdZfgrepz-Hz	*NickNamez*/etc/cups/ppd/(.*).ppd:\*NickName: *"(.*)"z\g<1>: \g<2>ZPpdFilesZfoo2zjszfoomatic-dbzfoomatic-db-enginezfoomatic-db-gutenprintzfoomatic-db-hpijszfoomatic-filterszfoomatic-guiZhpijsZhplipZm2300wZmin12xxwZc2050ZhpojZpxljrZpnm2ppaZsplixzhp-ppdz
hpijs-ppdszlinuxprinting.org-ppdszopenprinting-ppdszopenprinting-ppds-extraZghostscriptZcupszcups-driver-gutenprintZ
ijsgutenprintzcupsys-driver-gutenprintzgimp-gutenprintzgutenprint-doczgutenprint-localeszsystem-config-printer-commonZkdeprintZPrintingPackagesN)rrWr{rnr�package_versions)rZppdsZ	nicknamesrrr�attach_printing
sT
�r�c		Csvt|t�r|g}d}t�|tj�}d}t�|tj�}d|krXt|tjdgtjd��|d<d|kr�t	j
�d�r�t|dd|d	i�t
|d
d�t|dd
�t�||�dd�|�dd��D]�}|s�t|d��qrzR|ddkr�|dd�}n4tjddk�rt�|�jddd�}n|jddd�}Wntk
�r>Yq�YnX|D]*}t�d|d|��rDt|d�q��qDq�dS)z0Attach MAC information and events to the report.z!audit\(|apparmor|selinux|securityz'apparmor="DENIED".+?profile=([^ ]+?)[ ]ZKernLogrUr�ZAuditLogz/var/run/auditd.pidzegrep "z" /var/log/audit/audit.logz/proc/version_signatureZProcVersionSignaturereZProcCmdlinerDZapparmorr�"r�r�rrrr�hex�^�$N)r
r2rnr��
IGNORECASEr�r�r�r�rrrr�rr�findallrV�_add_tagrr	r�fromhexrr1�match)	rZprofilesZ	mac_regexZmac_reZaa_regexZaa_rer�ZprofileZsearch_profilerrr�attach_mac_events(s>
�$


r�cCs(|�dd�}|r|d7}|||d<dS)z#Adds or appends a tag to the reportZTagsrDrN)rV)r�tagZcurrent_tagsrrrr�Ssr�cCst|�|d<dS)ziAttach version information for related packages

    In the future, this might also run their hooks.
    ZRelatedPackageVersionsN)r�)r�packagesrrr�attach_related_packages[sr�c
s�|sdSg}|D]v}|sqt�|�}|s6|�|df�t|�D]F}zt�|�}Wntk
rhd}YnX|dkrvd}|�||f�q>qttdd�t|�D��\}}d|�d�	�fdd�|D��S)	ztReturn a text listing of package names and versions.

    Arguments may be package names or globs, e. g. "foo*"
    rDr�NcSsg|]}tt|��qSr)�map�len)r��trrrr�~sz$package_versions.<locals>.<listcomp>z
%%-%ds %%sr�csg|]}�|�qSrr)r��v�Zfmtrrr��s)
r9Zpackage_name_globry�sortedZget_versionrGr��max�ziprN)r�ZversionsZpackage_patternZmatching_packagesr?r	Z
package_widthZ
version_widthrr�rr�cs*

�r�cCs�z>tjd|gtjtjd�}|��d�d�}|jdkr<WdSWntk
rTYdSX|��D]:}|�dd�}t	|�d	kr|q^|dd
kr^|d�
�Sq^dS)z-Return the license for a given kernel module.z
/sbin/modinfo)r�r�rrZinvalidNr�r�r��license)r�r�r�r�rr�r^�
splitlinesrxr�r/)�moduleZmodinforqr}r~rrr�_get_module_license�s"
�

rrkc	Cs�z&t|��}dd�|D�}W5QRXWntk
r>gYSXg}|D]:}t|�}|rHd|ksHd|ksHd|ksHd|ksH|�|�qH|S)zCCheck loaded modules and return a list of those which are not free.cSsg|]}|��d�qS)r)rx�r�r}rrrr��sz*nonfree_kernel_modules.<locals>.<listcomp>ZGPLZBSDZMPLZMIT)r"r_rry)Zmodule_listr5ZmodsZnonfree�m�srrr�nonfree_kernel_modules�s

$rcCs�d}t�|�D]�}tj�||�}|dkstj�|�s6qt|d�����}|dkr\|�dd�}|dkrvt	�
|�}|d7}|d	||jd
dd�f7}q|S)
NrDr[rZmodes�
� Zedidz-base64z%s: %s
rrr)rr]rrNr|r"r.r/r�base64Z	b64encoder)�conrlr5r�valrrr�__drm_con_info�s
r
cCs`d}tj�|�sdSt�|�D]<}tj�||�}tj�tj�|d��rt|�|dt|�<qdS)zWAdd information about DRM hardware.

    Collect information from /sys/class/drm/.
    z/sys/class/drmN�enabledzDRM.)rrr\r]rNrr
r)rZdrm_dirr5rrrr�attach_drm_info�src
Cs:tj�d�}|sztd��\}|D]B}|��}d|kr|�d�rd|kr|�dd�ddd�}qpqW5QR�dSW5QRXt�tj	�}z^zHz&t�
tj	d	�t�t�
|d
��}Wntk
r�YW�WdSXW5t�
tj	|�XWntjk
�r�YdSXzt�d|�j}Wnttfk
�r0YdSX||kS)z�Check if the problem happened in the currently running XDG session.

    This can be used to determine if e. g. ~/.xsession-errors is relevant and
    should be attached.

    Return None if this cannot be determined.
    ZXDG_SESSION_IDz/proc/self/cgroupz
name=systemd:z.scopez	/session-r�Ni����r�ZDatez/run/systemd/sessions/)rrOrVr"r/rQrxr�Z	getlocale�LC_TIME�	setlocale�time�mktime�strptimerP�Errorr)r>r_r^)rZ
session_idr5r}Z
orig_ctimeZreport_timeZsession_start_timerrr�in_session_of_problem�s0
rc	CsVd}|st|�}tj�|�rRt|d��&}dd�|��D�}d�|�||<W5QRXdS)z;attach /etc/default/grub after filtering out password linesz/etc/default/grubr�cSsg|]}|�d�s|nd�qS)Zpasswordz### PASSWORD LINE REMOVED ###)r<rrrrr��s�z'attach_default_grub.<locals>.<listcomp>rDN)rrrrr"�	readlinesrN)rrrr5Zfilteredrrr�attach_default_grub�s�rcCsvd}g}tj�|�rLt|dd|i�d|krLt�|d�}|d}|d}||d<|rfd�|�|d<|�dd	�d	S)
z:attach the results of the casper md5check of install media�skipZ
CasperMD5jsonzcat '%s'r�Zchecksum_missmatchZCasperMD5CheckResultrZCasperMD5CheckMismatchesN)rrrr��json�loadsrN�pop)r�locationr�Z
mismatchesZcheckrrr�attach_casper_md5checksr)NTF)F)NTF)NN)N)N)N)r�)N)rk)N)R�__doc__r�rrrr=r{rnr)r
r�r�r�r�rZapport.packaging_implrr9rE�apport.fileutilsr�rr�rrr8rrArKrTrYrbrrr�r�roZSTDOUTrWr�r�r�rmr�r�r�r�ZPCI_MASS_STORAGEr�ZPCI_DISPLAYrvZ
PCI_MEMORYZ
PCI_BRIDGEZPCI_SIMPLE_COMMUNICATIONSZPCI_BASE_SYSTEM_PERIPHERALSZPCI_INPUT_DEVICESZPCI_DOCKING_STATIONSZPCI_PROCESSORSZPCI_SERIAL_BUSrur�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrrr�	fileutilsZshared_librariesZlinks_with_shared_libraryrrrr�<module>s�


%

'	@-�
!#5

!
$

+!
*