--- a/fixbot/api.py Mon Sep 15 00:31:12 2008 +0300
+++ b/fixbot/api.py Mon Sep 15 00:53:59 2008 +0300
@@ -1,5 +1,6 @@
+from twisted.application import internet, service
from twisted.internet import protocol, reactor
-from twisted.python import log
+from twisted.python import log, usage
from datetime import datetime
import sys
@@ -172,16 +173,8 @@
protocol = ClientProtocol
def __init__ (self) :
- log.msg("Connecting to %s:%d" % (SERVER_HOST, PORT))
- reactor.connectTCP(SERVER_HOST, PORT, self)
-
self.connection = None
- def run (self) :
- log.startLogging(sys.stderr)
-
- reactor.run()
-
def connected (self, connection) :
log.msg("Connected!")
self.connection = connection
@@ -209,4 +202,27 @@
def __init__ (self, nexus) :
self.nexus = nexus
-
+
+class ClientOptions (usage.Options) :
+ optParameters = [
+ ( "api-server", "s", "127.0.0.1", "address of API server to connect to" ),
+ ( "api-port", "P", 34888, "port of API server to connect to", int ),
+ ]
+
+ optFlags = [
+
+ ]
+
+def makeService (client_module_factory, config) :
+ s = service.MultiService()
+
+ # the API client
+ module_factory = client_module_factory()
+
+ log.msg("Connecting to API server on [%s:%d]" % (config['api-server'], config['api-port']))
+ api_client = internet.TCPClient(config['api-server'], config['api-port'], module_factory)
+
+ api_client.setServiceParent(s)
+
+ return s
+