# Path: third_party/xiuminglib/xiuminglib/os.py
# def makedirs(directory, rm_if_exists=False):
#     """Wraps :func:`os.makedirs` to support removing the directory if it
#     alread exists.
# 
#     Google Colossus-compatible: it tries to use ``gfile`` first for speed. This
#     will fail if Blaze is not used, in which case it then falls back to using
#     ``fileutil`` CLI as external process calls.
# 
#     Args:
#         directory (str)
#         rm_if_exists (bool, optional): Whether to remove the directory (and
#             its contents) if it already exists.
#     """
#     def exists_cns_cli(directory):
#         cmd = 'fileutil test -d %s' % directory
#         retcode, _, _ = call(cmd, quiet=True)
#         if retcode == 0:
#             return True
#         if retcode == 1:
#             return False
#         raise ValueError(retcode)
# 
#     def mkdir_cns_cli(directory):
#         cmd = 'fileutil mkdir -p %s' % directory
#         _call_assert_success(cmd, quiet=True)
# 
#     if _is_cnspath(directory):
#         # Is a CNS path
#         gfile = preset_import('gfile')
#         if gfile is None:
#             exists_func = exists_cns_cli
#             mkdir_func = mkdir_cns_cli
#         else:
#             exists_func = gfile.Exists
#             mkdir_func = gfile.MakeDirs
#     else:
#         # Is just a regular local path
#         exists_func = exists
#         mkdir_func = os.makedirs
# 
#     # Do the job
#     if exists_func(directory):
#         if rm_if_exists:
#             rm(directory)
#             mkdir_func(directory)
#             logger.info("Removed and then remade:\n\t%s", directory)
#     else:
#         mkdir_func(directory)


from os.path import dirname
from ..os import makedirs
            :class:`xiuminglib.vis.html.Table`: Table added.
        """
        table = Table(header=header, width=width, border=border)
        if name is None:
            i = 0
            while True:
                name = 'table%d' % i
                if name not in self.children:
                    break
                i += 1
        else:
            assert name not in self.children, \
                "A child already took the name '%s'" % name
        self.children[name] = table
        return table

    def save(self, index_file):
        """Saves the generated HTML string to the index file.

        Once called, this method also calls all children's :func:`close`,
        so that everything (e.g., a table) is properly closed.

        Args:
            index_file (str): Path to the generated index.html.

        Writes
            - An HTML index file.
        """
        if not index_file.endswith('.html'):
            index_file += '.html'

# Path: third_party/xiuminglib/xiuminglib/os.py
# def makedirs(directory, rm_if_exists=False):
#     """Wraps :func:`os.makedirs` to support removing the directory if it
#     alread exists.
# 
#     Google Colossus-compatible: it tries to use ``gfile`` first for speed. This
#     will fail if Blaze is not used, in which case it then falls back to using
#     ``fileutil`` CLI as external process calls.
# 
#     Args:
#         directory (str)
#         rm_if_exists (bool, optional): Whether to remove the directory (and
#             its contents) if it already exists.
#     """
#     def exists_cns_cli(directory):
#         cmd = 'fileutil test -d %s' % directory
#         retcode, _, _ = call(cmd, quiet=True)
#         if retcode == 0:
#             return True
#         if retcode == 1:
#             return False
#         raise ValueError(retcode)
# 
#     def mkdir_cns_cli(directory):
#         cmd = 'fileutil mkdir -p %s' % directory
#         _call_assert_success(cmd, quiet=True)
# 
#     if _is_cnspath(directory):
#         # Is a CNS path
#         gfile = preset_import('gfile')
#         if gfile is None:
#             exists_func = exists_cns_cli
#             mkdir_func = mkdir_cns_cli
#         else:
#             exists_func = gfile.Exists
#             mkdir_func = gfile.MakeDirs
#     else:
#         # Is just a regular local path
#         exists_func = exists
#         mkdir_func = os.makedirs
# 
#     # Do the job
#     if exists_func(directory):
#         if rm_if_exists:
#             rm(directory)
#             mkdir_func(directory)
#             logger.info("Removed and then remade:\n\t%s", directory)
#     else:
#         mkdir_func(directory)


# Path: third_party/xiuminglib/xiuminglib/vis/html.py
from os.path import dirname
from ..os import makedirs

            :class:`xiuminglib.vis.html.Table`: Table added.
        """
        table = Table(header=header, width=width, border=border)
        if name is None:
            i = 0
            while True:
                name = 'table%d' % i
                if name not in self.children:
                    break
                i += 1
        else:
            assert name not in self.children, \
                "A child already took the name '%s'" % name
        self.children[name] = table
        return table

    def save(self, index_file):
        """Saves the generated HTML string to the index file.

        Once called, this method also calls all children's :func:`close`,
        so that everything (e.g., a table) is properly closed.

        Args:
            index_file (str): Path to the generated index.html.

        Writes
            - An HTML index file.
        """
        if not index_file.endswith('.html'):
            index_file += '.html'

        makedirs(dirname(index_file))