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

View File

@ -46,10 +46,8 @@ 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): def __init__(self, name, repository):
super(LocalStatusSQLiteFolder, self).__init__(root, name, super(LocalStatusSQLiteFolder, self).__init__(name, repository)
repository)
# dblock protects against concurrent writes in same connection # dblock protects against concurrent writes in same connection
self._dblock = Lock() self._dblock = Lock()
#Try to establish connection, no need for threadsafety in __init__ #Try to establish connection, no need for threadsafety in __init__

View File

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