import logging
import re


def get_table_list_file_tables(table_list_file):
    """
    Reads a "table list file" to get a list if tables to limit to.
    Returns a list of table names.
    """

    result_tables = []

    # Read the file - each line is the tablename

    try:
        fh = open(table_list_file, "r")
    except Exception as e:
        logging.info("Failed to open table list file '%s': %s", table_list_file, e)
        return

    for line in fh:

        # Skip comments
        m = re.match(r'\s*#', line)
        if m: continue
        
        # Skip blank lines
        m = re.match(r'\s*$', line)
        if m: continue

        # Remove newlines at the end.
        line = line.rstrip("\r\n")

        result_tables.append(line)

    fh.close()

    return result_tables