# Path: third_party/xiuminglib/xiuminglib/log.py
# def get_logger(level=None):
#     """Creates a logger for functions in the library.
# 
#     Args:
#         level (str, optional): Logging level. Defaults to ``logging.INFO``.
# 
#     Returns:
#         logging.Logger: Logger created.
#     """
#     if level is None:
#         level = logging.INFO
#     logging.basicConfig(level=level)
#     logger = logging.getLogger()
#     return logger
# 
# Path: third_party/xiuminglib/xiuminglib/imprt.py
# def preset_import(name, assert_success=False):
#     """A unified importer for both regular and ``google3`` modules, according
#     to specified presets/profiles (e.g., ignoring ``ModuleNotFoundError``).
#     """
#     if name in ('cv2', 'opencv'):
#         try:
#             # BUILD dep:
#             # "//third_party/py/cvx2",
#             from cvx2 import latest as mod
#             # Or
#             # BUILD dep:
#             # "//third_party/OpenCVX:cvx2",
#             # from google3.third_party.OpenCVX import cvx2 as cv2
#         except ModuleNotFoundError:
#             mod = import_module_404ok('cv2')
# 
#     elif name in ('tf', 'tensorflow'):
#         mod = import_module_404ok('tensorflow')
# 
#     elif name == 'gfile':
#         # BUILD deps:
#         # "//pyglib:gfile",
#         # "//file/colossus/cns",
#         mod = import_module_404ok('google3.pyglib.gfile')
# 
#     elif name == 'video_api':
#         # BUILD deps:
#         # "//learning/deepmind/video/python:video_api",
#         mod = import_module_404ok(
#             'google3.learning.deepmind.video.python.video_api')
# 
#     elif name in ('bpy', 'bmesh', 'OpenEXR', 'Imath'):
#         # BUILD deps:
#         # "//third_party/py/Imath",
#         # "//third_party/py/OpenEXR",
#         mod = import_module_404ok(name)
# 
#     elif name in ('Vector', 'Matrix', 'Quaternion'):
#         mod = import_module_404ok('mathutils')
#         mod = _get_module_class(mod, name)
# 
#     elif name == 'BVHTree':
#         mod = import_module_404ok('mathutils.bvhtree')
#         mod = _get_module_class(mod, name)
# 
#     else:
#         raise NotImplementedError(name)
# 
#     if assert_success:
#         assert mod is not None, "Failed in importing '%s'" % name
# 
#     return mod
# 
# Path: third_party/xiuminglib/xiuminglib/interact.py
# def format_print(msg, fmt):
#     """Prints a message with format.
# 
#     Args:
#         msg (str): Message to print.
#         fmt (str): Format; try your luck with any value -- don't worry; if
#             it's illegal, you will be prompted with all legal values.
#     """
#     fmt_strs = {
#         'header': '\033[95m',
#         'okblue': '\033[94m',
#         'okgreen': '\033[92m',
#         'warn': '\033[93m',
#         'fail': '\033[91m',
#         'bold': '\033[1m',
#         'underline': '\033[4m',
#     }
#     if fmt in fmt_strs.keys():
#         start_str = fmt_strs[fmt]
#         end_str = '\033[0m'
#     elif len(fmt) == 1:
#         start_str = "\n<" + "".join([fmt] * 78) + '\n\n' # as per PEP8
#         end_str = '\n' + start_str[2:-2] + ">\n"
#     else:
#         raise ValueError(
#             ("Legal values for fmt: %s, plus any single character "
#              "(which will be repeated into the line separator), "
#              "but input is '%s'") % (list(fmt_strs.keys()), fmt))
#     print(start_str + msg + end_str)


