]> code.delx.au - offlineimap/blob - offlineimap/repository/LocalStatus.py
Make parent dirs of localstatus folders.
[offlineimap] / offlineimap / repository / LocalStatus.py
1 # Local status cache repository support
2 # Copyright (C) 2002 John Goerzen
3 # <jgoerzen@complete.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 from Base import BaseRepository
20 from offlineimap import folder
21 import offlineimap.folder.LocalStatus
22 import os, re, os.path
23
24 class LocalStatusRepository(BaseRepository):
25 def __init__(self, reposname, account):
26 BaseRepository.__init__(self, reposname, account)
27 self.directory = os.path.join(account.getaccountmeta(), 'LocalStatus')
28 if not os.path.exists(self.directory):
29 os.mkdir(self.directory, 0700)
30 self.folders = None
31
32 def getsep(self):
33 return '.'
34
35 def getfolderfilename(self, foldername):
36 foldername = re.sub('/\.$', '/dot', foldername)
37 foldername = re.sub('^\.$', 'dot', foldername)
38 return os.path.join(self.directory, foldername)
39
40 def makefolder(self, foldername):
41 # Create parent dirs
42
43 filename = self.getfolderfilename(foldername)
44 os.makedirs(os.path.dirname(foldername), 0700)
45
46 # "touch" the file, truncating it.
47 file = open(filename + ".tmp", "wt")
48 file.write(offlineimap.folder.LocalStatus.magicline + '\n')
49 file.flush()
50 os.fsync(file.fileno())
51 file.close()
52 os.rename(filename + ".tmp", filename)
53
54 # Invalidate the cache.
55 self.folders = None
56
57 def getfolders(self):
58 retval = []
59 for folder in os.listdir(self.directory):
60 retval.append(folder.LocalStatus.LocalStatusFolder(self.directory,
61 folder, self, self.accountname))
62 return retval
63
64 def getfolder(self, foldername):
65 return folder.LocalStatus.LocalStatusFolder(self.directory, foldername,
66 self, self.accountname)
67
68
69
70
71