Set accountname in BaseFolder, and don't pass it in initialization

We passed in the accountname to all derivatives of BaseFolder, such as
IMAPFolder(...,repository,...,accountname), although it is perfectly
possible to get the accountname from the Repository(). So remove this
unneeded parameter. Each backend had to define getaccountname() (although
the function is hardly used and most accessed .accountname directly).

On the other hand BaseFolder was using getaccountname but it never defined
the function. So make the sane thing, remove all definitions from backends
and define accountname() once in Basefolder. It was made a property and not
just a (public) attribute, so it will show up in our developer
documentation as public API.

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-09-16 10:54:23 +02:00 committed by Nicolas Sebrecht
parent c93cd9bb1a
commit 410e2d35e9
10 changed files with 26 additions and 32 deletions

View File

@ -44,6 +44,11 @@ class BaseFolder(object):
def __str__(self):
return self.name
@property
def accountname(self):
"""Account name as string"""
return self.repository.accountname
def suggeststhreads(self):
"""Returns true if this folder suggests using threads for actions;
false otherwise. Probably only IMAP will return true."""
@ -239,7 +244,7 @@ class BaseFolder(object):
# self.getmessage(). So, don't call self.getmessage unless
# really needed.
if register: # output that we start a new thread
self.ui.registerthread(self.getaccountname())
self.ui.registerthread(self.accountname)
try:
message = None
@ -295,7 +300,7 @@ class BaseFolder(object):
self.ui.error(e, exc_info()[2])
except Exception, e:
self.ui.error(e, "Copying message %s [acc: %s]:\n %s" %\
(uid, self.getaccountname(),
(uid, self.accountname,
traceback.format_exc()))
raise #raise on unknown errors, so we can fix those
@ -443,5 +448,5 @@ class BaseFolder(object):
self.ui.error(e, exc_info()[2])
except Exception, e:
self.ui.error(e, exc_info()[2], "Syncing folder %s [acc: %s]" %\
(self, self.getaccountname()))
(self, self.accountname))
raise # raise unknown Exceptions so we can fix them

View File

