Don't pass in 'root' as para to LocalStatusFolders

They have the Repository() which contains the root, so no need to pass
it in as an extra parameter. Rename repository.LocalStatus()'s
self.directory to self.root for consistency with other backends.

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:25 +02:00 committed by Nicolas Sebrecht
parent ee75e0921f
commit 80e87d0d99
3 changed files with 14 additions and 18 deletions

View File

@ -26,11 +26,10 @@ except NameError:
magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
class LocalStatusFolder(BaseFolder):
def __init__(self, root, name, repository):
def __init__(self, name, repository):
super(LocalStatusFolder, self).__init__(name, repository)
self.root = root
self.sep = '.'
self.filename = os.path.join(root, self.getfolderbasename())
self.filename = os.path.join(self.getroot(), self.getfolderbasename())
self.messagelist = {}
self.savelock = threading.Lock()
self.doautosave = self.config.getdefaultboolean("general", "fsync",
@ -47,7 +46,7 @@ class LocalStatusFolder(BaseFolder):
return self.name
def getroot(self):
return self.root
return self.repository.root
def getsep(self):
return self.sep

View File

@ -46,10 +46,8 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
#current version of our db format
cur_version = 1
def __init__(self, root, name, repository):
super(LocalStatusSQLiteFolder, self).__init__(root, name,
repository)
def __init__(self, name, repository):
super(LocalStatusSQLiteFolder, self).__init__(name, repository)
# dblock protects against concurrent writes in same connection
self._dblock = Lock()
#Try to establish connection, no need for threadsafety in __init__

View File

@ -25,14 +25,14 @@ import re
class LocalStatusRepository(BaseRepository):
def __init__(self, reposname, account):
BaseRepository.__init__(self, reposname, account)
self.directory = os.path.join(account.getaccountmeta(), 'LocalStatus')
# Root directory in which the LocalStatus folders reside
self.root = os.path.join(account.getaccountmeta(), 'LocalStatus')
# statusbackend can be 'plain' or 'sqlite'
backend = self.account.getconf('status_backend', 'plain')
if backend == 'sqlite':
self._backend = 'sqlite'
self.LocalStatusFolderClass = LocalStatusSQLiteFolder
self.directory += '-sqlite'
self.root += '-sqlite'
elif backend == 'plain':
self._backend = 'plain'
self.LocalStatusFolderClass = LocalStatusFolder
@ -40,8 +40,8 @@ class LocalStatusRepository(BaseRepository):
raise SyntaxWarning("Unknown status_backend '%s' for account '%s'" \
% (backend, account.name))
if not os.path.exists(self.directory):
os.mkdir(self.directory, 0700)
if not os.path.exists(self.root):
os.mkdir(self.root, 0700)
# self._folders is a list of LocalStatusFolders()
self._folders = None
@ -60,7 +60,7 @@ class LocalStatusRepository(BaseRepository):
# replace with literal 'dot' if final path name is '.' as '.' is
# an invalid file name.
basename = re.sub('(^|\/)\.$','\\1dot', basename)
return os.path.join(self.directory, basename)
return os.path.join(self.root, basename)
def makefolder(self, foldername):
"""Create a LocalStatus Folder
@ -82,8 +82,7 @@ class LocalStatusRepository(BaseRepository):
def getfolder(self, foldername):
"""Return the Folder() object for a foldername"""
return self.LocalStatusFolderClass(self.directory, foldername,
self)
return self.LocalStatusFolderClass(foldername, self)
def getfolders(self):
"""Returns a list of all cached folders."""
@ -91,7 +90,7 @@ class LocalStatusRepository(BaseRepository):
return self._folders
self._folders = []
for folder in os.listdir(self.directory):
for folder in os.listdir(self.root):
self._folders.append(self.getfolder(folder))
return self._folders