[PATCH 1/5] BaseFolder(): Save name and repository

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


As all Folders share these parameters, we can safely handle them in
BaseFolder. This makes sense, as BaseFolder has a getname() function
that returns self.name but nothing actually set self.name.

It also saves a few lines of code.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/Base.py        |    8 +++++++-
 offlineimap/folder/Gmail.py       |    4 ++--
 offlineimap/folder/IMAP.py        |    5 ++---
 offlineimap/folder/LocalStatus.py |    4 +---
 offlineimap/folder/Maildir.py     |    5 +----
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 5bd8061..9c8feeb 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -28,8 +28,14 @@ except NameError:
     from sets import Set as set
 
 class BaseFolder(object):
-    def __init__(self):
+    def __init__(self, name, repository):
+        """
+        :para name: Path & name of folder minus root or reference
+        :para repository: Repository() in which the folder is.
+        """
         self.ui = getglobalui()
+        self.name = name
+        self.repository = repository
 
     def getname(self):
         """Returns name"""
diff --git a/offlineimap/folder/Gmail.py b/offlineimap/folder/Gmail.py
index 3ca11cd..e65793d 100644
--- a/offlineimap/folder/Gmail.py
+++ b/offlineimap/folder/Gmail.py
@@ -34,12 +34,12 @@ class GmailFolder(IMAPFolder):
     """
 
     def __init__(self, imapserver, name, visiblename, accountname, repository):
+        super(GmailFolder, self).__init__(imapserver, name, visiblename,
+                                          accountname, repository)
         self.realdelete = repository.getrealdelete(name)
         self.trash_folder = repository.gettrashfolder(name)
         #: Gmail will really delete messages upon EXPUNGE in these folders
         self.real_delete_folders =  [ self.trash_folder, repository.getspamfolder() ]
-        IMAPFolder.__init__(self, imapserver, name, visiblename, \
-                            accountname, repository)
 
     def deletemessages_noconvert(self, uidlist):
         uidlist = [uid for uid in uidlist if uid in self.messagelist]
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 4dcae7d..129b9f0 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -33,18 +33,17 @@ except NameError:
 
 class IMAPFolder(BaseFolder):
     def __init__(self, imapserver, name, visiblename, accountname, repository):
+        name = imaputil.dequote(name)
+        super(IMAPFolder, self).__init__(name, repository)
         self.config = imapserver.config
         self.expunge = repository.getexpunge()
-        self.name = imaputil.dequote(name)
         self.root = None # imapserver.root
         self.sep = imapserver.delim
         self.imapserver = imapserver
         self.messagelist = None
         self.visiblename = visiblename
         self.accountname = accountname
-        self.repository = repository
         self.randomgenerator = random.Random()
-        BaseFolder.__init__(self)
         #self.ui is set in BaseFolder
 
     def selectro(self, imapobj):
diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index be9d1e3..732c5a6 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -27,18 +27,16 @@ magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
 
 class LocalStatusFolder(BaseFolder):
     def __init__(self, root, name, repository, accountname, config):
-        self.name = name
+        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.repository = repository
         self.savelock = threading.Lock()
         self.doautosave = config.getdefaultboolean("general", "fsync", False)
         """Should we perform fsyncs as often as possible?"""
         self.accountname = accountname
-        super(LocalStatusFolder, self).__init__()
 
     def getaccountname(self):
         return self.accountname
diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index cedcb5d..20b306b 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -59,13 +59,12 @@ def gettimeseq():
 
 class MaildirFolder(BaseFolder):
     def __init__(self, root, name, sep, repository, accountname, config):
-        self.name = name
+        super(MaildirFolder, self).__init__(name, repository)
         self.config = config
         self.dofsync = config.getdefaultboolean("general", "fsync", True)
         self.root = root
         self.sep = sep
         self.messagelist = None
-        self.repository = repository
         self.accountname = accountname
 
         self.wincompatible = self.config.getdefaultboolean(
@@ -77,8 +76,6 @@ class MaildirFolder(BaseFolder):
             self.infosep = '!'
 
         self.flagmatchre = re.compile(self.infosep + '.*2,([A-Z]+)')
-
-        BaseFolder.__init__(self)
         #self.ui is set in BaseFolder.init()
         # Cache the full folder path, as we use getfullname() very often
         self._fullname = os.path.join(self.getroot(), self.getname())
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list