3 if3@sddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl m Z dZ dddZddZd d Zd d Zd dZddZdS))print_functiondivisionabsolute_importN)ugettextz/etc/rhsm-host/cCsR|rDt|tgtfgkr"|f}x |D]}tjjt|dq(Wtj|dS)zDExit with a code and optional message(s). Saved a few lines of code. N)typesysstderrwritestrexit)codeZmsgsmsgr/usr/lib/python3.6/utils.py system_exit"s  rcCslytj|ddWnTtk rf}z8|jtjkr4dS|jtjkrVttjtdj |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) osmakedirsOSErrorerrnoEEXISTEACCESr EX_NOPERM_format)patherrr create_dir-s  "rcCsy2tj|ddd}t|||jWdQRXWnXtk r}z<|jtjkrTdS|jtjkrxtt j t dj |nWYdd}~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) ioopenwrite_to_file_utf8flushrrrrrrrrr)rcontentsfrrrr create_file?s   r'cCstjjtrdSdS)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)rrexistsHOST_CONFIG_DIRrrrr in_containerWs r*cCs>tjr |S|dk r6t|tr6t|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 Zunicodedecode)objrrr make_utf8cs  r/cCs |jttj|dddddS)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/jsondumps)filedatarrrr#rsr#)N)Z __future__rrrr!r2rrrr+Zsyspurpose.i18nrrr)rrr'r*r/r#rrrrs