From 9250247e57255ab9886fd15107f4f5ec31a0a888 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 6 Sep 2011 14:36:57 +0200 Subject: //Reaktor/IRC: get name from tinc.conf --- Reaktor/IRC/bot2.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'Reaktor') diff --git a/Reaktor/IRC/bot2.py b/Reaktor/IRC/bot2.py index 7365686e..49e8a57f 100755 --- a/Reaktor/IRC/bot2.py +++ b/Reaktor/IRC/bot2.py @@ -85,16 +85,32 @@ class IRCBot(SimpleIRCClient): # TODO reconnect exit(0) +# retrieve the value of a [singleton] variable from a tinc.conf(5)-like file +def getconf1(x, path): + from re import findall + pattern = '(?:^|\n)\s*' + x + '\s*=\s*(.*\w)\s*(?:\n|$)' + y = findall(pattern, open(path, 'r').read()) + if len(y) < 1: + raise AttributeError("len(getconf1('%s', '%s') < 1)" % (x, path)) + if len(y) > 1: + y = ' '.join(y) + raise AttributeError("len(getconf1('%s', '%s') > 1)\n ====> %s" + % (x, path, y)) + return y[0] + def main(): - host = str(env.get('host', 'irc.freenode.org')) + name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf') + host = str(env.get('host', 'supernode')) port = int(env.get('port', 6667)) - nick = str(env.get('nick', 'crabspasm')) + nick = str(env.get('nick', name)) target = str(env.get('target', '#tincspasm')) print('====> irc://%s@%s:%s/%s' % (nick, host, port, target)) client = IRCBot(target) try: - client.connect(host, port, nick) + from getpass import getuser + client.connect(host, port, nick, username=getuser(), + ircname='//Reaktor running at %s.retiolum' % (name)) except ServerConnectionError, error: print(error) exit(1) -- cgit v1.2.3