shep

Multi-state key stores using bit masks for python3
git clone git://git.defalsify.org/shep.git
Log | Files | Refs | LICENSE

commit f00cb9564d10badbf60f24f856bd38316a449ace
parent d133832e7370e144eeedcee7cff707dba13d1e99
Author: lash <dev@holbrook.no>
Date:   Wed, 20 Apr 2022 15:24:32 +0000

Guarantee close on store factory close

Diffstat:
Ashep/store/base.py | 15+++++++++++++++
Mshep/store/file.py | 7+++++--
Mshep/store/redis.py | 5++++-
Mshep/store/rocksdb.py | 6+++++-
4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/shep/store/base.py b/shep/store/base.py @@ -0,0 +1,15 @@ +re_processedname = r'^_?[A-Z,\.]*$' + + +class StoreFactory: + + def __del__(self): + self.close() + + + def add(self, k): + raise NotImplementedError() + + + def close(self): + pass diff --git a/shep/store/file.py b/shep/store/file.py @@ -3,7 +3,10 @@ import os import re # local imports -from .base import re_processedname +from .base import ( + re_processedname, + StoreFactory, + ) class SimpleFileStore: @@ -124,7 +127,7 @@ class SimpleFileStore: pass -class SimpleFileStoreFactory: +class SimpleFileStoreFactory(StoreFactory): """Provide a method to instantiate SimpleFileStore instances that provide persistence for individual states. :param path: Filesystem path as base path for states diff --git a/shep/store/redis.py b/shep/store/redis.py @@ -4,6 +4,9 @@ import datetime # external imports import redis +# local imports +from .base import StoreFactory + class RedisStore: @@ -86,7 +89,7 @@ class RedisStore: self.redis.set(k) -class RedisStoreFactory: +class RedisStoreFactory(StoreFactory): def __init__(self, host='localhost', port=6379, db=0, binary=False): self.redis = redis.Redis(host=host, port=port, db=db) diff --git a/shep/store/rocksdb.py b/shep/store/rocksdb.py @@ -4,6 +4,10 @@ import datetime # external imports import rocksdb +# local imports +from .base import StoreFactory + + class RocksDbStore: def __init__(self, path, db, binary=False): @@ -109,7 +113,7 @@ class RocksDbStore: self.db.set(k) -class RocksDbStoreFactory: +class RocksDbStoreFactory(StoreFactory): def __init__(self, path, binary=False): self.db = rocksdb.DB(path, rocksdb.Options(create_if_missing=True))