3 •vh3ã@sŠddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl m Z dZ ddd„Zdd„Zd d „Zd d „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 t dƒ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Ú isinstancer ZunicodeÚ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Ús