Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/oslo_utils/__pycache__/fileutils.cpython-39.pyc
Ðазад
a s�h� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl mZ ejej B ejB Zefdd�Zejfdd�Zejefdd ��Zddd �Zddd�Zdd� Zdd� Zdd� ZdS )z( File utilities. .. versionadded:: 1.8 � N)�excutilsc C sX zt �| |� W nB tyR } z*|jtjkr<t j�| �s>� n� W Y d}~n d}~0 0 dS )z�Create a directory (and any ancestor directories required) :param path: Directory to create :param mode: Directory creation permissions N)�os�makedirs�OSError�errno�EEXIST�path�isdir)r �mode�exc� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/oslo_utils/fileutils.py�ensure_tree% s r c C sD z|| � W n2 t y> } z|jtjkr*� W Y d}~n d}~0 0 dS )z�Delete a file, but ignore file not found error. :param path: File to delete :param remove: Optional function to remove passed path N)r r �ENOENT)r �remove�er r r �delete_if_exists5 s r c c sR z dV W nB t yL t�� � || � W d � n1 s>0 Y Y n0 dS )z�Protect code that wants to operate on PATH atomically. Any exception will cause PATH to be removed. :param path: File to work with :param remove: Optional function to remove passed path N)� Exceptionr Zsave_and_reraise_exception)r r r r r �remove_path_on_errorC s r � �tmpc C sL |rt |� tj|||d�\}}zt�|| � W t�|� nt�|� 0 |S )a� Create a temporary file containing data. Create a temporary file containing specified content, with a specified filename suffix and prefix. The tempfile will be created in a default location, or in the directory `path`, if it is not None. `path` and its parent directories will be created if they don't exist. :param content: bytestring to write to the file :param path: same as parameter 'dir' for mkstemp :param suffix: same as parameter 'suffix' for mkstemp :param prefix: same as parameter 'prefix' for mkstemp For example: it can be used in database tests for creating configuration files. .. versionadded:: 1.9 )�suffix�dir�prefix)r �tempfile�mkstempr �write�close)�contentr r r �fdr r r �write_to_tempfileS s r � �sha256c sj t �|�}t| d��>� t� �fdd�d�D ]}|�|� t�d� q*W d � n1 sX0 Y |�� S )a� Compute checksum of a file's contents. :param path: Path to the file :param read_chunksize: Maximum number of bytes to be read from the file at once. Default is 65536 bytes or 64KB :param algorithm: The hash algorithm name to use. For example, 'md5', 'sha256', 'sha512' and so on. Default is 'sha256'. Refer to hashlib.algorithms_available for available algorithms :return: Hex digest string of the checksum .. versionadded:: 3.31.0 �rbc s � � ��S )N)�readr ��f�read_chunksizer r �<lambda> � z'compute_file_checksum.<locals>.<lambda>r) r N)�hashlib�new�open�iter�update�time�sleep� hexdigest)r r'