# Path: pyani/pyani_tools.py
# def termcolor(
#     logstr: str, color: Optional[str] = None, bold: Optional[bool] = False
# ) -> str:
#     """Return the passed logstr, wrapped in terminal colouring."""
#     # For terminal colouring
#     termcolors = {
#         "BLACK": 0,
#         "RED": 1,
#         "GREEN": 2,
#         "YELLOW": 3,
#         "BLUE": 4,
#         "MAGENTA": 5,
#         "CYAN": 6,
#         "WHITE": 7,
#     }
#     reset = "\033[0m"
# 
#     # Colour the string
#     if isinstance(color, str) and color.upper() in termcolors:
#         logstr = f"\033[1;{30 + termcolors[color.upper()]}m{logstr}{reset}"
# 
#     # Make the string bold
#     if bold is True:
#         logstr = f"\033[1m{logstr}"
#         if not logstr.endswith(reset):
#             logstr += reset
# 
#     return logstr


import hashlib
import logging
import re
import shlex
import subprocess
import os
import sys
import traceback
import urllib.request
from namedlist import namedlist
from pathlib import Path
from subprocess import CompletedProcess
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
from urllib.error import HTTPError, URLError
from Bio import Entrez  # type: ignore
from tqdm import tqdm  # type: ignore
from pyani.pyani_tools import termcolor
    robust regex replace/escape may be required. Sadly, NCBI don't just
    use standard percent escapes, but instead replace certain
    characters with underscores: white space, slash, comma, hash, brackets.
    """
    escapes = re.compile(r"[\s/,#\(\)]")
    escname = re.sub(escapes, "_", esummary["AssemblyName"])
    return "_".join([esummary["AssemblyAccession"], escname])


# Get eSummary data for a single assembly UID
def get_ncbi_esummary(asm_uid, retries, api_key=None) -> Tuple:
    """Obtain full eSummary info for the passed assembly UID.

    :param asm_uid:
    :param retries:
    :param api_key:
    """
    logger = logging.getLogger(__name__)

    # Obtain full eSummary data for the assembly
    summary = entrez_esummary(
        retries=retries, db="assembly", id=asm_uid, report="full", api_key=api_key
    )

    # Extract filestem from assembly data
    try:
        data = summary["DocumentSummarySet"]["DocumentSummary"][0]
    except (IndexError, KeyError):
        # Something has gone awry with the download
        logger.warning(

# Path: pyani/pyani_tools.py
# def termcolor(
#     logstr: str, color: Optional[str] = None, bold: Optional[bool] = False
# ) -> str:
#     """Return the passed logstr, wrapped in terminal colouring."""
#     # For terminal colouring
#     termcolors = {
#         "BLACK": 0,
#         "RED": 1,
#         "GREEN": 2,
#         "YELLOW": 3,
#         "BLUE": 4,
#         "MAGENTA": 5,
#         "CYAN": 6,
#         "WHITE": 7,
#     }
#     reset = "\033[0m"
# 
#     # Colour the string
#     if isinstance(color, str) and color.upper() in termcolors:
#         logstr = f"\033[1;{30 + termcolors[color.upper()]}m{logstr}{reset}"
# 
#     # Make the string bold
#     if bold is True:
#         logstr = f"\033[1m{logstr}"
#         if not logstr.endswith(reset):
#             logstr += reset
# 
#     return logstr


# Path: pyani/download.py
import hashlib
import logging
import re
import shlex
import subprocess
import os
import sys
import traceback
import urllib.request
from namedlist import namedlist
from pathlib import Path
from subprocess import CompletedProcess
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
from urllib.error import HTTPError, URLError
from Bio import Entrez  # type: ignore
from tqdm import tqdm  # type: ignore
from pyani.pyani_tools import termcolor

    robust regex replace/escape may be required. Sadly, NCBI don't just
    use standard percent escapes, but instead replace certain
    characters with underscores: white space, slash, comma, hash, brackets.
    """
    escapes = re.compile(r"[\s/,#\(\)]")
    escname = re.sub(escapes, "_", esummary["AssemblyName"])
    return "_".join([esummary["AssemblyAccession"], escname])


# Get eSummary data for a single assembly UID
def get_ncbi_esummary(asm_uid, retries, api_key=None) -> Tuple:
    """Obtain full eSummary info for the passed assembly UID.

    :param asm_uid:
    :param retries:
    :param api_key:
    """
    logger = logging.getLogger(__name__)

    # Obtain full eSummary data for the assembly
    summary = entrez_esummary(
        retries=retries, db="assembly", id=asm_uid, report="full", api_key=api_key
    )

    # Extract filestem from assembly data
    try:
        data = summary["DocumentSummarySet"]["DocumentSummary"][0]
    except (IndexError, KeyError):
        # Something has gone awry with the download
        logger.warning(

            termcolor("Could not get eSummary for UID %s", "red"),