Closed nuest closed 3 years ago
I used dict where its key is the file format and value is the module.
I used another way to do it, but the issue isremaining open
.
I used a dictionary that holds file format as a key
and module as a value
. After file format is extracted is goes through a loop of all keys to get the suitable module to handle the file.
modulesSupported = {'geojson':handleGeojson, 'json':handleGeojson,'csv':handleCSV,
'shp':handleShapefile, 'dbf':handleShapefile, 'geotiff':handleGeotiff, 'tif':handleGeotiff}
# get the module that will be called (depending on the format of the file)
for key in modulesSupported.keys():
if key == fileFormat:
print(key)
usedModule = modulesSupported.get(key)
Get rid of the modulesSupported
object in https://github.com/o2r-project/geoextent/blob/master/geoextent/lib/extent.py#L12
As of now, there is an "if else" chain checking and selecting suitable handlers. The concept of a handler is great, but instead of a fixed chain, we should have a list of handlers, and each handler can decide if they "take" the format because they support it, or if they don't.
See a working example of such a mechanism here:
contentproviders
): https://github.com/jupyter/repo2docker/blob/master/repo2docker/app.py#L41True
in thedetect()
function.For this to work, we need a class
FormatHandler
, sketched here (roughly based onContentProvider
):Based on this abstract class, we can implement the respective handlers (pseudo code!):