repository.LocalStatus: Remove code duplication

Make getfolders() invoke getfolder() for each folder rather than
duplicating code. Also add a forgetfolders() implementation.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-05-05 15:59:28 +02:00 committed by Nicolas Sebrecht
parent e1e9c8e831
commit af25c2779f

View File

@ -48,24 +48,28 @@ class LocalStatusRepository(BaseRepository):
os.fsync(file.fileno()) os.fsync(file.fileno())
file.close() file.close()
os.rename(filename + ".tmp", filename) os.rename(filename + ".tmp", filename)
# Invalidate the cache. # Invalidate the cache.
self.folders = None self.folders = None
def getfolders(self):
retval = []
for folder in os.listdir(self.directory):
retval.append(folder.LocalStatus.LocalStatusFolder(self.directory,
folder, self, self.accountname,
self.config))
return retval
def getfolder(self, foldername): def getfolder(self, foldername):
return folder.LocalStatus.LocalStatusFolder(self.directory, foldername, """Return the Folder() object for a foldername"""
self, self.accountname, return self.LocalStatusFolderClass(self.directory, foldername,
self.config) self, self.accountname,
self.config)
def getfolders(self):
"""Returns a list of ALL folders on this server.
This is currently nowhere used in the code."""
if self._folders != None:
return self._folders
for folder in os.listdir(self.directory):
self._folders = retval.append(self.getfolder(folder))
return self._folders
def forgetfolders(self):
"""Forgets the cached list of folders, if any. Useful to run
after a sync run."""
self._folders = None