Permalink
Browse files

weave 'merge' attribute through the service

  • Loading branch information...
1 parent 6e5ade8 commit edb05859915f7f155d2107ebbc302c52ec4efee1 @glyph glyph committed Feb 16, 2012
Showing with 19 additions and 11 deletions.
  1. +19 −11 txdav/common/datastore/upgrade/migrate.py
@@ -38,7 +38,7 @@
from twext.python.parallel import Parallelizer
from twext.internet.spawnsvc import SpawnerService
-from twisted.protocols.amp import AMP, Command, String
+from twisted.protocols.amp import AMP, Command, String, Boolean
from txdav.caldav.datastore.util import migrateHome as migrateCalendarHome
from txdav.carddav.datastore.util import migrateHome as migrateAddressbookHome
@@ -108,7 +108,8 @@ class Configure(Command):
"""
arguments = [("filename", String()),
- ("appropriateStoreClass", String())]
+ ("appropriateStoreClass", String()),
+ ("merge", Boolean())]
@@ -146,7 +147,8 @@ def configure(self, filename, storeClass):
name, with the given dead property storage class.
"""
return self.callRemote(Configure, filename=filename,
- appropriateStoreClass=qual(storeClass))
+ appropriateStoreClass=qual(storeClass),
+ merge=self.service.merge)
def oneUpgrade(self, uid, homeType):
@@ -174,13 +176,13 @@ def __init__(self, store):
@Configure.responder
- def configure(self, filename, appropriateStoreClass):
+ def configure(self, filename, appropriateStoreClass, merge):
subsvc = None
self.upgrader = UpgradeToDatabaseService(
FileStore(
CachingFilePath(filename), None, True, True,
propertyStoreClass=namedAny(appropriateStoreClass)
- ), self.store, subsvc
+ ), self.store, subsvc, merge=merge
)
return {}
@@ -210,7 +212,7 @@ class UpgradeToDatabaseService(Service, LoggingMixIn, object):
@classmethod
def wrapService(cls, path, service, store, uid=None, gid=None,
- parallel=0, spawner=None):
+ parallel=0, spawner=None, merge=False):
"""
Create an L{UpgradeToDatabaseService} if there are still file-based
calendar or addressbook homes remaining in the given path.
@@ -236,6 +238,9 @@ def wrapService(cls, path, service, store, uid=None, gid=None,
@param spawner: a concrete L{StoreSpawnerService} subclass that will be
used to spawn helper processes.
+ @param merge: merge filesystem homes into SQL homes, rather than
+ skipping them.
+
@return: a service
@rtype: L{IService}
"""
@@ -277,14 +282,14 @@ def wrapService(cls, path, service, store, uid=None, gid=None,
FileStore(path, None, True, True,
propertyStoreClass=appropriateStoreClass),
store, service, uid=uid, gid=gid,
- parallel=parallel, spawner=spawner,
+ parallel=parallel, spawner=spawner, merge=merge
)
return self
return service
def __init__(self, fileStore, sqlStore, service, uid=None, gid=None,
- parallel=0, spawner=None):
+ parallel=0, spawner=None, merge=False):
"""
Initialize the service.
"""
@@ -295,6 +300,7 @@ def __init__(self, fileStore, sqlStore, service, uid=None, gid=None,
self.gid = gid
self.parallel = parallel
self.spawner = spawner
+ self.merge = merge
@inlineCallbacks
@@ -308,16 +314,18 @@ def migrateOneHome(self, fileTxn, homeType, fileHome):
(homeType, uid))
sqlTxn = self.sqlStore.newTransaction()
homeGetter = destFunc(sqlTxn)
- if (yield homeGetter(uid, create=False)) is not None:
+ sqlHome = yield homeGetter(uid, create=False)
+ if sqlHome is not None and not self.merge:
self.log_warn(
"%s home %r already existed not migrating" % (
homeType, uid))
yield sqlTxn.abort()
yield fileTxn.commit()
returnValue(None)
try:
- sqlHome = yield homeGetter(uid, create=True)
- yield migrateFunc(fileHome, sqlHome)
+ if sqlHome is None:
+ sqlHome = yield homeGetter(uid, create=True)
+ yield migrateFunc(fileHome, sqlHome, merge=self.merge)
except:
f = Failure()
yield fileTxn.abort()

0 comments on commit edb0585

Please sign in to comment.