Propagate save option when setting a roster backend.

This commit is contained in:
Lance Stout 2012-03-05 11:28:10 -08:00
parent 7b51c6f5cc
commit fdfe2cd64f
2 changed files with 8 additions and 4 deletions

View file

@ -95,19 +95,21 @@ class Roster(object):
if node not in self._rosters:
self._rosters[node] = RosterNode(self.xmpp, node, self.db)
def set_backend(self, db=None):
def set_backend(self, db=None, save=True):
"""
Set the datastore interface object for the roster.
Arguments:
db -- The new datastore interface.
save -- If True, save the existing state to the new
backend datastore. Defaults to True.
"""
self.db = db
existing_entries = set(self._rosters)
new_entries = set(self.db.entries(None, {}))
for node in existing_entries:
self._rosters[node].set_backend(db)
self._rosters[node].set_backend(db, save)
for node in new_entries - existing_entries:
self.add(node)

View file

@ -101,19 +101,21 @@ class RosterNode(object):
"""Iterate over the roster items."""
return self._jids.__iter__()
def set_backend(self, db=None):
def set_backend(self, db=None, save=True):
"""
Set the datastore interface object for the roster node.
Arguments:
db -- The new datastore interface.
save -- If True, save the existing state to the new
backend datastore. Defaults to True.
"""
self.db = db
existing_entries = set(self._jids)
new_entries = set(self.db.entries(self.jid, {}))
for jid in existing_entries:
self._jids[jid].set_backend(db)
self._jids[jid].set_backend(db, save)
for jid in new_entries - existing_entries:
self.add(jid)