@ -33,9 +33,9 @@ class GmailFolder(IMAPFolder):
http://mail.google.com/support/bin/answer.py?answer=77657&topic=12815
"""
def __init__(self, imapserver, name, visiblename, accountname, repository):
def __init__(self, imapserver, name, visiblename, repository):
super(GmailFolder, self).__init__(imapserver, name, visiblename,
accountname, repository)
repository)
self.realdelete = repository.getrealdelete(name)
self.trash_folder = repository.gettrashfolder(name)
#: Gmail will really delete messages upon EXPUNGE in these folders

View File

@ -32,7 +32,7 @@ except NameError:
class IMAPFolder(BaseFolder):
def __init__(self, imapserver, name, visiblename, accountname, repository):
def __init__(self, imapserver, name, visiblename, repository):
name = imaputil.dequote(name)
super(IMAPFolder, self).__init__(name, repository)
self.config = imapserver.config
@ -42,7 +42,6 @@ class IMAPFolder(BaseFolder):
self.imapserver = imapserver
self.messagelist = None
self.visiblename = visiblename
self.accountname = accountname
self.randomgenerator = random.Random()
#self.ui is set in BaseFolder
@ -60,9 +59,6 @@ class IMAPFolder(BaseFolder):
except imapobj.readonly:
imapobj.select(self.getfullname(), readonly = 1)
def getaccountname(self):
return self.accountname
def suggeststhreads(self):
return 1

View File

@ -26,7 +26,7 @@ except NameError:
magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
class LocalStatusFolder(BaseFolder):
def __init__(self, root, name, repository, accountname, config):
def __init__(self, root, name, repository, config):
super(LocalStatusFolder, self).__init__(name, repository)
self.root = root
self.sep = '.'
@ -36,10 +36,6 @@ class LocalStatusFolder(BaseFolder):
self.savelock = threading.Lock()
self.doautosave = config.getdefaultboolean("general", "fsync", False)
"""Should we perform fsyncs as often as possible?"""
self.accountname = accountname
def getaccountname(self):
return self.accountname
def storesmessages(self):
return 0

View File

@ -46,10 +46,9 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
#current version of our db format
cur_version = 1
def __init__(self, root, name, repository, accountname, config):
def __init__(self, root, name, repository, config):
super(LocalStatusSQLiteFolder, self).__init__(root, name,
repository,
accountname,
config)
# dblock protects against concurrent writes in same connection

View File

@ -58,14 +58,13 @@ def gettimeseq():
timelock.release()
class MaildirFolder(BaseFolder):
def __init__(self, root, name, sep, repository, accountname, config):
def __init__(self, root, name, sep, repository, config):
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.accountname = accountname
self.wincompatible = self.config.getdefaultboolean(
"Account "+self.accountname, "maildir-windows-compatible", False)
@ -80,9 +79,6 @@ class MaildirFolder(BaseFolder):
# Cache the full folder path, as we use getfullname() very often
self._fullname = os.path.join(self.getroot(), self.getname())
def getaccountname(self):
return self.accountname
def getfullname(self):
"""Return the absolute file path to the Maildir folder (sans cur|new)"""
return self._fullname

View File

@ -22,13 +22,14 @@ from offlineimap import CustomConfig
from offlineimap.ui import getglobalui
class BaseRepository(object, CustomConfig.ConfigHelperMixin):
def __init__(self, reposname, account):
self.ui = getglobalui()
self.account = account
self.config = account.getconfig()
self.name = reposname
self.localeval = account.getlocaleval()
self.accountname = self.account.getname()
self._accountname = self.account.getname()
self.uiddir = os.path.join(self.config.getmetadatadir(), 'Repository-' + self.name)
if not os.path.exists(self.uiddir):
os.mkdir(self.uiddir, 0700)
@ -71,15 +72,17 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
def __str__(self):
return self.name
@property
def accountname(self):
"""Account name as string"""
return self._accountname
def getuiddir(self):
return self.uiddir
def getmapdir(self):
return self.mapdir
def getaccountname(self):
return self.accountname
def getsection(self):
return 'Repository ' + self.name

View File

@ -261,7 +261,7 @@ class IMAPRepository(BaseRepository):
def getfolder(self, foldername):
return self.getfoldertype()(self.imapserver, foldername,
self.nametrans(foldername),
self.accountname, self)
self)
def getfoldertype(self):
return folder.IMAP.IMAPFolder
@ -303,7 +303,7 @@ class IMAPRepository(BaseRepository):
continue
retval.append(self.getfoldertype()(self.imapserver, foldername,
self.nametrans(foldername),
self.accountname, self))
self))
if len(self.folderincludes):
imapobj = self.imapserver.acquireconnection()
try:
@ -320,7 +320,7 @@ class IMAPRepository(BaseRepository):
retval.append(self.getfoldertype()(self.imapserver,
foldername,
self.nametrans(foldername),
self.accountname, self))
self))
finally:
self.imapserver.releaseconnection(imapobj)

View File

@ -83,7 +83,7 @@ class LocalStatusRepository(BaseRepository):
def getfolder(self, foldername):
"""Return the Folder() object for a foldername"""
return self.LocalStatusFolderClass(self.directory, foldername,
self, self.accountname,
self,
self.config)
def getfolders(self):

View File

@ -118,7 +118,7 @@ class MaildirRepository(BaseRepository):
self._append_folder_atimes(foldername)
return folder.Maildir.MaildirFolder(self.root, foldername,
self.getsep(), self,
self.accountname, self.config)
self.config)
def _getfolders_scandir(self, root, extension = None):
"""Recursively scan folder 'root'; return a list of MailDirFolder
@ -168,7 +168,6 @@ class MaildirRepository(BaseRepository):
foldername,
self.getsep(),
self,
self.accountname,
self.config))
if self.getsep() == '/' and dirname != '.':
# Recursively check sub-directories for folders too.