/
writers.py
55 lines (41 loc) · 1.5 KB
/
writers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This file is part of the Open Data Cube, see https://opendatacube.org for more information
#
# Copyright (c) 2015-2024 ODC Contributors
# SPDX-License-Identifier: Apache-2.0
from typing import List
from ._tools import singleton_setup
from .driver_cache import load_drivers
class WriterDriverCache(object):
def __init__(self, group: str):
self._drivers = load_drivers(group)
for driver in list(self._drivers.values()):
if hasattr(driver, 'aliases'):
for alias in driver.aliases:
self._drivers[alias] = driver
def __call__(self, name: str):
"""
:returns: None if driver with a given name is not found
:param name: Driver name
:return: Returns WriterDriver
"""
return self._drivers.get(name, None)
def drivers(self) -> List[str]:
""" Returns list of driver names
"""
return list(self._drivers.keys())
def writer_cache() -> WriterDriverCache:
""" Singleton for WriterDriverCache
"""
return singleton_setup(writer_cache, '_instance',
WriterDriverCache,
'datacube.plugins.io.write')
def writer_drivers() -> List[str]:
""" Returns list driver names
"""
return writer_cache().drivers()
def storage_writer_by_name(name):
""" Lookup writer driver by name
:returns: Initialised writer driver instance
:returns: None if driver with this name doesn't exist
"""
return writer_cache()(name)