Filter list persistencE
This commit is contained in:
parent
384c79bed0
commit
ca82ea247f
@ -141,3 +141,12 @@ class SyncDriver:
|
||||
|
||||
def get(self, conn):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def save_filter_list(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def load_filter_list(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -58,19 +58,12 @@ def main():
|
||||
state_dir = config.get('_STATE_DIR')
|
||||
|
||||
factory = syncer_store_class(state_dir)
|
||||
store = SyncStore(state_dir, no_session=True)
|
||||
#base_state = PersistedState(factory.add, 0, check_alias=False)
|
||||
#state = FilterState(base_state, scan=True)
|
||||
store = SyncStore(state_dir)
|
||||
store.setup_filter_state(factory=factory)
|
||||
store.connect()
|
||||
store.filter_state.scan()
|
||||
locked_state = store.filter_state.list(store.filter_state.from_name('RESET'))
|
||||
print(locked_state)
|
||||
# if locked_state == None:
|
||||
# sys.stderr.write('state in {} backend "{}" is not locked\n'.format(state_dir, config.get('SYNCER_BACKEND')))
|
||||
# sys.exit(1)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -196,6 +196,8 @@ class SyncStore:
|
||||
if self.started:
|
||||
return
|
||||
|
||||
self.save_filter_list()
|
||||
|
||||
self.load(target)
|
||||
|
||||
if self.first:
|
||||
|
@ -74,3 +74,25 @@ class SyncFsStore(SyncStore):
|
||||
f.write(str(v))
|
||||
f.close()
|
||||
self.target = v
|
||||
|
||||
|
||||
def load_filter_list(self):
|
||||
fltr = []
|
||||
fp = os.path.join(self.session_path, 'filter_list')
|
||||
f = open(fp, 'r')
|
||||
while True:
|
||||
v = f.readline()
|
||||
if len(v) == 0:
|
||||
break
|
||||
v = v.rstrip()
|
||||
fltr.append(v)
|
||||
f.close()
|
||||
return fltr
|
||||
|
||||
|
||||
def save_filter_list(self):
|
||||
fp = os.path.join(self.session_path, 'filter_list')
|
||||
f = open(fp, 'w')
|
||||
for fltr in self.filters:
|
||||
f.write(fltr.common_name() + '\n')
|
||||
f.close()
|
||||
|
@ -35,3 +35,11 @@ class SyncMemStore(SyncStore):
|
||||
if item != None:
|
||||
super(SyncMemStore, self).stop(item)
|
||||
logg.info('I am an in-memory only state store. I am shutting down now, so all state will now be discarded.')
|
||||
|
||||
|
||||
def save_filter_list(self):
|
||||
pass
|
||||
|
||||
|
||||
def load_filter_list(self):
|
||||
return []
|
||||
|
@ -64,3 +64,17 @@ class SyncRocksDbStore(SyncStore):
|
||||
if item != None:
|
||||
super(SyncRocksDbStore, self).stop(item)
|
||||
self.factory.close()
|
||||
|
||||
|
||||
def save_filter_list(self):
|
||||
fltr = []
|
||||
for v in self.filters:
|
||||
fltr.append(v.common_name())
|
||||
self.target_db.put('filter_list', ','.join(fltr))
|
||||
|
||||
|
||||
def load_filter_list(self):
|
||||
v = self.target_db.get('filter_list')
|
||||
v = v.decode('utf-8')
|
||||
return v.split(',')
|
||||
|
||||
|
@ -50,6 +50,7 @@ class TestStoreBase(unittest.TestCase):
|
||||
"default",
|
||||
"store_start",
|
||||
"store_resume",
|
||||
"filter_list",
|
||||
"sync_process_nofilter",
|
||||
"sync_process_onefilter",
|
||||
"sync_process_outoforder",
|
||||
@ -275,3 +276,26 @@ class TestStoreBase(unittest.TestCase):
|
||||
o.next(advance_block=True)
|
||||
with self.assertRaises(SyncDone):
|
||||
o.next(advance_block=True)
|
||||
|
||||
|
||||
def t_filter_list(self):
|
||||
bogus_item = MockItem(0, 0, 0, 0)
|
||||
store = self.store_factory()
|
||||
|
||||
if store.session_path == None:
|
||||
return
|
||||
|
||||
fltr_one = MockFilter('foo_bar')
|
||||
store.register(fltr_one)
|
||||
|
||||
fltr_two = MockFilter('bar_baz')
|
||||
store.register(fltr_two)
|
||||
|
||||
store.start()
|
||||
store.stop(bogus_item)
|
||||
|
||||
store = self.store_factory()
|
||||
r = store.load_filter_list()
|
||||
|
||||
self.assertEqual(r[0], 'foo_bar')
|
||||
self.assertEqual(r[1], 'bar_baz')
|
||||
|
Loading…
Reference in New Issue
Block a user