???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
vh3                 @   s   d dl mZmZmZ d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ dZdddZdd Zd	d
 Zdd Zdd Zdd ZdS )    )print_functiondivisionabsolute_importN)ugettextz/etc/rhsm-host/c             C   sR   |rDt |t g t f gkr"|f}x |D ]}tjjt|d  q(W tj|  dS )zDExit with a code and optional message(s). Saved a few lines of code.
N)typesysstderrwritestrexit)codeZmsgsmsg r   /usr/lib/python3.6/utils.pysystem_exit"   s    
r   c             C   sl   yt j| dd W nT tk
rf } z8|jtjkr4dS |jtjkrVtt jtdj	|  W Y dd}~X nX dS )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er   r   r   
create_dir-   s    "r   c             C   s   y2t j| ddd}t|| |j  W dQ R X W nX tk
r } z<|jtjkrTdS |jtjkrxtt	j
tdj|  n W Y dd}~X nX dS )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
    wzutf-8)encodingNFz#Cannot create file {}
Are you root?T)ioopenwrite_to_file_utf8flushr   r   r   r   r   r   r   r   r   )r   contentsfr   r   r   r   create_file?   s    
r'   c               C   s   t jjtrdS dS )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)r   r   existsHOST_CONFIG_DIRr   r   r   r   in_containerW   s    r*   c             C   s>   t jr
| S | dk	r6t| tr6t| t r6| jd} | S | S dS )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
    Nzutf-8)sixZPY3
isinstancer   Zunicodedecode)objr   r   r   	make_utf8c   s    
r/   c             C   s    | j ttj|dddd dS )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datar   r   r   r#   r   s    r#   )N)Z
__future__r   r   r   r!   r2   r   r   r   r+   Zsyspurpose.i18nr   r   r)   r   r   r'   r*   r/   r#   r   r   r   r   <module>   s   
