관리-도구
편집 파일: utilities.cpython-39.opt-1.pyc
a -�_g P � @ sv d dl Z d dlZd dlZd dlZd dlmZmZmZ d dlZd dl Z d dl Z d dlZd dlZd dl Z d dlZd dlZd dlZd dlmZ d dlmZ zd dlmZ W n ey� d dlmZ Y n0 e�d�ZdZzd dlZe�e� d ZW nD ee f�y0 d d l!m"Z" dZ#e�$de"e#d dd�� d�� Y n0 dZ%g d�Z&dd� Z'dKdd�Z(dd� Z)dLdd�Z*dd� Z+dd� Z,dMdd�Z-d d!� Z.dNd"d#�Z/e%ddddddddddfd$d%�Z0dOd&d'�Z1dPd)d*�Z2dQd,d-�Z3e j4fd.d/�Z5d0d1� Z6d2d3� Z7d4d5� Z8d6d7� Z9d8d9� Z:e j;d:�d;d<�Z<d=d>� Z=g fd?d@�Z>G dAdB� dB�Z?G dCdD� dDej@�ZAG dEdF� dF�ZBG dGdH� dH�ZCG dIdJ� dJeD�ZEdS )R� N)�Popen�PIPE�STDOUT)�closing)�deque)�parse)� parse_versionZsosFT)�fillz�WARNING: Failed to load 'magic' module version >= 0.4.20 which sos aims to use for detecting binary files. A less effective method will be used. It is recommended to install proper python3-magic package with the module. � �H )Zreplace_whitespacei, )�TIMEOUT_DEFAULT�ImporterHelper�SoSTimeoutError�TempFileUtil�bold�file_is_binary�fileobj�find�get_human_readable�grep� import_module� is_executable�listdirr �path_exists� path_isdir�path_isfile�path_islink� path_join�recursive_dict_values_by_key� shell_out�sos_get_command_output�tailc C s� t �d�}zF|j| dd�\}}}|s*| W S t �dd|��d�}|� d|� �}|W S ty� } z&t�d| � d |� �� | W Y d }~S d }~0 0 d S )z< Convert the version into a PEP440 compliant version scheme.z2^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?� )�maxsplitz[+~]+�.�-�+zUnable to format z to pep440 format: N)�re�compile�split�sub�strip� Exception�log�debug)�verZpublic_version_re�_Zpublic�localZsanitized_localZpep440_version�err� r3 �1/usr/lib/python3.9/site-packages/sos/utilities.py�format_version_to_pep440N s �r5 c C s |rt | �}t|�S t| �S )z6 Converts the version to PEP440 format before parsing )r5 r )r/ Zpep440Z ver_pep440r3 r3 r4 �sos_parse_version_ s r6 c C sT t | d��6}t�| �j|kr*|�| d� |�� W d � S 1 sF0 Y dS )z,Returns the last number_of_bytes of filename�rb� N)�open�os�stat�st_size�seek�read)�filenameZnumber_of_bytes�fr3 r3 r4 r! h s r! �rc C sZ t | t�rNzt| |dd�W S tyJ t�d| � d�� tt�� � Y S 0 nt| �S dS )z@Returns a file-like object that can be used as a context manager�utf-8��encodingz fileobj: z could not be openedN) � isinstance�strr9 �IOErrorr- r. r �io�StringIO)Zpath_or_file�moder3 r3 r4 r p s r c C sH ddddd�}|� � D ]*\}}| |krt| �| d�|� � S q| � S )zCConverts a number of bytes to a shorter, more human friendly formatl i @� � )�T�G�M�Kz.1f)�items�float)Z num_bytesZsizes�symbol�sizer3 r3 r4 � convert_bytes| s rU c s� t rNz6t�| �� ddg}� jdko8t� fdd�|D �� W S tyL Y n0 t| ddd��N}z|�d � W W d � dS ty� Y W d � dS 0 W d � n1 s�0 Y d S ) az Helper to determine if a given file contains binary content or not. This is especially helpful for `sos clean`, which cannot obfuscate binary data and instead, by default, will remove binary files. :param fname: The full path of the file to check binaryness of :type fname: ``str`` :returns: True if binary, else False :rtype: ``bool`` ztext/zinode/�binaryc 3 s | ]}� j �|�V qd S �N)Z mime_type� startswith)�.0Z_mt�Z_ftupr3 r4 � <genexpr>� � z!file_is_binary.<locals>.<genexpr>�trrB rC r"