509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
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   
