4
0
mirror of git://holbrook.no/eth-monitor.git synced 2024-11-27 05:36:46 +01:00
eth-monitor/eth_monitor/cache.py

34 lines
764 B
Python
Raw Normal View History

# standard imports
import logging
from urllib.parse import urlparse
logg = logging.getLogger(__name__)
def from_cache_spec(chain_spec, s):
o = urlparse(s)
path = '.'
scheme = None
if o.scheme == '':
scheme = 'file'
else:
scheme = o.scheme
if o.path != '':
if o.path[0] != '/':
path = os.path.join(path, o.path)
else:
path = o.path
logg.debug('parsed scheme {} from cache spec'.format(scheme))
if scheme == 'file':
from eth_cache.store.fs import FileStore
return FsStore(chain_spec, cache_root=path)
if scheme == 'lmdb':
from eth_cache.store.lmdb import LmdbStore
return LmdbStore(chain_spec, cache_root=path)
return None