File: //usr/lib64/python3.9/site-packages/syspurpose/__pycache__/utils.cpython-39.pyc
a
X�Zh � @ sl d Z ddlZddlZddlZddlZddlZe�e�Ze e
d�dd�Ze ee
d�dd�Z
edd �d
d�ZdS )z,
Utility methods for the syspurpose command
� N)�path�returnc
C sr zt j| dd� W nZ tyl } zB|jtjkr<W Y d}~dS |jtjkrXt�d�| �� W Y d}~n
d}~0 0 dS )z�
Attempts to create the path given (less any file)
:param path: path
:return: True if changes were made, false otherwise
i� )�modeNFzCannot create directory {}T) �os�makedirs�OSError�errno�EEXIST�EACCES�log�error�format)r �e� r �6/usr/lib64/python3.9/site-packages/syspurpose/utils.py�
create_dir s &r )r �contentsr c
C s� zFt j| ddd��"}t||� |�� W d � n1 s:0 Y W n^ ty� } zF|jtjkrpW Y d}~dS |jtjkr�t� d�
| �� n� W Y d}~n
d}~0 0 dS )z�
Attempts to create a file, with the given contents
:param path: The desired path to the file
:param contents: The contents to write to the file, should json-serializable
:return: True if the file was newly created, false otherwise
�wzutf-8)�encodingNFzCannot create file {}T)�io�open�write_to_file_utf8�flushr r r r
r r r
)r r �fr r r r �create_file, s
*r )�datar c C s | � tj|dddd�� dS )z�
Writes out the provided data to the specified file, with user-friendly indentation,
and in utf-8 encoding
:param file: The file to write to
:param data: The data to be written
:return:
� FT)�indentZensure_asciiZ sort_keysN)�write�json�dumps)�filer r r r r C s r )�__doc__r r r r ZloggingZ getLogger�__name__r �str�boolr �dictr r r r r r �<module> s