# Path: pyroSAR/_dev_config.py
# __LOCAL__ = ['sensor', 'projection', 'orbit', 'polarizations', 'acquisition_mode',
#              'start', 'stop', 'product', 'spacing', 'samples', 'lines']
# LOOKUP = Storage(attributes={'sensor': 'TEXT',
#                              'orbit': 'TEXT',
#                              'acquisition_mode': 'TEXT',
#                              'start': 'TEXT',
#                              'stop': 'TEXT',
#                              'product': 'TEXT',
#                              'samples': 'INTEGER',
#                              'lines': 'INTEGER',
#                              'outname_base': 'TEXT PRIMARY KEY',
#                              'scene': 'TEXT',
#                              'hh': 'INTEGER',
#                              'vv': 'INTEGER',
#                              'hv': 'INTEGER',
#                              'vh': 'INTEGER'})
# URL = Storage(dem=dem,
#               orbit=orbit,
#               auxcal=auxcal)
# STORAGE = Storage(URL=URL,
#                   LOOKUP=LOOKUP)
# class Storage(dict):
# class Singleton(type):
# class ConfigHandler(metaclass=Singleton):
#     def __getattr__(self, name):
#     def __repr__(self):
#     def __dir__(self):
#     def __init__(cls, name, bases, attrs, **kwargs):
#     def __call__(cls, *args, **kwargs):
#     def __init__(self):
#     def __create_config(self):
#     def __str__(self):
#     def __getitem__(self, section):
#     def sections(self):
#     def keys(self, section):
#     def open(self):
#     def add_section(self, section):
#     def file(self):
#     def set(self, section, key, value, overwrite=False):
#     def remove_option(self, section, key):
#     def remove_section(self, section):
#     def write(self):


import os
import re
import inspect
from math import sin, radians
from datetime import datetime
from ._dev_config import product_pattern
from spatialist.ancillary import finder
    return out


def find_datasets(directory, recursive=False, **kwargs):
    """
    find pyroSAR datasets in a directory based on their metadata
    
    Parameters
    ----------
    directory: str
        the name of the directory to be searched
    recursive: bool
        search the directory recursively into subdirectories?
    kwargs:
        Metadata attributes for filtering the scene list supplied as `key=value`. e.g. `sensor='S1A'`.
        Multiple allowed options can be provided in tuples, e.g. `sensor=('S1A', 'S1B')`.
        Any types other than tuples require an exact match, e.g. `proc_steps=['grd', 'mli', 'geo', 'norm', 'db']`
        will be matched only if these processing steps are contained in the product name in this exact order.
        The special attributes `start` and `stop` can be used for time filtering where `start<=value<=stop`.
        See function :func:`parse_datasetname` for further options.
    
    Returns
    -------
    list of str
        the file names found in the directory and filtered by metadata attributes
    
    Examples
    --------
    >>> selection = find_datasets('path/to/files', sensor=('S1A', 'S1B'), polarization='VV')
    """

# Path: pyroSAR/_dev_config.py
# __LOCAL__ = ['sensor', 'projection', 'orbit', 'polarizations', 'acquisition_mode',
#              'start', 'stop', 'product', 'spacing', 'samples', 'lines']
# LOOKUP = Storage(attributes={'sensor': 'TEXT',
#                              'orbit': 'TEXT',
#                              'acquisition_mode': 'TEXT',
#                              'start': 'TEXT',
#                              'stop': 'TEXT',
#                              'product': 'TEXT',
#                              'samples': 'INTEGER',
#                              'lines': 'INTEGER',
#                              'outname_base': 'TEXT PRIMARY KEY',
#                              'scene': 'TEXT',
#                              'hh': 'INTEGER',
#                              'vv': 'INTEGER',
#                              'hv': 'INTEGER',
#                              'vh': 'INTEGER'})
# URL = Storage(dem=dem,
#               orbit=orbit,
#               auxcal=auxcal)
# STORAGE = Storage(URL=URL,
#                   LOOKUP=LOOKUP)
# class Storage(dict):
# class Singleton(type):
# class ConfigHandler(metaclass=Singleton):
#     def __getattr__(self, name):
#     def __repr__(self):
#     def __dir__(self):
#     def __init__(cls, name, bases, attrs, **kwargs):
#     def __call__(cls, *args, **kwargs):
#     def __init__(self):
#     def __create_config(self):
#     def __str__(self):
#     def __getitem__(self, section):
#     def sections(self):
#     def keys(self, section):
#     def open(self):
#     def add_section(self, section):
#     def file(self):
#     def set(self, section, key, value, overwrite=False):
#     def remove_option(self, section, key):
#     def remove_section(self, section):
#     def write(self):


# Path: pyroSAR/ancillary.py
import os
import re
import inspect
from math import sin, radians
from datetime import datetime
from ._dev_config import product_pattern
from spatialist.ancillary import finder

    return out


def find_datasets(directory, recursive=False, **kwargs):
    """
    find pyroSAR datasets in a directory based on their metadata
    
    Parameters
    ----------
    directory: str
        the name of the directory to be searched
    recursive: bool
        search the directory recursively into subdirectories?
    kwargs:
        Metadata attributes for filtering the scene list supplied as `key=value`. e.g. `sensor='S1A'`.
        Multiple allowed options can be provided in tuples, e.g. `sensor=('S1A', 'S1B')`.
        Any types other than tuples require an exact match, e.g. `proc_steps=['grd', 'mli', 'geo', 'norm', 'db']`
        will be matched only if these processing steps are contained in the product name in this exact order.
        The special attributes `start` and `stop` can be used for time filtering where `start<=value<=stop`.
        See function :func:`parse_datasetname` for further options.
    
    Returns
    -------
    list of str
        the file names found in the directory and filtered by metadata attributes
    
    Examples
    --------
    >>> selection = find_datasets('path/to/files', sensor=('S1A', 'S1B'), polarization='VV')
    """

    files = finder(directory, [product_pattern], regex=True, recursive=recursive)