| Current Path : /usr/lib/python3/dist-packages/sos/__pycache__/ |
| Current File : //usr/lib/python3/dist-packages/sos/__pycache__/utilities.cpython-38.pyc |
U
�l�b�B �
@ s� d dl Z d dlZd dlZd dlmZmZmZ d dlZd dlZd dl Z d dl
Z
d dlZd dlZd dl
Z
d dlZd dlZd dlmZ d dlmZ dZdd� ZdAd d
�ZdBdd�Zdd� ZdCdd�Zdd� ZdDdd�Zedddddddddf
dd�ZdEdd�ZdFdd �ZdGd"d#�Ze j fd$d%�Z!d&d'� Z"d(d)� Z#d*d+� Z$d,d-� Z%d.d/� Z&e j'd0�d1d2�Z(d3d4� Z)g fd5d6�Z*G d7d8� d8�Z+G d9d:� d:e
j,�Z-G d;d<� d<e.�Z/G d=d>� d>�Z0G d?d@� d@e1�Z2dS )H� N)�Popen�PIPE�STDOUT)�closing)�dequei, c
C sH t | d��4}t�| �j|kr*|�| d� |�� W 5 Q R � S Q R X dS )z,Returns the last number_of_bytes of filename�rb� N)�open�os�stat�st_size�seek�read)�filenameZnumber_of_bytes�f� r �//usr/lib/python3/dist-packages/sos/utilities.py�tail s r �rc C s^ t | t�rRzt| |�W S tk
rN t�d�}|�d| � tt� � � Y S X nt| �S dS )z@Returns a file-like object that can be used as a context managerZsoszfileobj: %s could not be openedN)
�
isinstance�strr �IOError�loggingZ getLogger�debugr �io�StringIO)Zpath_or_file�mode�logr r r �fileobj% s
r � � � @� c C sd t | �}| |krd|| S | |kr0d|| S | |krDd|| S | |krXd|| S d| S dS )zCConverts a number of bytes to a shorter, more human friendly formatz%.1fTz%.1fGz%.1fMz%.1fKz%dN)�float)Zbytes_�K�M�G�T�fnr r r �
convert_bytes2 s r) c C sV t | d��B}z|�d� W W 5 Q R � dS tk
rF Y W 5 Q R � dS X W 5 Q R X dS )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``
Ztr� FTN)r r �UnicodeDecodeError)�fnameZtfiler r r �file_is_binaryA s
r- c c s� |r"t j�|��t jj�}||7 }t �|�D ]^\}}}|rV|�t jj�|krV|dd�= |rht�||�shq,t�|| �D ]}t j�||�V qtq,dS )z�Generator function to find files recursively.
Usage::
for filename in find("*.properties", "/var/log/foobar"):
print filename
N) r
�path�dirname�count�sep�walk�fnmatch�filter�join) Zfile_patternZtop_dirZ max_depthZpath_patternZ
base_depthr. �dirlistZfilelist�namer r r �findW s
r8 c
s>