WIP selective state sync
This commit is contained in:
parent
53da59c06e
commit
714bf79d22
@ -144,7 +144,7 @@ class PersistedState(State):
|
||||
return to_state
|
||||
|
||||
|
||||
def sync(self, state=None):
|
||||
def sync(self, state=None, not_state=None):
|
||||
"""Reload resources for a single state in memory from the persisted state store.
|
||||
|
||||
:param state: State to load
|
||||
@ -153,11 +153,17 @@ class PersistedState(State):
|
||||
# :todo: if sync state is none, sync all
|
||||
"""
|
||||
|
||||
states = []
|
||||
states_numeric = []
|
||||
if state == None:
|
||||
states = list(self.all())
|
||||
states_numeric = list(self.all(numeric=True))
|
||||
else:
|
||||
states = [self.name(state)]
|
||||
#states = [self.name(state)]
|
||||
states_numeric = [state]
|
||||
|
||||
states = []
|
||||
for state in states_numeric:
|
||||
if not_state != None and state & not_state == 0:
|
||||
states.append(self.name(state))
|
||||
|
||||
ks = []
|
||||
for k in states:
|
||||
|
@ -217,14 +217,15 @@ class State:
|
||||
return self.__alias(k, *args)
|
||||
|
||||
|
||||
def all(self, pure=False):
|
||||
"""Return list of all unique atomic and alias states.
|
||||
def all(self, pure=False, numeric=False):
|
||||
"""Return list of all unique atomic and alias state strings.
|
||||
|
||||
:rtype: list of ints
|
||||
:return: states
|
||||
"""
|
||||
l = []
|
||||
for k in dir(self):
|
||||
state = None
|
||||
if k[0] == '_':
|
||||
continue
|
||||
if k.upper() != k:
|
||||
@ -233,7 +234,12 @@ class State:
|
||||
state = self.from_name(k)
|
||||
if not self.__is_pure(state):
|
||||
continue
|
||||
l.append(k)
|
||||
if numeric:
|
||||
if state == None:
|
||||
state = self.from_name(k)
|
||||
l.append(state)
|
||||
else:
|
||||
l.append(k)
|
||||
l.sort()
|
||||
return l
|
||||
|
||||
@ -628,3 +634,25 @@ class State:
|
||||
statemask = ~statemask
|
||||
statemask &= self.__limit
|
||||
return statemask
|
||||
|
||||
|
||||
def purge(self, key):
|
||||
state = self.state(key)
|
||||
state_name = self.name(state)
|
||||
|
||||
import sys
|
||||
sys.stderr.write('foo {} {}'.format(state_name, self.__keys))
|
||||
v = self.__keys.get(state)
|
||||
v.remove(key)
|
||||
|
||||
del self.__keys_reverse[key]
|
||||
|
||||
try:
|
||||
del self.__contents[key]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
del self.modified_last[key]
|
||||
except KeyError:
|
||||
pass
|
||||
|
@ -7,6 +7,7 @@ from shep import State
|
||||
from shep.error import (
|
||||
StateExists,
|
||||
StateInvalid,
|
||||
StateItemNotFound,
|
||||
)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@ -250,5 +251,24 @@ class TestState(unittest.TestCase):
|
||||
self.assertEqual(mask, states.ALL)
|
||||
|
||||
|
||||
def test_remove(self):
|
||||
states = State(1)
|
||||
states.add('foo')
|
||||
|
||||
states.put('xyzzy', contents='plugh')
|
||||
v = states.get('xyzzy')
|
||||
self.assertEqual(v, 'plugh')
|
||||
|
||||
states.next('xyzzy')
|
||||
|
||||
v = states.state('xyzzy')
|
||||
self.assertEqual(states.FOO, v)
|
||||
|
||||
states.purge('xyzzy')
|
||||
|
||||
with self.assertRaises(StateItemNotFound):
|
||||
states.state('xyzzy')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user