]> code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/repository/Base.py
e0aae0082bd94e342d567d892c9d9332ab848594
[offlineimap] / offlineimap / head / offlineimap / repository / Base.py
1 # Base 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; version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 class BaseRepository:
19 def getfolders(self):
20 """Returns a list of ALL folders on this server."""
21 return []
22
23 def getsep(self):
24 raise NotImplementedError
25
26 def makefolder(self, foldername):
27 raise NotImplementedError
28
29 def deletefolder(self, foldername):
30 raise NotImplementedError
31
32 def getfolder(self, foldername):
33 raise NotImplementedError
34
35 def syncfoldersto(self, dest):
36 """Syncs the folders in this repository to those in dest.
37 It does NOT sync the contents of those folders."""
38 src = self
39 srcfolders = src.getfolders()
40 destfolders = dest.getfolders()
41
42 # Create hashes with the names, but convert the source folders
43 # to the dest folder's sep.
44
45 srchash = {}
46 for folder in srcfolders:
47 srchash[folder.getvisiblename().replace(src.getsep(), dest.getsep())] = \
48 folder
49 desthash = {}
50 for folder in destfolders:
51 desthash[folder.getvisiblename()] = folder
52
53 #
54 # Find new folders.
55 #
56
57 for key in srchash.keys():
58 if not key in desthash:
59 dest.makefolder(key)
60
61 #
62 # Find deleted folders.
63 #
64 # We don't delete folders right now.
65
66 #for key in desthash.keys():
67 # if not key in srchash:
68 # dest.deletefolder(key)
69