import logging

from collections import OrderedDict
from egpackager.datasources import GspreadDataSource, RasterDataSource


class DataManager(object):

    def __init__(self, debug=False):
        # Set up logging
        if debug:
            logging.basicConfig(level=logging.DEBUG)
        else:
            logging.basicConfig(level=logging.INFO)
        self.logger = logging.getLogger(__name__)

        self.logger.debug("Initializing new registry manager")
        self._data = OrderedDict()

    def add_datasource(self, *args, **kwargs):
        if 'type' not in kwargs:
            raise TypeError("Missing require keyword argument: 'type")

        if kwargs['type'] == 'gspread':
            # Remove keyword argument 'type' as it us not needed anymore
            del kwargs['type']
            self.logger.debug('Adding Google Sheets data source')
            self._data['metadata'] = GspreadDataSource(*args, **kwargs)
        elif kwargs['type'] == 'raster':
            del kwargs['type']
            self.logger.debug('Adding raster data source')
            self._data['resource'] = RasterDataSource(*args, **kwargs)
        else:
            raise TypeError("Unknown data source type: {0}".format(kwargs['type']))
        self._data['uri'] = kwargs['uri']

    @property
    def data(self):
        return self._data

    def get_metadata_value(self, key, value):
        return self.data['metadata'].get_value(key, value)

    def get_resource_value(self, key, value):
        return self.data['resource'].get_value(key, value)

    @property
    def metadata(self):
        return self.data['metadata'].data

    @property
    def resource_metadata(self):
        return self.data['resource'].data

@@ -1329,24 +1329,574 @@
 self._data%0A%0A
+    def find_name(self, resource_name):%0A        %22%22%22%0A        Simple method to find out the name of the dataset based on a resource name (essentially raster file name).%0A%0A        If no match is found, return a None.%0A%0A        :param resource_name: String raster file name as stated in the data source.%0A        :return: String name of the dataset.%0A        %22%22%22%0A        name = None%0A        for item in self.data%5B'metadata'%5D.data.items():%0A            if item%5B1%5D%5B'resource_name'%5D == resource_name:%0A                name = item%5B1%5D%5B'name'%5D%0A        return name%0A%0A%0A
     def get_

Implement find_name()