import os
from os.path import join, exists, isdir, dirname
from shutil import rmtree, copy2, copytree
from glob import glob
from .log import get_logger
from .imprt import preset_import
from .interact import format_print
    from collections import OrderedDict
    from json import dump
    from shlex import split
    from subprocess import Popen, DEVNULL
    from subprocess import Popen, PIPE
        cmd (str): Command to be executed.
        cwd (str, optional): Directory to execute the command in. ``None``
            means current directory.
        wait (bool, optional): Whether to block until the call finishes.
        quiet (bool, optional): Whether to print out the output stream (if any)
            and error stream (if error occured).

    Returns:
        tuple:
            - **retcode** (*int*) -- Command exit code. 0 means a successful
              call. Always ``None`` if not waiting for the command to finish.
            - **stdout** (*str*) -- Standard output stream. Always ``None`` if
              not waiting.
            - **stderr** (*str*) -- Standard error stream. Always ``None`` if
              not waiting.
    """

    process = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=cwd, shell=True)

    if not wait:
        return None, None, None

    stdout, stderr = process.communicate() # waits for completion
    stdout, stderr = stdout.decode(), stderr.decode()

    if not quiet:
        if stdout != '':
            format_print(stdout, 'O')
        if process.returncode != 0:
            if stderr != '':

# Path: third_party/xiuminglib/xiuminglib/log.py
# def get_logger(level=None):
#     """Creates a logger for functions in the library.
# 
#     Args:
#         level (str, optional): Logging level. Defaults to ``logging.INFO``.
# 
#     Returns:
#         logging.Logger: Logger created.
#     """
#     if level is None:
#         level = logging.INFO
#     logging.basicConfig(level=level)
#     logger = logging.getLogger()
#     return logger
# 
# Path: third_party/xiuminglib/xiuminglib/imprt.py
# def preset_import(name, assert_success=False):
#     """A unified importer for both regular and ``google3`` modules, according
#     to specified presets/profiles (e.g., ignoring ``ModuleNotFoundError``).
#     """
#     if name in ('cv2', 'opencv'):
#         try:
#             # BUILD dep:
#             # "//third_party/py/cvx2",
#             from cvx2 import latest as mod
#             # Or
#             # BUILD dep:
#             # "//third_party/OpenCVX:cvx2",
#             # from google3.third_party.OpenCVX import cvx2 as cv2
#         except ModuleNotFoundError:
#             mod = import_module_404ok('cv2')
# 
#     elif name in ('tf', 'tensorflow'):
#         mod = import_module_404ok('tensorflow')
# 
#     elif name == 'gfile':
#         # BUILD deps:
#         # "//pyglib:gfile",
#         # "//file/colossus/cns",
#         mod = import_module_404ok('google3.pyglib.gfile')
# 
#     elif name == 'video_api':
#         # BUILD deps:
#         # "//learning/deepmind/video/python:video_api",
#         mod = import_module_404ok(
#             'google3.learning.deepmind.video.python.video_api')
# 
#     elif name in ('bpy', 'bmesh', 'OpenEXR', 'Imath'):
#         # BUILD deps:
#         # "//third_party/py/Imath",
#         # "//third_party/py/OpenEXR",
#         mod = import_module_404ok(name)
# 
#     elif name in ('Vector', 'Matrix', 'Quaternion'):
#         mod = import_module_404ok('mathutils')
#         mod = _get_module_class(mod, name)
# 
#     elif name == 'BVHTree':
#         mod = import_module_404ok('mathutils.bvhtree')
#         mod = _get_module_class(mod, name)
# 
#     else:
#         raise NotImplementedError(name)
# 
#     if assert_success:
#         assert mod is not None, "Failed in importing '%s'" % name
# 
#     return mod
# 
# Path: third_party/xiuminglib/xiuminglib/interact.py
# def format_print(msg, fmt):
#     """Prints a message with format.
# 
#     Args:
#         msg (str): Message to print.
#         fmt (str): Format; try your luck with any value -- don't worry; if
#             it's illegal, you will be prompted with all legal values.
#     """
#     fmt_strs = {
#         'header': '\033[95m',
#         'okblue': '\033[94m',
#         'okgreen': '\033[92m',
#         'warn': '\033[93m',
#         'fail': '\033[91m',
#         'bold': '\033[1m',
#         'underline': '\033[4m',
#     }
#     if fmt in fmt_strs.keys():
#         start_str = fmt_strs[fmt]
#         end_str = '\033[0m'
#     elif len(fmt) == 1:
#         start_str = "\n<" + "".join([fmt] * 78) + '\n\n' # as per PEP8
#         end_str = '\n' + start_str[2:-2] + ">\n"
#     else:
#         raise ValueError(
#             ("Legal values for fmt: %s, plus any single character "
#              "(which will be repeated into the line separator), "
#              "but input is '%s'") % (list(fmt_strs.keys()), fmt))
#     print(start_str + msg + end_str)


# Path: third_party/xiuminglib/xiuminglib/os.py
import os
from os.path import join, exists, isdir, dirname
from shutil import rmtree, copy2, copytree
from glob import glob
from .log import get_logger
from .imprt import preset_import
from .interact import format_print
    from collections import OrderedDict
    from json import dump
    from shlex import split
    from subprocess import Popen, DEVNULL
    from subprocess import Popen, PIPE

        cmd (str): Command to be executed.
        cwd (str, optional): Directory to execute the command in. ``None``
            means current directory.
        wait (bool, optional): Whether to block until the call finishes.
        quiet (bool, optional): Whether to print out the output stream (if any)
            and error stream (if error occured).

    Returns:
        tuple:
            - **retcode** (*int*) -- Command exit code. 0 means a successful
              call. Always ``None`` if not waiting for the command to finish.
            - **stdout** (*str*) -- Standard output stream. Always ``None`` if
              not waiting.
            - **stderr** (*str*) -- Standard error stream. Always ``None`` if
              not waiting.
    """

    process = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=cwd, shell=True)

    if not wait:
        return None, None, None

    stdout, stderr = process.communicate() # waits for completion
    stdout, stderr = stdout.decode(), stderr.decode()

    if not quiet:
        if stdout != '':
            format_print(stdout, 'O')
        if process.returncode != 0:
            if stderr != '':

                format_print(stderr, 'E')