view service/tomatoWifi/dhcpparse.py @ 971:fbe72d44f15a

only recompile if the C code is new. redo Device class api. single temperature sensor is working Ignore-this: e78106d25dbb2ac8c5e5d8a81d576358 darcs-hash:20150411084359-312f9-7c50d2f4f21dd9d5a0fa8913873a1e6d7d325118
author drewp <drewp@bigasterisk.com>
date Sat, 11 Apr 2015 01:43:59 -0700
parents d9bc9a82dcca
children
line wrap: on
line source

def addDhcpData(rows):
    """given dicts with 'mac', add other data from the dhcp cache"""
    currentLease = None
    for line in open('/var/lib/dhcp/dhcpd.leases'):
        if line.startswith('lease '):
            currentLease = {'ip': line.split()[1]}
        elif line.startswith('  hardware ethernet '):
            currentLease['mac'] = line.split()[2].strip(';').upper()
        elif line.startswith('  client-hostname'):
            currentLease['clientHostname'] = line.split(None, 2)[1].strip('";')
        elif line.startswith('  binding state'):
            currentLease['bindingState'] = line.split()[2].strip(';')
        elif line.startswith('}'):
            if currentLease.get('bindingState') == 'active':
                # there seem to be a lot of 'active' blocks
                # for the same ip addr and mac. I haven't
                # looked into whether they hold different
                # lease terms or what
                for r in rows:
                    if r['mac'] == currentLease['mac']:
                        r.update(currentLease)