from pathlib import Path


def queryS2(file):
    """Read an input product list returning the full-path product list suitable for reading datasets.

    Parameters:
        file (str): full-path of the input file listing target products

    Return: S5P L2 full-path to files (list)
    """
    with open(file,"r") as f:
        data = f.readlines()
        list = [d.split("\n")[0] for d in data]
    products = []
    for item in list:
        if item.endswith('.zip') or item.endswith('.SAFE') :
            products.append(item)
        else:
            for file in Path(item).rglob('*.zip') or Path(item).rglob('*.SAFE') :
                products.append(str(file))
    return products