2002-06-21 04:20:42 +02:00
|
|
|
# Local status cache repository support
|
|
|
|
# Copyright (C) 2002 John Goerzen
|
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2002-06-21 04:20:42 +02:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2006-08-12 06:15:55 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-06-21 04:20:42 +02:00
|
|
|
|
|
|
|
from Base import BaseRepository
|
2002-06-21 12:01:10 +02:00
|
|
|
from offlineimap import folder
|
2008-03-03 19:57:56 +01:00
|
|
|
import offlineimap.folder.LocalStatus
|
2008-05-07 01:23:48 +02:00
|
|
|
import os, re
|
2002-06-21 04:20:42 +02:00
|
|
|
|
|
|
|
class LocalStatusRepository(BaseRepository):
|
2003-04-18 04:18:34 +02:00
|
|
|
def __init__(self, reposname, account):
|
|
|
|
BaseRepository.__init__(self, reposname, account)
|
|
|
|
self.directory = os.path.join(account.getaccountmeta(), 'LocalStatus')
|
|
|
|
if not os.path.exists(self.directory):
|
|
|
|
os.mkdir(self.directory, 0700)
|
2002-06-21 04:20:42 +02:00
|
|
|
self.folders = None
|
|
|
|
|
|
|
|
def getsep(self):
|
|
|
|
return '.'
|
|
|
|
|
|
|
|
def getfolderfilename(self, foldername):
|
2003-04-18 04:18:34 +02:00
|
|
|
foldername = re.sub('/\.$', '/dot', foldername)
|
|
|
|
foldername = re.sub('^\.$', 'dot', foldername)
|
2002-06-21 04:20:42 +02:00
|
|
|
return os.path.join(self.directory, foldername)
|
|
|
|
|
|
|
|
def makefolder(self, foldername):
|
2008-04-17 07:09:32 +02:00
|
|
|
# "touch" the file, truncating it.
|
2008-05-07 01:23:48 +02:00
|
|
|
filename = self.getfolderfilename(foldername)
|
2008-04-17 07:09:11 +02:00
|
|
|
file = open(filename + ".tmp", "wt")
|
2008-03-03 19:57:56 +01:00
|
|
|
file.write(offlineimap.folder.LocalStatus.magicline + '\n')
|
2008-04-17 07:09:11 +02:00
|
|
|
file.flush()
|
|
|
|
os.fsync(file.fileno())
|
2002-06-21 04:20:42 +02:00
|
|
|
file.close()
|
2008-03-03 19:59:40 +01:00
|
|
|
os.rename(filename + ".tmp", filename)
|
|
|
|
|
2002-06-21 04:20:42 +02:00
|
|
|
# Invalidate the cache.
|
|
|
|
self.folders = None
|
|
|
|
|
|
|
|
def getfolders(self):
|
|
|
|
retval = []
|
|
|
|
for folder in os.listdir(self.directory):
|
2002-06-21 05:40:58 +02:00
|
|
|
retval.append(folder.LocalStatus.LocalStatusFolder(self.directory,
|
2008-08-02 21:55:08 +02:00
|
|
|
folder, self, self.accountname,
|
|
|
|
self.config))
|
2002-06-21 04:20:42 +02:00
|
|
|
return retval
|
|
|
|
|
|
|
|
def getfolder(self, foldername):
|
2002-08-20 22:54:02 +02:00
|
|
|
return folder.LocalStatus.LocalStatusFolder(self.directory, foldername,
|
2008-08-02 21:55:08 +02:00
|
|
|
self, self.accountname,
|
|
|
|
self.config)
|
2002-06-21 05:40:58 +02:00
|
|
|
|
2002-06-21 04:20:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|