You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2012/03/07 03:57:06 UTC

svn commit: r1297845 - /subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py

Author: gstein
Date: Wed Mar  7 02:57:06 2012
New Revision: 1297845

URL: http://svn.apache.org/viewvc?rev=1297845&view=rev
Log:
Switch the client over to the new client code based on asyncore.

This is a minimal-impact change to make it more obvious what has
changed. A future revision will clear out all of the Twisted code, and
then tighten things up.

* tools/server-side/svnpubsub/svnwcsub.py:
  (BigDoEverythingClasss._restartStream): disable twisted-based
    connection setup.
  (run_client): new function to construct a MultiClient and then start
    it up, looking for updates.
  (_commit): wrapper around the BDEC's commit callback. we need to
    remap the stream and tweak the Revision object
  (_event): basic callback to log various events from the MultiClient
  (Daemon.run): use run_client() rather than the Twisted reactor

Modified:
    subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py

Modified: subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py?rev=1297845&r1=1297844&r2=1297845&view=diff
==============================================================================
--- subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py (original)
+++ subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py Wed Mar  7 02:57:06 2012
@@ -39,7 +39,9 @@ import time
 import logging.handlers
 import Queue
 import optparse
+import functools
 
+### these will go away shortly
 from twisted.internet import reactor
 from twisted.application import internet
 from twisted.web.client import HTTPClientFactory, HTTPPageDownloader
@@ -47,6 +49,7 @@ from urlparse import urlparse
 from xml.sax import handler, make_parser
 
 import daemonize
+import svnpubsub.client
 
 # check_output() is only available in Python 2.7. Allow us to run with
 # earlier versions
@@ -229,6 +232,7 @@ class BigDoEverythingClasss(object):
             WorkingCopy(self, path, url)
 
     def _restartStream(self, url):
+        return
         (self.streams[url], self.transports[url]) = connectTo(url, self)
 
     def wc_ready(self, wc):
@@ -264,6 +268,33 @@ class BigDoEverythingClasss(object):
                 self.worker.add_work(OP_UPDATE, wc)
 
 
+### hack in support for the MultiClient.
+def run_client(bdec):
+    hostports = [ ]
+    for url in bdec.urls:
+        parsed = urlparse(url)
+        hostports.append((parsed.hostname, parsed.port))
+
+    mc = svnpubsub.client.MultiClient(hostports,
+                                      functools.partial(_commit, bdec),
+                                      _event)
+    mc.run_forever()
+
+def _commit(bdec, host, port, rev):
+    class _stream(object):
+        url = '%s:%s' % (host, port)
+    rev.repos = rev.uuid  ### quick little hack
+    bdec.commit(_stream, rev)
+
+def _event(host, port, event_name):
+    if event_name == 'error':
+        logging.exception('from %s:%s', host, port)
+    elif event_name == 'ping':
+        logging.debug('ping from %s:%s', host, port)
+    else:
+        logging.info('"%s" from %s:%s', event_name, host, port)
+
+
 # Start logging warnings if the work backlog reaches this many items
 BACKLOG_TOO_HIGH = 20
 OP_UPDATE = 'update'
@@ -406,7 +437,8 @@ class Daemon(daemonize.Daemon):
     def run(self):
         # Start the BDEC (on the main thread), then start up twisted
         self.bdec.start()
-        reactor.run()
+        #reactor.run()
+        run_client(self.bdec)
 
 
 def prepare_logging(logfile):