File: //lib/python3/dist-packages/sos/cleaner/archives/__pycache__/__init__.cpython-38.pyc
U
i��dN; � @ sb d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm Z dd� Z
G dd� d�ZdS )� N)�ProcessPoolExecutor)�file_is_binaryc C sN t �| �}tj�|d�}|�|� |�� tj�||j�d�d �d�d �S )NZcleaner�/����.tarr ) �tarfile�open�os�path�joinZ
extractall�close�name�split)�archive_path�tmpdir�archiver
� r �?/usr/lib/python3/dist-packages/sos/cleaner/archives/__init__.py�extract_archive s
r c @ s2 e Zd ZdZg ZdZdZdZdZdZ g Z
i Zdd� Ze
dd� �Zed d
� �Zedd� �Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zedd� �Zdd � Zd!d"� Zd#d$� ZdBd%d&�Zd'd(� Zd)d*� Z d+d,� Z!d-d.� Z"d/d0� Z#d1d2� Z$d3d4� Z%d5d6� Z&d7d8� Z'd9d:� Z(d;d<� Z)d=d>� Z*d?d@� Z+dAS )C�SoSObfuscationArchivea A representation of an extracted archive or an sos archive build
directory which is used by SoSCleaner.
Each archive that needs to be obfuscated is loaded into an instance of this
class. All report-level operations should be contained within this class.
r ZundeterminedFc C s� || _ | j | _|| _| j �d�d �d�d | _| j| _t�d�| _t�d�| _ | �
� | _d| _| �
� d| _| �d | j | jf � d S )
Nr r r r �sosZsos_uiF� zLoaded %s as type %s)r �final_archive_pathr r �archive_name�ui_name�loggingZ getLogger�soslog�ui_log�_load_skip_list� skip_list�is_extracted�
_load_self�archive_root�log_info�description)�selfr r r r r �__init__2 s
��zSoSObfuscationArchive.__init__c C s dS )z=Check if the archive is a well-known type we directly supportFr )�clsZarc_pathr r r �
check_is_typeC s z#SoSObfuscationArchive.check_is_typec C s d| j j�� kS )Nr )� __class__�__name__�lower�r% r r r �is_sosH s zSoSObfuscationArchive.is_sosc C s
d| j kS )NZinsights)� type_namer, r r r �is_insightsL s z!SoSObfuscationArchive.is_insightsc C s | j rt�| j�| _d S �N)�
is_tarfiler r r �tarobjr, r r r r! P s z SoSObfuscationArchive._load_selfc C s g S )a/ Return a list of ObfuscationArchives that represent additional
archives found within the target archive. For example, an archive from
`sos collect` will return a list of ``SoSReportArchive`` objects.
This should be overridden by individual types of ObfuscationArchive's
r r, r r r �get_nested_archivesT s z)SoSObfuscationArchive.get_nested_archivesc C s0 | j r"| jj}|�� r|jS tjS tj�| j �S )z|Set the root path for the archive that should be prepended to any
filenames given to methods in this class.
)
r1 r2 Zfirstmember�isdirr
r �sepr
�abspathr )r% Ztoplevelr r r �get_archive_root] s z&SoSObfuscationArchive.get_archive_rootc C s | j �d�| jd |�� dS )z9Helper to easily format ui messages on a per-report basisz {:<50} {}z :N)r �info�formatr �r% �msgr r r �
report_msgi s z SoSObfuscationArchive.report_msgc C s d| j |f S )Nz[cleaner:%s] %s)r r: r r r �_fmt_log_msgm s z"SoSObfuscationArchive._fmt_log_msgc C s | j �| �|�� d S r0 )r �debugr= r: r r r � log_debugp s zSoSObfuscationArchive.log_debugc C s | j �| �|�� d S r0 )r r8 r= r: r r r r# s s zSoSObfuscationArchive.log_infoc C s ddddddgS )zyProvide a list of files and file regexes to skip obfuscation on
Returns: list of files and file regexes
z
proc/kallsymsz
sosreport-zsys/firmwarezsys/fszsys/kernel/debugz
sys/moduler r, r r r r v s �z%SoSObfuscationArchive._load_skip_listc C s* zt �| j�W S tk
r$ Y dS X d S )NF)r r1 r � Exceptionr, r r r r1 � s z SoSObfuscationArchive.is_tarfilec C s8 | � |�}|r4| �d| � t�|� | jd7 _dS )z�Remove a file from the archive. This is used when cleaner encounters
a binary file, which we cannot reliably obfuscate.
z&Removing binary file '%s' from archive� N)�
get_file_pathr# r �remove�removed_file_count)r% �fnameZ
full_fnamer r r �remove_file� s
z!SoSObfuscationArchive.remove_filec C s: | j s&| js| �� | _tj�| j|�S tj�| j|�S dS )z�Based on the type of archive we're dealing with, do whatever that
archive requires to a provided **relative** filepath to be able to
access it within the archive
N)r r"