Merge branch 'ss/abstract-repository-class' into next
Conflicts: Changelog.draft.rst
This commit is contained in:
commit
8197077c00
@ -19,6 +19,7 @@ Changes
|
||||
-------
|
||||
|
||||
* Makefile use magic to find the version number.
|
||||
* Rework the repository module
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
@ -16,7 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from offlineimap import threadutil, mbnames, CustomConfig
|
||||
import offlineimap.repository.Base, offlineimap.repository.LocalStatus
|
||||
from offlineimap.repository import Repository
|
||||
from offlineimap.ui import getglobalui
|
||||
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
|
||||
from subprocess import Popen, PIPE
|
||||
@ -179,13 +179,10 @@ class SyncableAccount(Account):
|
||||
if not os.path.exists(accountmetadata):
|
||||
os.mkdir(accountmetadata, 0700)
|
||||
|
||||
self.remoterepos = offlineimap.repository.Base.LoadRepository(self.getconf('remoterepository'), self, 'remote')
|
||||
|
||||
# Connect to the local repository.
|
||||
self.localrepos = offlineimap.repository.Base.LoadRepository(self.getconf('localrepository'), self, 'local')
|
||||
|
||||
# Connect to the local cache.
|
||||
self.statusrepos = offlineimap.repository.LocalStatus.LocalStatusRepository(self.getconf('localrepository'), self)
|
||||
# get all three repositories
|
||||
self.remoterepos = Repository(self, 'remote')
|
||||
self.localrepos = Repository(self, 'local')
|
||||
self.statusrepos = Repository(self, 'status')
|
||||
|
||||
#might need changes here to ensure that one account sync does not crash others...
|
||||
if not self.refreshperiod:
|
||||
|
@ -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):
|
||||
|
@ -15,7 +15,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from IMAP import IMAPRepository
|
||||
from offlineimap.repository.IMAP import IMAPRepository
|
||||
from offlineimap import folder, imaputil
|
||||
from offlineimap.imapserver import IMAPServer
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from Base import BaseRepository
|
||||
from offlineimap.repository.Base import BaseRepository
|
||||
from offlineimap import folder, imaputil, imapserver
|
||||
from offlineimap.folder.UIDMaps import MappedIMAPFolder
|
||||
from offlineimap.threadutil import ExitNotifyThread
|
||||
|
@ -1 +1,71 @@
|
||||
__all__ = ['Gmail', 'IMAP', 'Base', 'Maildir', 'LocalStatus']
|
||||
# Copyright (C) 2002-2007 John Goerzen <jgoerzen@complete.org>
|
||||
# 2010 Sebastian Spaeth <Sebastian@SSpaeth.de> and contributors
|
||||
#
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from offlineimap.repository.IMAP import IMAPRepository, MappedIMAPRepository
|
||||
from offlineimap.repository.Gmail import GmailRepository
|
||||
from offlineimap.repository.Maildir import MaildirRepository
|
||||
from offlineimap.repository.LocalStatus import LocalStatusRepository
|
||||
|
||||
class Repository(object):
|
||||
"""Abstract class that returns the correct Repository type
|
||||
instance based on 'account' and 'reqtype', e.g. a
|
||||
class:`ImapRepository` instance."""
|
||||
|
||||
def __new__(cls, account, reqtype):
|
||||
"""
|
||||
:param account: :class:`Account`
|
||||
:param regtype: 'remote', 'local', or 'status'"""
|
||||
|
||||
if reqtype == 'remote':
|
||||
name = account.getconf('remoterepository')
|
||||
# We don't support Maildirs on the remote side.
|
||||
typemap = {'IMAP': IMAPRepository,
|
||||
'Gmail': GmailRepository}
|
||||
|
||||
elif reqtype == 'local':
|
||||
name = account.getconf('localrepository')
|
||||
typemap = {'IMAP': MappedIMAPRepository,
|
||||
'Maildir': MaildirRepository}
|
||||
|
||||
elif reqtype == 'status':
|
||||
# create and return a LocalStatusRepository
|
||||
name = account.getconf('localrepository')
|
||||
return LocalStatusRepository(name, account)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def __init__(self, account, reqtype):
|
||||
"""Load the correct Repository type and return that. The
|
||||
__init__ of the corresponding Repository class will be
|
||||
executed instead of this stub
|
||||
|
||||
:param account: :class:`Account`
|
||||
:param regtype: 'remote', 'local', or 'status'
|
||||
"""
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user