shep

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

commit d68286ee6ca7366ba80fa7af95198016369ea9bb
parent b92a4e64583002a13ad9d30e7c21f7a0a5f49546
Author: lash <dev@holbrook.no>
Date:   Sun, 13 Mar 2022 16:36:17 +0000

Add modify dates handler

Diffstat:
Mshep/state.py | 14++++++++++++++
Mshep/store/file.py | 10++++++++++
Mtests/test_state.py | 16++++++++++++++++
3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/shep/state.py b/shep/state.py @@ -1,5 +1,6 @@ # standard imports import re +import datetime # local imports from shep.error import ( @@ -39,6 +40,7 @@ class State: self.__keys = {getattr(self, self.base_state_name): []} self.__keys_reverse = {} self.__contents = {} + self.__change = {} self.verifier = verifier @@ -302,6 +304,8 @@ class State: if contents != None: self.__contents[key] = contents + self.register_modify(key) + return state @@ -348,6 +352,8 @@ class State: current_state_list.pop(idx) self.__add_state_list(to_state, key) + self.register_modify(key) + return to_state @@ -549,3 +555,11 @@ class State: """ self.state(key) self.__contents[key] = contents + + + def modified(self, key): + return self.__change[key] + + + def register_modify(self, key): + self.__change[key] = datetime.datetime.now().timestamp() diff --git a/shep/store/file.py b/shep/store/file.py @@ -103,6 +103,16 @@ class SimpleFileStore: f.close() + def modified(self, k): + path = self.path(k) + st = os.stat(path) + return float(st.st_ctime()) + + + def register_modify(self, k): + pass + + class SimpleFileStoreFactory: """Provide a method to instantiate SimpleFileStore instances that provide persistence for individual states. diff --git a/tests/test_state.py b/tests/test_state.py @@ -136,5 +136,21 @@ class TestState(unittest.TestCase): self.assertEqual(states.state('abcd'), states.FOO) + def test_change_dates(self): + states = State(3) + states.add('foo') + states.put('abcd') + states.put('bcde') + + a = states.modified('abcd') + b = states.modified('bcde') + self.assertGreater(b, a) + + states.set('abcd', states.FOO) + a = states.modified('abcd') + b = states.modified('bcde') + self.assertGreater(a, b) + + if __name__ == '__main__': unittest.main()