Mercurial > code > home > repos > homeauto
diff service/tomatoWifi/wifi.py @ 51:d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
Ignore-this: dc012ad1d539d3a1c37c779e63c8cf4b
author | drewp@bigasterisk.com |
---|---|
date | Mon, 31 Dec 2012 15:01:04 -0800 |
parents | 0ab069867c64 |
children | 875a37be1228 |
line wrap: on
line diff
--- a/service/tomatoWifi/wifi.py Mon Dec 31 14:15:33 2012 -0800 +++ b/service/tomatoWifi/wifi.py Mon Dec 31 15:01:04 2012 -0800 @@ -1,8 +1,14 @@ -import re, ast, restkit, logging, socket +import re, ast, logging, socket +from twisted.internet.defer import inlineCallbacks, returnValue +from cyclone.httpclient import fetch from rdflib import Literal, Graph log = logging.getLogger() +class Router(object): + def __repr__(self): + return repr(self.__dict__) + class Wifi(object): """ gather the users of wifi from the tomato routers @@ -37,12 +43,14 @@ for k, v in repl.items(): url = url.replace(k, v) - r = restkit.Resource(url, timeout=2) + r = Router() + r.url = url.replace('root:admin@', '') + r.headers = {'Authorization': ['Basic cm9vdDphZG1pbg==']} r.name = {'tomato1' : 'bigasterisk3', 'tomato2' : 'bigasterisk4'}[name.split('/')[1]] self.routers.append(r) - + @inlineCallbacks def getPresentMacAddrs(self): aboutIp = {} byMac = {} # mac : [ip] @@ -50,7 +58,8 @@ for router in self.routers: log.debug("GET %s", router) try: - data = router.get().body_string() + data = yield fetch(router.url, headers=router.headers, + timeout=2) except socket.error: log.warn("get on %s failed" % router) continue @@ -62,7 +71,7 @@ mac=mac, iface=iface, )) - + byMac.setdefault(mac, set()).add(ip) for (name, ip, mac, lease) in jsValue(data, 'dhcpd_lease'): @@ -74,9 +83,9 @@ mac=mac, lease=lease )) - + byMac.setdefault(mac, set()).add(ip) - + for iface, mac, signal in jsValue(data, 'wldev'): matched = False for addr in aboutIp.values(): @@ -102,7 +111,7 @@ addr['name'] = 'unknown' ret.append(addr) - return ret + returnValue(ret) def jsValue(js, variableName):