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] [metadata]
name = shep name = shep
version = 0.2.1a1 version = 0.2.1a2
description = Multi-state key stores using bit masks description = Multi-state key stores using bit masks
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

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

View File

@ -1,5 +1,9 @@
# standard imports # standard imports
import os import os
import re
# local imports
from .base import re_processedname
class SimpleFileStore: class SimpleFileStore:
@ -17,7 +21,7 @@ class SimpleFileStore:
self.__m = ['r', 'w'] self.__m = ['r', 'w']
def add(self, k, contents=None): def put(self, k, contents=None):
"""Add a new key and optional contents """Add a new key and optional contents
:param k: Content key to add :param k: Content key to add
@ -142,3 +146,11 @@ class SimpleFileStoreFactory:
k = str(k) k = str(k)
store_path = os.path.join(self.__path, k) store_path = os.path.join(self.__path, k)
return SimpleFileStore(store_path, binary=self.__binary) 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') return v.decode('utf-8')
def add(self, k, contents=b''): def put(self, k, contents=b''):
if contents == None: if contents == None:
contents = b'' contents = b''
k = self.__to_path(k) k = self.__to_path(k)

View File

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

View File

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