[PATCH 8/9] repository.LocalStatus: Remove code duplication

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Apr 26 11:31:39 BST 2011


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

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/repository/LocalStatus.py |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/offlineimap/repository/LocalStatus.py b/offlineimap/repository/LocalStatus.py
index 5cbf77b..722f6c3 100644
--- a/offlineimap/repository/LocalStatus.py
+++ b/offlineimap/repository/LocalStatus.py
@@ -48,24 +48,28 @@ class LocalStatusRepository(BaseRepository):
         os.fsync(file.fileno())
         file.close()
         os.rename(filename + ".tmp", filename)
-        
         # Invalidate the cache.
         self.folders = None
 
+    def getfolder(self, foldername):
+        """Return the Folder() object for a foldername"""
+        return self.LocalStatusFolderClass(self.directory, foldername,
+                                           self, self.accountname,
+                                           self.config)
+
     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
+        """Returns a list of ALL folders on this server.
 
-    def getfolder(self, foldername):
-        return folder.LocalStatus.LocalStatusFolder(self.directory, foldername,
-                                                    self, self.accountname,
-                                                    self.config)
+        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
 
-    
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list