Added check for disabled autoupdater and branch

This commit is contained in:
Simon Wüllhorst 2016-01-08 17:24:41 +01:00
parent 1d66bb7418
commit 330e78c85f
4 changed files with 38 additions and 7 deletions

View file

@ -4,7 +4,7 @@
import json, urllib
from graph import Graph
class DomainSelector:
def __init__(self, nodesFile, graphFile, dataPath = './', printStatus = False, targets = None):
def __init__(self, nodesFile, graphFile, dataPath = './', printStatus = False, targets = None, branch = 'stable'):
self.printStatus = printStatus
self.targets = targets
self.nodesData = self.__getFile__(nodesFile)
@ -18,7 +18,7 @@ class DomainSelector:
else:
nodes = {}
for k,v in self.targets.iteritems():
nodes = self.graph.getNodeCloudsIn(v)
nodes = self.graph.getNodeCloudsIn(v,branch)
self.writeConfigFiles(nodes,k)
self.writeDumpFile(nodes,k)
nodes = {}

View file

@ -21,7 +21,7 @@ class Graph:
def parseNodes(self):
for k,v in self.nodes['nodes'].iteritems():
lat, lon = self.getGeo(k)
node = Node(k, ipv6 = self.getPublicAddress(k), hostname = self.getHostname(k), isOnline = self.getOnlineState(k), lat=lat, lon=lon, coder = self.coder)
node = Node(k, ipv6 = self.getPublicAddress(k), hostname = self.getHostname(k), isOnline = self.getOnlineState(k), lat=lat, lon=lon, coder = self.coder, autoupdater = self.getAutoupdaterStatus(k), branch = self.getBranch(k))
self.nodes_list[k] = node
def parseLinks(self):
@ -73,6 +73,22 @@ class Graph:
def getHostname(self,node_id):
return self.nodes['nodes'][node_id]['nodeinfo']['hostname']
def getAutoupdaterStatus(self, node_id):
#return True
if 'autoupdater' in self.nodes['nodes'][node_id]['nodeinfo']['software']:
return self.nodes['nodes'][node_id]['nodeinfo']['software']['autoupdater']['enabled']
else:
#if node is offline for a long time sometimes no autoupdater status can be found
return False
def getBranch(self, node_id):
#return True
if 'autoupdater' in self.nodes['nodes'][node_id]['nodeinfo']['software']:
return self.nodes['nodes'][node_id]['nodeinfo']['software']['autoupdater']['branch']
else:
#if node is offline for a long time sometimes no autoupdater status can be found
return None
def getGeo(self, node_id):
if 'location' in self.nodes['nodes'][node_id]['nodeinfo'] and 'latitude' in self.nodes['nodes'][node_id]['nodeinfo']['location'] and 'longitude' in self.nodes['nodes'][node_id]['nodeinfo']['location']:
return self.nodes['nodes'][node_id]['nodeinfo']['location']['latitude'], self.nodes['nodes'][node_id]['nodeinfo']['location']['longitude']
@ -90,12 +106,16 @@ class Graph:
return self.nodes['nodes'][node_id]['flags']['online']
def getNodeCloudsIn(self, region):
def getNodeCloudsIn(self, region, branch = 'stable'):
results = {}
for k,v in self.getAllLevelXNodes(0).iteritems():
if v.geodata != None and v.isOnline == True:
if v.isInRegion(region):
results.update(v.getNodeCloud({}))
for ksub,vsub in v.getNodeCloud({}).iteritems():
if not vsub.autoupdater or vsub.branch != branch:
break
else:
results.update(v.getNodeCloud({}))
print "Result:",len(results), region
return results

View file

@ -4,7 +4,7 @@ from geocode import Geocode
import time
class Node(object):
def __init__(self, nodeid, ipv6 = None, hostname = None, isOnline = False, lastSeen = None, lat = None, lon = None, coder = None):
def __init__(self, nodeid, ipv6 = None, hostname = None, isOnline = False, lastSeen = None, lat = None, lon = None, coder = None, autoupdater = False, branch = None):
self.coder = coder
if self.coder == None:
self.coder = Geocode(geocoderCache = True, printStatus = True)
@ -15,6 +15,8 @@ class Node(object):
self.stepsToVpn = -1
self.isOnline = isOnline
self.lastSeen = lastSeen
self.autoupdater = autoupdater
self.branch = branch
self._geo = None
self.geodata = None
if lat != None and lon != None:

View file

@ -68,8 +68,17 @@ targets = {
{'village' : u'Südlohn'},
{'town' : u'Velen'},
{'town' : u'Vreden'},
],
'sassenberg' : [
{'town' : u'Sassenberg'},
],
'telgte' : [
{'town' : u'Telgte'},
],
'warendorf_stadt' : [
{'town' : u'Warendorf'},
]
}
#ds = DomainSelector(nodesFile = 'nodes.json', graphFile = 'graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets)
ds = DomainSelector(nodesFile = 'https://freifunk-muensterland.de/map/data/nodes.json', graphFile = 'https://freifunk-muensterland.de/map/data/graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets)
ds = DomainSelector(nodesFile = 'https://freifunk-muensterland.de/map/data/nodes.json', graphFile = 'https://freifunk-muensterland.de/map/data/graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets, branch = 'stable')