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:
parent
c93cd9bb1a
commit
410e2d35e9
@ -44,6 +44,11 @@ class BaseFolder(object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def accountname(self):
|
||||||
|
"""Account name as string"""
|
||||||
|
return self.repository.accountname
|
||||||
|
|
||||||
def suggeststhreads(self):
|
def suggeststhreads(self):
|
||||||
"""Returns true if this folder suggests using threads for actions;
|
"""Returns true if this folder suggests using threads for actions;
|
||||||
false otherwise. Probably only IMAP will return true."""
|
false otherwise. Probably only IMAP will return true."""
|
||||||
@ -239,7 +244,7 @@ class BaseFolder(object):
|
|||||||
# self.getmessage(). So, don't call self.getmessage unless
|
# self.getmessage(). So, don't call self.getmessage unless
|
||||||
# really needed.
|
# really needed.
|
||||||
if register: # output that we start a new thread
|
if register: # output that we start a new thread
|
||||||
self.ui.registerthread(self.getaccountname())
|
self.ui.registerthread(self.accountname)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = None
|
message = None
|
||||||
@ -295,7 +300,7 @@ class BaseFolder(object):
|
|||||||
self.ui.error(e, exc_info()[2])
|
self.ui.error(e, exc_info()[2])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.ui.error(e, "Copying message %s [acc: %s]:\n %s" %\
|
self.ui.error(e, "Copying message %s [acc: %s]:\n %s" %\
|
||||||
(uid, self.getaccountname(),
|
(uid, self.accountname,
|
||||||
traceback.format_exc()))
|
traceback.format_exc()))
|
||||||
raise #raise on unknown errors, so we can fix those
|
raise #raise on unknown errors, so we can fix those
|
||||||
|
|
||||||
@ -443,5 +448,5 @@ class BaseFolder(object):
|
|||||||
self.ui.error(e, exc_info()[2])
|
self.ui.error(e, exc_info()[2])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.ui.error(e, exc_info()[2], "Syncing folder %s [acc: %s]" %\
|
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
|
raise # raise unknown Exceptions so we can fix them
|
||||||
|
@ -33,9 +33,9 @@ class GmailFolder(IMAPFolder):
|
|||||||
http://mail.google.com/support/bin/answer.py?answer=77657&topic=12815
|
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,
|
super(GmailFolder, self).__init__(imapserver, name, visiblename,
|
||||||
accountname, repository)
|
repository)
|
||||||
self.realdelete = repository.getrealdelete(name)
|
self.realdelete = repository.getrealdelete(name)
|
||||||
self.trash_folder = repository.gettrashfolder(name)
|
self.trash_folder = repository.gettrashfolder(name)
|
||||||
#: Gmail will really delete messages upon EXPUNGE in these folders
|
#: Gmail will really delete messages upon EXPUNGE in these folders
|
||||||
|
@ -32,7 +32,7 @@ except NameError:
|
|||||||
|
|
||||||
|
|
||||||
class IMAPFolder(BaseFolder):
|
class IMAPFolder(BaseFolder):
|
||||||
def __init__(self, imapserver, name, visiblename, accountname, repository):
|
def __init__(self, imapserver, name, visiblename, repository):
|
||||||
name = imaputil.dequote(name)
|
name = imaputil.dequote(name)
|
||||||
super(IMAPFolder, self).__init__(name, repository)
|
super(IMAPFolder, self).__init__(name, repository)
|
||||||
self.config = imapserver.config
|
self.config = imapserver.config
|
||||||
@ -42,7 +42,6 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.imapserver = imapserver
|
self.imapserver = imapserver
|
||||||
self.messagelist = None
|
self.messagelist = None
|
||||||
self.visiblename = visiblename
|
self.visiblename = visiblename
|
||||||
self.accountname = accountname
|
|
||||||
self.randomgenerator = random.Random()
|
self.randomgenerator = random.Random()
|
||||||
#self.ui is set in BaseFolder
|
#self.ui is set in BaseFolder
|
||||||
|
|
||||||
@ -60,9 +59,6 @@ class IMAPFolder(BaseFolder):
|
|||||||
except imapobj.readonly:
|
except imapobj.readonly:
|
||||||
imapobj.select(self.getfullname(), readonly = 1)
|
imapobj.select(self.getfullname(), readonly = 1)
|
||||||
|
|
||||||
def getaccountname(self):
|
|
||||||
return self.accountname
|
|
||||||
|
|
||||||
def suggeststhreads(self):
|
def suggeststhreads(self):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ except NameError:
|
|||||||
magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
|
magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
|
||||||
|
|
||||||
class LocalStatusFolder(BaseFolder):
|
class LocalStatusFolder(BaseFolder):
|
||||||
def __init__(self, root, name, repository, accountname, config):
|
def __init__(self, root, name, repository, config):
|
||||||
super(LocalStatusFolder, self).__init__(name, repository)
|
super(LocalStatusFolder, self).__init__(name, repository)
|
||||||
self.root = root
|
self.root = root
|
||||||
self.sep = '.'
|
self.sep = '.'
|
||||||
@ -36,10 +36,6 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
self.savelock = threading.Lock()
|
self.savelock = threading.Lock()
|
||||||
self.doautosave = config.getdefaultboolean("general", "fsync", False)
|
self.doautosave = config.getdefaultboolean("general", "fsync", False)
|
||||||
"""Should we perform fsyncs as often as possible?"""
|
"""Should we perform fsyncs as often as possible?"""
|
||||||
self.accountname = accountname
|
|
||||||
|
|
||||||
def getaccountname(self):
|
|
||||||
return self.accountname
|
|
||||||
|
|
||||||
def storesmessages(self):
|
def storesmessages(self):
|
||||||
return 0
|
return 0
|
||||||
|
@ -46,10 +46,9 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
|
|||||||
#current version of our db format
|
#current version of our db format
|
||||||
cur_version = 1
|
cur_version = 1
|
||||||
|
|
||||||
def __init__(self, root, name, repository, accountname, config):
|
def __init__(self, root, name, repository, config):
|
||||||
super(LocalStatusSQLiteFolder, self).__init__(root, name,
|
super(LocalStatusSQLiteFolder, self).__init__(root, name,
|
||||||
repository,
|
repository,
|
||||||
accountname,
|
|
||||||
config)
|
config)
|
||||||
|
|
||||||
# dblock protects against concurrent writes in same connection
|
# dblock protects against concurrent writes in same connection
|
||||||
|
@ -58,14 +58,13 @@ def gettimeseq():
|
|||||||
timelock.release()
|
timelock.release()
|
||||||
|
|
||||||
class MaildirFolder(BaseFolder):
|
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)
|
super(MaildirFolder, self).__init__(name, repository)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.dofsync = config.getdefaultboolean("general", "fsync", True)
|
self.dofsync = config.getdefaultboolean("general", "fsync", True)
|
||||||
self.root = root
|
self.root = root
|
||||||
self.sep = sep
|
self.sep = sep
|
||||||
self.messagelist = None
|
self.messagelist = None
|
||||||
self.accountname = accountname
|
|
||||||
|
|
||||||
self.wincompatible = self.config.getdefaultboolean(
|
self.wincompatible = self.config.getdefaultboolean(
|
||||||
"Account "+self.accountname, "maildir-windows-compatible", False)
|
"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
|
# Cache the full folder path, as we use getfullname() very often
|
||||||
self._fullname = os.path.join(self.getroot(), self.getname())
|
self._fullname = os.path.join(self.getroot(), self.getname())
|
||||||
|
|
||||||
def getaccountname(self):
|
|
||||||
return self.accountname
|
|
||||||
|
|
||||||
def getfullname(self):
|
def getfullname(self):
|
||||||
"""Return the absolute file path to the Maildir folder (sans cur|new)"""
|
"""Return the absolute file path to the Maildir folder (sans cur|new)"""
|
||||||
return self._fullname
|
return self._fullname
|
||||||
|
@ -22,13 +22,14 @@ from offlineimap import CustomConfig
|
|||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
|
|
||||||
class BaseRepository(object, CustomConfig.ConfigHelperMixin):
|
class BaseRepository(object, CustomConfig.ConfigHelperMixin):
|
||||||
|
|
||||||
def __init__(self, reposname, account):
|
def __init__(self, reposname, account):
|
||||||
self.ui = getglobalui()
|
self.ui = getglobalui()
|
||||||
self.account = account
|
self.account = account
|
||||||
self.config = account.getconfig()
|
self.config = account.getconfig()
|
||||||
self.name = reposname
|
self.name = reposname
|
||||||
self.localeval = account.getlocaleval()
|
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)
|
self.uiddir = os.path.join(self.config.getmetadatadir(), 'Repository-' + self.name)
|
||||||
if not os.path.exists(self.uiddir):
|
if not os.path.exists(self.uiddir):
|
||||||
os.mkdir(self.uiddir, 0700)
|
os.mkdir(self.uiddir, 0700)
|
||||||
@ -71,15 +72,17 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def accountname(self):
|
||||||
|
"""Account name as string"""
|
||||||
|
return self._accountname
|
||||||
|
|
||||||
def getuiddir(self):
|
def getuiddir(self):
|
||||||
return self.uiddir
|
return self.uiddir
|
||||||
|
|
||||||
def getmapdir(self):
|
def getmapdir(self):
|
||||||
return self.mapdir
|
return self.mapdir
|
||||||
|
|
||||||
def getaccountname(self):
|
|
||||||
return self.accountname
|
|
||||||
|
|
||||||
def getsection(self):
|
def getsection(self):
|
||||||
return 'Repository ' + self.name
|
return 'Repository ' + self.name
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ class IMAPRepository(BaseRepository):
|
|||||||
def getfolder(self, foldername):
|
def getfolder(self, foldername):
|
||||||
return self.getfoldertype()(self.imapserver, foldername,
|
return self.getfoldertype()(self.imapserver, foldername,
|
||||||
self.nametrans(foldername),
|
self.nametrans(foldername),
|
||||||
self.accountname, self)
|
self)
|
||||||
|
|
||||||
def getfoldertype(self):
|
def getfoldertype(self):
|
||||||
return folder.IMAP.IMAPFolder
|
return folder.IMAP.IMAPFolder
|
||||||
@ -303,7 +303,7 @@ class IMAPRepository(BaseRepository):
|
|||||||
continue
|
continue
|
||||||
retval.append(self.getfoldertype()(self.imapserver, foldername,
|
retval.append(self.getfoldertype()(self.imapserver, foldername,
|
||||||
self.nametrans(foldername),
|
self.nametrans(foldername),
|
||||||
self.accountname, self))
|
self))
|
||||||
if len(self.folderincludes):
|
if len(self.folderincludes):
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
try:
|
try:
|
||||||
@ -320,7 +320,7 @@ class IMAPRepository(BaseRepository):
|
|||||||
retval.append(self.getfoldertype()(self.imapserver,
|
retval.append(self.getfoldertype()(self.imapserver,
|
||||||
foldername,
|
foldername,
|
||||||
self.nametrans(foldername),
|
self.nametrans(foldername),
|
||||||
self.accountname, self))
|
self))
|
||||||
finally:
|
finally:
|
||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class LocalStatusRepository(BaseRepository):
|
|||||||
def getfolder(self, foldername):
|
def getfolder(self, foldername):
|
||||||
"""Return the Folder() object for a foldername"""
|
"""Return the Folder() object for a foldername"""
|
||||||
return self.LocalStatusFolderClass(self.directory, foldername,
|
return self.LocalStatusFolderClass(self.directory, foldername,
|
||||||
self, self.accountname,
|
self,
|
||||||
self.config)
|
self.config)
|
||||||
|
|
||||||
def getfolders(self):
|
def getfolders(self):
|
||||||
|
@ -118,7 +118,7 @@ class MaildirRepository(BaseRepository):
|
|||||||
self._append_folder_atimes(foldername)
|
self._append_folder_atimes(foldername)
|
||||||
return folder.Maildir.MaildirFolder(self.root, foldername,
|
return folder.Maildir.MaildirFolder(self.root, foldername,
|
||||||
self.getsep(), self,
|
self.getsep(), self,
|
||||||
self.accountname, self.config)
|
self.config)
|
||||||
|
|
||||||
def _getfolders_scandir(self, root, extension = None):
|
def _getfolders_scandir(self, root, extension = None):
|
||||||
"""Recursively scan folder 'root'; return a list of MailDirFolder
|
"""Recursively scan folder 'root'; return a list of MailDirFolder
|
||||||
@ -168,7 +168,6 @@ class MaildirRepository(BaseRepository):
|
|||||||
foldername,
|
foldername,
|
||||||
self.getsep(),
|
self.getsep(),
|
||||||
self,
|
self,
|
||||||
self.accountname,
|
|
||||||
self.config))
|
self.config))
|
||||||
if self.getsep() == '/' and dirname != '.':
|
if self.getsep() == '/' and dirname != '.':
|
||||||
# Recursively check sub-directories for folders too.
|
# Recursively check sub-directories for folders too.
|
||||||
|
Loading…
Reference in New Issue
Block a user