From b3b43c361a36e65a3e16385e5d84a9e24539a6ed Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Thu, 5 Sep 2013 20:05:10 +0200 Subject: [PATCH] [tv] recup_sap.py ++ on a l'info du groupe --- tv/recup_sap.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tv/recup_sap.py b/tv/recup_sap.py index 4a489ac1..b17a8097 100755 --- a/tv/recup_sap.py +++ b/tv/recup_sap.py @@ -19,6 +19,7 @@ mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) service={} +service_simple={} start=time.time() while True: @@ -28,17 +29,24 @@ while True: ip=None for line in msg[:-1]: (tag, value) = line.split('=', 1) + print (tag, value) if tag=='s': s=value if tag=='c': ip=value.split(' ')[2].split('/')[0] - service[s]=ip - print "%s: %s" % (s, ip) + if tag=='a' and value.startswith('x-plgroup:'): + group=value[10:] + service_simple[s]=ip + try: + service[group][s]=ip + except KeyError: + service[group]={s:ip} +# print "%s: %s" % (s, ip) if time.time() - start > timeout: break f=open(path, 'w') -l=service.items() +l=service_simple.items() l.sort() for (name, ip) in l: f.write("%s:%s\n" % (name, ip))