Create an abstract Repository class

A Repository() returns the correctly instanciated dervivate of a
BaseRepository, depending on the parameters passed to it. The returned
instance is eg an ImapRepository(). This makes the code look nicer,
and we have less functions lying around outside of classes (no more
global LoadRepository() function).

This will also enable us to conveniently hand back a
LocalStatusRepository based on SQLITE rather than plain text, if the
user configures this to be the experimental and optional backend
(once it exists).

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-03-03 11:05:15 +01:00
committed by Nicolas Sebrecht
parent d05162675c
commit d5e7620ce9
6 changed files with 82 additions and 35 deletions

View File

@ -16,32 +16,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from offlineimap import CustomConfig
from offlineimap.ui import getglobalui
import os.path
import traceback
def LoadRepository(name, account, reqtype):
from offlineimap.repository.Gmail import GmailRepository
from offlineimap.repository.IMAP import IMAPRepository, MappedIMAPRepository
from offlineimap.repository.Maildir import MaildirRepository
if reqtype == 'remote':
# For now, we don't support Maildirs on the remote side.
typemap = {'IMAP': IMAPRepository,
'Gmail': GmailRepository}
elif reqtype == 'local':
typemap = {'IMAP': MappedIMAPRepository,
'Maildir': MaildirRepository}
else:
raise ValueError, "Request type %s not supported" % reqtype
config = account.getconfig()
repostype = config.get('Repository ' + name, 'type').strip()
try:
repo = typemap[repostype]
except KeyError:
raise Exception, "'%s' repository not supported for %s repositories."%\
(repostype, reqtype)
return repo(name, account)
from offlineimap import CustomConfig
from offlineimap.ui import getglobalui
class BaseRepository(CustomConfig.ConfigHelperMixin):
def __init__(self, reposname, account):