# 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
    Supports Google Colossus, by using ``gfile`` (preferred for speed)
    or the ``fileutil`` CLI when Blaze is not used (hence, ``gfile``
    unavailable).

    Args:
        directory (str): Directory to glob, e.g., ``'/path/to/'``.
        filename (str or tuple(str), optional): Filename pattern excluding
            extensions, e.g., ``'img*'``.
        ext (str or tuple(str), optional): Extensions of interest, e.g.,
            ``('png', 'jpg')``. ``None`` means no extension, useful for
            folders or files with no extension.
        ext_ignore_case (bool, optional): Whether to ignore case for
            extensions.

    Returns:
        list(str): Sorted list of files globbed.
    """
    def glob_cns_cli(pattern):
        cmd = 'fileutil ls -d %s' % pattern # -d to avoid recursively
        _, stdout, _ = call(cmd, quiet=True)
        return [x for x in stdout.split('\n') if x != '']

    def glob_bs_cli(pattern):
        cmd = '/google/data/ro/projects/cloud/bigstore/fileutil_bs ls -d %s' \
            % pattern # -d to avoid recursively
        _, stdout, _ = call(cmd, quiet=True)
        return [x for x in stdout.split('\n') if x != '']

    if _is_cnspath(directory):
        # Is a CNS path

# 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

    Supports Google Colossus, by using ``gfile`` (preferred for speed)
    or the ``fileutil`` CLI when Blaze is not used (hence, ``gfile``
    unavailable).

    Args:
        directory (str): Directory to glob, e.g., ``'/path/to/'``.
        filename (str or tuple(str), optional): Filename pattern excluding
            extensions, e.g., ``'img*'``.
        ext (str or tuple(str), optional): Extensions of interest, e.g.,
            ``('png', 'jpg')``. ``None`` means no extension, useful for
            folders or files with no extension.
        ext_ignore_case (bool, optional): Whether to ignore case for
            extensions.

    Returns:
        list(str): Sorted list of files globbed.
    """
    def glob_cns_cli(pattern):
        cmd = 'fileutil ls -d %s' % pattern # -d to avoid recursively
        _, stdout, _ = call(cmd, quiet=True)
        return [x for x in stdout.split('\n') if x != '']

    def glob_bs_cli(pattern):
        cmd = '/google/data/ro/projects/cloud/bigstore/fileutil_bs ls -d %s' \
            % pattern # -d to avoid recursively
        _, stdout, _ = call(cmd, quiet=True)
        return [x for x in stdout.split('\n') if x != '']

    if _is_cnspath(directory):
        # Is a CNS path

        gfile = preset_import('gfile', assert_success=True)