Rename add to put in persistent store backends

This commit is contained in:
lash 2022-04-20 14:24:02 +00:00
parent 5bcc6b6934
commit 14f4cb23ae
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 22 additions and 10 deletions

View File

@ -1,6 +1,6 @@
[metadata]
name = shep
version = 0.2.1a1
version = 0.2.1a2
description = Multi-state key stores using bit masks
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -39,7 +39,7 @@ class PersistedState(State):
k = self.name(to_state)
self.__ensure_store(k)
self.__stores[k].add(key, contents)
self.__stores[k].put(key, contents)
self.register_modify(key)
@ -57,7 +57,7 @@ class PersistedState(State):
self.__ensure_store(k_to)
contents = self.__stores[k_from].get(key)
self.__stores[k_to].add(key, contents)
self.__stores[k_to].put(key, contents)
self.__stores[k_from].remove(key)
self.sync(to_state)
@ -79,7 +79,7 @@ class PersistedState(State):
self.__ensure_store(k_to)
contents = self.__stores[k_from].get(key)
self.__stores[k_to].add(key, contents)
self.__stores[k_to].put(key, contents)
self.__stores[k_from].remove(key)
return to_state
@ -99,7 +99,7 @@ class PersistedState(State):
self.__ensure_store(k_to)
contents = self.__stores[k_from].get(key)
self.__stores[k_to].add(key, contents)
self.__stores[k_to].put(key, contents)
self.__stores[k_from].remove(key)
self.register_modify(key)
@ -125,7 +125,7 @@ class PersistedState(State):
self.__ensure_store(k_to)
contents = self.__stores[k_from].get(key)
self.__stores[k_to].add(key, contents)
self.__stores[k_to].put(key, contents)
self.__stores[k_from].remove(key)
self.register_modify(key)

View File

@ -1,5 +1,9 @@
# standard imports
import os
import re
# local imports
from .base import re_processedname
class SimpleFileStore:
@ -17,7 +21,7 @@ class SimpleFileStore:
self.__m = ['r', 'w']
def add(self, k, contents=None):
def put(self, k, contents=None):
"""Add a new key and optional contents
:param k: Content key to add
@ -142,3 +146,11 @@ class SimpleFileStoreFactory:
k = str(k)
store_path = os.path.join(self.__path, k)
return SimpleFileStore(store_path, binary=self.__binary)
def ls(self):
r = []
for v in os.listdir(self.__path):
if re.match(re_processedname, v):
r.append(v)
return r

View File

@ -28,7 +28,7 @@ class RedisStore:
return v.decode('utf-8')
def add(self, k, contents=b''):
def put(self, k, contents=b''):
if contents == None:
contents = b''
k = self.__to_path(k)

View File

@ -37,7 +37,7 @@ class RocksDbStore:
return v.decode('utf-8')
def add(self, k, contents=b''):
def put(self, k, contents=b''):
if contents == None:
contents = b''
else:

View File

@ -21,7 +21,7 @@ class MockStore:
self.for_state = 0
def add(self, k, contents=None):
def put(self, k, contents=None):
self.v[k] = contents