Alex Monk has uploaded a new change for review. https://gerrit.wikimedia.org/r/240939
Change subject: tcpircbot: Allow per-infile channel lists ...................................................................... tcpircbot: Allow per-infile channel lists Change-Id: If56a29a972f125f2886ed1669e2701746a08b99d --- M modules/tcpircbot/files/tcpircbot.py M modules/tcpircbot/manifests/instance.pp M modules/tcpircbot/templates/tcpircbot.json.erb 3 files changed, 18 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/39/240939/1 diff --git a/modules/tcpircbot/files/tcpircbot.py b/modules/tcpircbot/files/tcpircbot.py index 0525b7f..b2a94c9 100755 --- a/modules/tcpircbot/files/tcpircbot.py +++ b/modules/tcpircbot/files/tcpircbot.py @@ -21,7 +21,7 @@ "cidr": "::/0", "port": 9125 }, - "infiles": [] + "infiles": {"filename": ["#channel1", "#channel2"]} } Requirements: @@ -60,7 +60,7 @@ logging.basicConfig(level=logging.INFO, stream=sys.stderr, format='%(asctime)-15s %(message)s') -files = [] +files = {} class ForwarderBot(ircbot.SingleServerIRCBot): @@ -93,10 +93,13 @@ if 'infiles' in config: global files - for infile in config['infiles']: - f = open(infile, 'r') + for filename, channels in config['infiles'].items(): + f = open(filename, 'r') f.seek(0, 2) - files.append(f) + if isinstance(channels, list): + files[f] = channels + else: + files[f] = [channels] if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'): @@ -121,10 +124,10 @@ server.bind((config['tcp'].get('iface', ''), config['tcp']['port'])) server.listen(config['tcp']['max_clients']) - files.append(server) + files[server] = None def close_sockets(): - for f in files: + for f in files.keys(): try: f.close() except socket.error: @@ -147,7 +150,7 @@ return ip.is_private() or ip.is_loopback() while 1: - readable, _, _ = select.select([bot.connection.socket] + files, [], []) + readable, _, _ = select.select([bot.connection.socket] + files.keys(), [], []) for f in readable: if f is server: conn, addr = server.accept() @@ -156,14 +159,14 @@ continue conn.setblocking(0) logging.info('Connection from %s', addr) - files.append(conn) + files[conn] = None elif f is bot.connection.socket: bot.connection.process_data() elif isinstance(f, file): data = f.readline().rstrip() if data: - logging.info('infile: %s', data) - for channel in bot.target_channels: + logging.info('infile for %s: %s', ', '.join(files[f]), data) + for channel in files[f]: bot.connection.privmsg(channel, data) else: data = f.recv(BUFSIZE) @@ -174,4 +177,4 @@ bot.connection.privmsg(channel, data) else: f.close() - files.remove(f) + del files[f] diff --git a/modules/tcpircbot/manifests/instance.pp b/modules/tcpircbot/manifests/instance.pp index dfe934b..ad04268 100644 --- a/modules/tcpircbot/manifests/instance.pp +++ b/modules/tcpircbot/manifests/instance.pp @@ -31,7 +31,8 @@ # Example: ['192.0.2.0/24', '2001:db8::/32'] # # [*infiles*] -# Read these files as extra inputs. Optional. +# Read these files as extra inputs. Keys are filenames and values are +# either channel names or arrays of channel names. Optional. # # [*ssl*] # Whether to use SSL to connect to IRC server (default: true). diff --git a/modules/tcpircbot/templates/tcpircbot.json.erb b/modules/tcpircbot/templates/tcpircbot.json.erb index 003ce8c..d14fc67 100755 --- a/modules/tcpircbot/templates/tcpircbot.json.erb +++ b/modules/tcpircbot/templates/tcpircbot.json.erb @@ -5,7 +5,7 @@ <% if @ssl %>"ssl": true,<% end %> "nickname": "<%= @nickname %>" }, - <% if @infiles %>"infiles": <%= Array(@infiles).to_pson %>,<% end %> + <% if @infiles %>"infiles": <%= Hash(@infiles).to_pson %>,<% end %> "tcp": { "max_clients": <%= @max_clients %>, <% if @cidr %>"cidr": <%= Array(@cidr).to_pson %>,<% end %> -- To view, visit https://gerrit.wikimedia.org/r/240939 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If56a29a972f125f2886ed1669e2701746a08b99d Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Alex Monk <kren...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits