Your IP : 18.191.120.103


Current Path : /usr/lib/python3.6/site-packages/syspurpose/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/syspurpose/__pycache__/utils.cpython-36.opt-1.pyc

3

i�f3�@s�ddlmZmZmZddlZddlZddlZddlZddlZddl	Z	ddl
mZdZ
ddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�ZdS)�)�print_function�division�absolute_importN)�ugettextz/etc/rhsm-host/cCsR|rDt|�tg�tf�gkr"|f}x |D]}tjjt|�d�q(Wtj|�dS)zDExit with a code and optional message(s). Saved a few lines of code.�
N)�type�sys�stderr�write�str�exit)�codeZmsgs�msg�r�/usr/lib/python3.6/utils.py�system_exit"s
rcCslytj|dd�WnTtk
rf}z8|jtjkr4dS|jtjkrVttjtd�j	|��WYdd}~XnXdS)z�
    Attempts to create the path given (less any file)
    :param path: path
    :return: True if changes were made, false otherwise
    i�)�modeFz(Cannot create directory {}
Are you root?NT)
�os�makedirs�OSError�errno�EEXIST�EACCESr�	EX_NOPERM�_�format)�path�errr�
create_dir-s"rcCs�y2tj|ddd��}t||�|j�WdQRXWnXtk
r�}z<|jtjkrTdS|jtjkrxtt	j
td�j|��n�WYdd}~XnXdS)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)�encodingNFz#Cannot create file {}
Are you root?T)
�io�open�write_to_file_utf8�flushrrrrrrrrr)r�contents�frrrr�create_file?s
r'cCstjjt�rdSdS)z�
    Are we running in a docker container or not?

    Assumes that if we see host rhsm configuration shared with us, we must
    be running in a container.
    TF)rr�exists�HOST_CONFIG_DIRrrrr�in_containerWsr*cCs>tjr
|S|dk	r6t|t�r6t|t�r6|jd�}|S|SdS)z�
    Transforms the provided string into unicode if it is not already
    :param obj: the string to decode
    :return: the unicode format of the string
    Nzutf-8)�sixZPY3�
isinstancerZunicode�decode)�objrrr�	make_utf8cs
r/cCs |jttj|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)�indentZensure_asciiZ	sort_keysN)r
r/�json�dumps)�file�datarrrr#rsr#)N)Z
__future__rrrr!r2rrrr+Zsyspurpose.i18nrrr)rrr'r*r/r#rrrr�<module>s


?>