Split common connect routine into a module.
authorTim Potter <tpot@hp.com>
Tue, 8 Apr 2008 06:38:56 +0000 (16:38 +1000)
committerTim Potter <tpot@hp.com>
Tue, 8 Apr 2008 06:38:56 +0000 (16:38 +1000)
bbclient.py [new file with mode: 0644]
gbuildbotclient

diff --git a/bbclient.py b/bbclient.py
new file mode 100644 (file)
index 0000000..25e75b0
--- /dev/null
@@ -0,0 +1,44 @@
+from twisted.internet import reactor
+from twisted.cred import credentials
+from twisted.spread import pb
+from twisted.python import log
+
+class BuildbotClient:
+    """A class to manage a remote connection to the buildbot server."""
+
+    def __init__(self):
+
+        self.builders = {}
+        self.remote = None
+        
+    def connect(self, host, port, username, password):
+
+        cf = pb.PBClientFactory()
+        creds = credentials.UsernamePassword(username, password)
+
+        d = cf.login(creds)
+        reactor.connectTCP(host, port, cf)
+
+        d.addCallbacks(self.connected, lambda arg: log.err(arg))
+        
+        log.msg('connecting to %s:%d as %s' % (host, port, username))
+
+        return d
+
+    def connected(self, ref):
+
+        log.msg('connected')
+
+        # Remote reference is a StatusClientPerspective object.
+
+        self.remote = ref
+        self.remote.notifyOnDisconnect(self.disconnected)
+
+    def disconnected(self, ref):
+
+        log.msg('disconnected')
+
+        ref = None        
+
+    def subscribe(self, mode, interval, target):
+        return self.remote.callRemote('subscribe', mode, interval, target)
index a1fc016..017c857 100755 (executable)
@@ -19,47 +19,7 @@ from twisted.internet import reactor
 from twisted.spread import pb
 from twisted.cred import credentials
 from twisted.python import log
-
-# A class to manage the remote connection to the buildbot server
-
-class BuildbotClient:
-
-    def __init__(self):
-
-        self.builders = {}
-        self.remote = None
-        
-    def connect(self, host, port, username, password):
-
-        cf = pb.PBClientFactory()
-        creds = credentials.UsernamePassword(username, password)
-
-        d = cf.login(creds)
-        reactor.connectTCP(host, port, cf)
-
-        d.addCallbacks(self.connected, lambda arg: log.err(arg))
-        
-        log.msg('connecting to %s:%d as %s' % (host, port, username))
-
-        return d
-
-    def connected(self, ref):
-
-        log.msg('connected')
-
-        # Remote reference is a StatusClientPerspective object.
-
-        self.remote = ref
-        self.remote.notifyOnDisconnect(self.disconnected)
-
-    def disconnected(self, ref):
-
-        log.msg('disconnected')
-
-        ref = None        
-
-    def subscribe(self, mode, interval, target):
-        return self.remote.callRemote('subscribe', mode, interval, target)
+from bbclient import BuildbotClient
 
 # Application class
 
@@ -169,6 +129,7 @@ class App(pb.Referenceable):
         self.model.set_value(iter, self.COL_BUILDER, builder)
         self.model.set_value(iter, self.COL_BUILDER_NAME, buildername)
         self.model.set_value(iter, self.COL_BUILDER_BUILD_ETA_TEXT, 'n/a')
+
     def remote_builderRemoved(self, buildername):
         """Called by the PB server when a builder has been removed from the
         buildbot."""