Victor Vasiliev has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/53003


Change subject: Load configuration from file.
......................................................................

Load configuration from file.

Change-Id: Idf294b9edf960f9544b319b79d3d2d207a14294f
---
A config.json.example
M rcsub.py
2 files changed, 21 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/rcsub 
refs/changes/03/53003/1

diff --git a/config.json.example b/config.json.example
new file mode 100644
index 0000000..b9e9dba
--- /dev/null
+++ b/config.json.example
@@ -0,0 +1,6 @@
+{
+    "input_port" : 12719,
+    "websocket_port" : 13719,
+    "text_port" : 14719,
+    "max_channels" : 100
+}
diff --git a/rcsub.py b/rcsub.py
index adbef3b..9de20bb 100644
--- a/rcsub.py
+++ b/rcsub.py
@@ -1,18 +1,19 @@
 #!/usr/bin/python
 
-import json
+import json, sys
 
 from twisted.internet import reactor
 from twisted.internet.protocol import DatagramProtocol, ServerFactory
 from twisted.protocols.basic import LineReceiver
 from autobahn.websocket import WebSocketServerFactory, 
WebSocketServerProtocol, listenWS
 
-config = {
-    'input_port' : 12719,
-    'websocket_port' : 13719,
-    'text_port' : 14719,
-    'max_channels' : 100,
-}
+
+class Configuration(object):
+    def __init__(self, filename):
+        self.filename = filename
+        configFile = open(filename)
+        configData = json.load(configFile)
+        self.__dict__.update(configData)
 
 class MessageRouter(object):
     def __init__(self):
@@ -39,8 +40,8 @@
         self.channels = []
 
     def subscribe(self, channel):
-        if len(self.channels) >= config['max_channels']:
-            raise ProtocolError('Exceeded maximum subscription limit of %i 
channels' % config['max_channels'])
+        if len(self.channels) >= config.max_channels:
+            raise ProtocolError('Exceeded maximum subscription limit of %i 
channels' % config.max_channels)
         if channel in self.channels:
             raise ProtocolError('You are already subscribed to the channel %s' 
% channel)
 
@@ -138,15 +139,17 @@
     def deliver(self, message):
         self.message(message)
 
-ws_factory = WebSocketServerFactory( "ws://localhost:%i" % 
config['websocket_port'] )
+config = Configuration(sys.argv[1])
+
+ws_factory = WebSocketServerFactory( "ws://localhost:%i" % 
config.websocket_port )
 ws_factory.protocol = WebSocketRCFeed
 listenWS(ws_factory)
 
 st_factory = ServerFactory()
 st_factory.protocol = SimpleTextRCFeed
-reactor.listenTCP(config['text_port'], st_factory)
+reactor.listenTCP(config.text_port, st_factory)
 
-reactor.listenUDP(config['input_port'], MediaWikiRCInput())
+reactor.listenUDP(config.input_port, MediaWikiRCInput())
 
 reactor.run()
 

-- 
To view, visit https://gerrit.wikimedia.org/r/53003
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf294b9edf960f9544b319b79d3d2d207a14294f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/rcsub
Gerrit-Branch: master
Gerrit-Owner: Victor Vasiliev <vasi...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to