conductor supports --protocols option twisty
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 12 Mar 2009 22:35:06 +1100
branchtwisty
changeset 88 d3e18d08271bb40fbbf46469b28f0b5c2b370cf0
parent 87 14e5d7be81ff23c6ab69a7f7b44be8511c5a7818
child 89 ab86e5a10ee8b2449fc0cb29b33f3f71d13c9568
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
conductor supports --protocols option
server/python/junius/sync.py
--- a/server/python/junius/sync.py
+++ b/server/python/junius/sync.py
@@ -4,26 +4,30 @@ from twisted.internet import reactor, de
 import paisley
 
 import junius.proto as proto
 from junius.model import get_db
 
 logger = logging.getLogger(__name__)
 
 _conductor = None
-def get_conductor():
+
+def get_conductor(options=None):
   global _conductor
   if _conductor is None:
-    _conductor = SyncConductor()
+    _conductor = SyncConductor(options)
+  else:
+    assert options is None, 'can only set this at startup'
   return _conductor
   
   
 class SyncConductor(object):
-  def __init__(self):
+  def __init__(self, options):
     self.log = logger
+    self.options = options
 
     self.db = get_db()
 
     self.active_accounts = []
 
   def _ohNoes(self, failure, *args, **kwargs):
     self.log.error('OH NOES! failure! %s', failure)
     reactor.stop()
@@ -33,26 +37,27 @@ class SyncConductor(object):
       ).addCallback(self._gotAllAccounts
       ).addErrback(self._ohNoes)
 
   def _gotAllAccounts(self, rows, *args, **kwargs):
     self.log.info("Have %d accounts to synch", len(rows))
     for row in rows:
       account_details = row['value']
       kind = account_details['kind']
-      if kind in proto.protocols:
-        account = proto.protocols[kind](self.db, account_details)
-        self.log.info('Starting sync of %s account: %s',
-                      account_details['kind'],
-                      account_details.get('name', '(un-named)'))
-        account.startSync(self)
-        self.active_accounts.append(account)
+      if not self.options.protocols or kind in self.options.protocols:
+        if kind in proto.protocols:
+          account = proto.protocols[kind](self.db, account_details)
+          self.log.info('Starting sync of %s account: %s',
+                        kind, account_details.get('name', '(un-named)'))
+          account.startSync(self)
+          self.active_accounts.append(account)
+        else:
+          self.log.error("Don't know what to do with account kind: %s", kind)
       else:
-        log.error("Don't know what to do with account kind: %s",
-                  account_details['kind'])
+          self.log.info("Skipping account - protocol '%s' is disabled", kind)
 
   def accountFinishedSync(self, account):
     self.log.debug("Account %s reports it has finished", account)
     assert account in self.active_accounts, (account, self.active_accounts)
     self.active_accounts.remove(account)
     if not self.active_accounts:
       self.log.info("sync has finished; stopping reactor")
       return reactor.stop()