[PATCH 3/5] Remove 'config' as parameter from BaseFolder & derivatives

Sebastian Spaeth Sebastian at SSpaeth.de
Fri Sep 16 09:54:24 BST 2011


It is possible to get the config parameter from the Repository() which is
set in BaseFolder, so we set self.config there and remove the various
methods and 'config' parameters that are superfluous.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/Base.py              |    1 +
 offlineimap/folder/IMAP.py              |    1 -
 offlineimap/folder/LocalStatus.py       |    6 +++---
 offlineimap/folder/LocalStatusSQLite.py |    5 ++---
 offlineimap/folder/Maildir.py           |    5 ++---
 offlineimap/repository/LocalStatus.py   |    3 +--
 offlineimap/repository/Maildir.py       |    6 ++----
 7 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 3339424..c8ed108 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -36,6 +36,7 @@ class BaseFolder(object):
         self.ui = getglobalui()
         self.name = name
         self.repository = repository
+        self.config = repository.getconfig()
 
     def getname(self):
         """Returns name"""
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 9fee150..822ab7c 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -35,7 +35,6 @@ class IMAPFolder(BaseFolder):
     def __init__(self, imapserver, name, visiblename, repository):
         name = imaputil.dequote(name)
         super(IMAPFolder, self).__init__(name, repository)
-        self.config = imapserver.config
         self.expunge = repository.getexpunge()
         self.root = None # imapserver.root
         self.sep = imapserver.delim
diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index ad7ccb6..821ad88 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -26,15 +26,15 @@ except NameError:
 magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
 
 class LocalStatusFolder(BaseFolder):
-    def __init__(self, root, name, repository, config):
+    def __init__(self, root, name, repository):
         super(LocalStatusFolder, self).__init__(name, repository)
         self.root = root
         self.sep = '.'
-        self.config = config
         self.filename = os.path.join(root, self.getfolderbasename())
         self.messagelist = {}
         self.savelock = threading.Lock()
-        self.doautosave = config.getdefaultboolean("general", "fsync", False)
+        self.doautosave = self.config.getdefaultboolean("general", "fsync",
+                                                        False)
         """Should we perform fsyncs as often as possible?"""
 
     def storesmessages(self):
diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py
index 6eccbaa..ba80aa1 100644
--- a/offlineimap/folder/LocalStatusSQLite.py
+++ b/offlineimap/folder/LocalStatusSQLite.py
@@ -46,10 +46,9 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
     #current version of our db format
     cur_version = 1
 
-    def __init__(self, root, name, repository, config):
+    def __init__(self, root, name, repository):
         super(LocalStatusSQLiteFolder, self).__init__(root, name, 
-                                                      repository, 
-                                                      config)       
+                                                      repository)       
 
         # dblock protects against concurrent writes in same connection
         self._dblock = Lock()
diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index 5d75121..894328c 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -58,10 +58,9 @@ def gettimeseq():
         timelock.release()
 
 class MaildirFolder(BaseFolder):
-    def __init__(self, root, name, sep, repository, config):
+    def __init__(self, root, name, sep, repository):
         super(MaildirFolder, self).__init__(name, repository)
-        self.config = config
-        self.dofsync = config.getdefaultboolean("general", "fsync", True)
+        self.dofsync = self.config.getdefaultboolean("general", "fsync", True)
         self.root = root
         self.sep = sep
         self.messagelist = None
diff --git a/offlineimap/repository/LocalStatus.py b/offlineimap/repository/LocalStatus.py
index 20291a1..d555064 100644
--- a/offlineimap/repository/LocalStatus.py
+++ b/offlineimap/repository/LocalStatus.py
@@ -83,8 +83,7 @@ class LocalStatusRepository(BaseRepository):
     def getfolder(self, foldername):
         """Return the Folder() object for a foldername"""
         return self.LocalStatusFolderClass(self.directory, foldername,
-                                           self,
-                                           self.config)
+                                           self)
 
     def getfolders(self):
         """Returns a list of all cached folders."""
diff --git a/offlineimap/repository/Maildir.py b/offlineimap/repository/Maildir.py
index 0ffc2da..f8f39b8 100644
--- a/offlineimap/repository/Maildir.py
+++ b/offlineimap/repository/Maildir.py
@@ -113,8 +113,7 @@ class MaildirRepository(BaseRepository):
         if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'):
             self._append_folder_atimes(foldername)
         return folder.Maildir.MaildirFolder(self.root, foldername,
-                                            self.getsep(), self, 
-                                            self.config)
+                                            self.getsep(), self)
     
     def _getfolders_scandir(self, root, extension = None):
         """Recursively scan folder 'root'; return a list of MailDirFolder
@@ -163,8 +162,7 @@ class MaildirRepository(BaseRepository):
                 retval.append(folder.Maildir.MaildirFolder(self.root,
                                                            foldername,
                                                            self.getsep(),
-                                                           self,
-                                                           self.config))
+                                                           self))
             if self.getsep() == '/' and dirname != '.':
                 # Recursively check sub-directories for folders too.
                 retval.extend(self._getfolders_scandir(root, foldername))
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list