Updated mechanism for generating output for nodes with disabled autoupdater or no geoinformations
This commit is contained in:
parent
c6a167dde5
commit
fac219a7ac
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -
|
# -*- coding: utf-8 -
|
||||||
#Imports:
|
#Imports:
|
||||||
import json, urllib, os
|
import json, urllib, os, glob
|
||||||
from graph import Graph
|
from graph import Graph
|
||||||
from hieraException import HieraException
|
from hieraException import HieraException
|
||||||
|
|
||||||
|
@ -13,9 +13,11 @@ class DomainSelector:
|
||||||
|
|
||||||
self.printStatus = printStatus
|
self.printStatus = printStatus
|
||||||
self.targets = targets
|
self.targets = targets
|
||||||
|
self.dataPath = dataPath.rstrip('/')
|
||||||
self.nodesData = self.__getFile__(nodesFile)
|
self.nodesData = self.__getFile__(nodesFile)
|
||||||
self.graphData = self.__getFile__(graphFile)
|
self.graphData = self.__getFile__(graphFile)
|
||||||
self.dataPath = dataPath
|
|
||||||
|
self.__prepareOutDir__()
|
||||||
|
|
||||||
self.graph = Graph(self.nodesData, self.graphData)
|
self.graph = Graph(self.nodesData, self.graphData)
|
||||||
if self.targets == None:
|
if self.targets == None:
|
||||||
|
@ -28,8 +30,14 @@ class DomainSelector:
|
||||||
self.writeConfigFiles(nodes,k)
|
self.writeConfigFiles(nodes,k)
|
||||||
self.writeDumpFile(nodes,k)
|
self.writeDumpFile(nodes,k)
|
||||||
nodes = {}
|
nodes = {}
|
||||||
self.writeConfigFiles(self.graph.nodes_no_autoupdater,"no_autoupdater")
|
self.writeConfigFiles(self.graph.getProblemNodes(noAutoupdater = True),"no_autoupdater")
|
||||||
self.writeConfigFiles(self.graph.nodes_no_geo,"no_geo")
|
self.writeConfigFiles(self.graph.getProblemNodes(noGeodata = True),"no_geo")
|
||||||
|
self.writeConfigFiles(self.graph.getProblemNodes(noGeodata = True, noAutoupdater = True),"no_nothing")
|
||||||
|
|
||||||
|
def __prepareOutDir__(self):
|
||||||
|
files = glob.glob(self.dataPath+'/*')
|
||||||
|
for f in files:
|
||||||
|
os.remove(f)
|
||||||
|
|
||||||
def __getFile__(self, nodesFile):
|
def __getFile__(self, nodesFile):
|
||||||
if nodesFile.startswith('https://') or nodesFile.startswith('http://'):
|
if nodesFile.startswith('https://') or nodesFile.startswith('http://'):
|
||||||
|
@ -52,6 +60,7 @@ class DomainSelector:
|
||||||
|
|
||||||
def writeConfigFiles(self, nodes, name):
|
def writeConfigFiles(self, nodes, name):
|
||||||
maxDepth = self.maxDepth(nodes)
|
maxDepth = self.maxDepth(nodes)
|
||||||
|
if len(nodes) > 0:
|
||||||
for i in range(0,maxDepth):
|
for i in range(0,maxDepth):
|
||||||
content = 'geo $switch {\n default 0;'
|
content = 'geo $switch {\n default 0;'
|
||||||
f = open(self.dataPath.rstrip('/')+'/'+name+'_node_level'+str(i),'w')
|
f = open(self.dataPath.rstrip('/')+'/'+name+'_node_level'+str(i),'w')
|
||||||
|
|
38
graph.py
38
graph.py
|
@ -113,25 +113,45 @@ class Graph:
|
||||||
def getOnlineState(self,node_id):
|
def getOnlineState(self,node_id):
|
||||||
return self.nodes['nodes'][node_id]['flags']['online']
|
return self.nodes['nodes'][node_id]['flags']['online']
|
||||||
|
|
||||||
|
def getProblemNodes(self, noAutoupdater = False, noGeodata = False, online = True):
|
||||||
|
results = {}
|
||||||
|
for k,v in self.nodes_list.iteritems():
|
||||||
|
if v.isOnline or online == False:
|
||||||
|
if noAutoupdater and noGeodata:
|
||||||
|
if not v.autoupdater and not v.geodata:
|
||||||
|
results[k] = v
|
||||||
|
elif noAutoupdater:
|
||||||
|
if v.autoupdater and v.geodata:
|
||||||
|
results[k] = v
|
||||||
|
elif noGeodata:
|
||||||
|
if not v.geodata and v.autoupdater:
|
||||||
|
results[k] = v
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def getNodeCloudsIn(self, region, branch = 'stable'):
|
def getNodeCloudsIn(self, region, branch = 'stable'):
|
||||||
results = {}
|
results = {}
|
||||||
noAuto = False
|
# noAuto = False
|
||||||
for k,v in self.getAllLevelXNodes(0).iteritems():
|
for k,v in self.getAllLevelXNodes(0).iteritems():
|
||||||
if v.isOnline == True:
|
if v.isOnline == True:
|
||||||
if v.geodata != None:
|
if v.geodata != None:
|
||||||
if v.isInRegion(region):
|
if v.isInRegion(region):
|
||||||
noAuto = False
|
|
||||||
for ksub,vsub in v.getNodeCloud({}).iteritems():
|
for ksub,vsub in v.getNodeCloud({}).iteritems():
|
||||||
if not vsub.autoupdater or (branch and vsub.branch != branch):
|
if not vsub.autoupdater or (branch and vsub.branch != branch):
|
||||||
#break
|
break
|
||||||
noAuto = True
|
|
||||||
self.nodes_no_autoupdater[ksub] = vsub
|
|
||||||
#else:
|
|
||||||
if not noAuto:
|
|
||||||
results.update(v.getNodeCloud({}))
|
|
||||||
else:
|
else:
|
||||||
self.nodes_no_geo.update(v.getNodeCloud({}))
|
results.update(v.getNodeCloud({}))
|
||||||
|
# noAuto = False
|
||||||
|
# for ksub,vsub in v.getNodeCloud({}).iteritems():
|
||||||
|
# if not vsub.autoupdater or (branch and vsub.branch != branch):
|
||||||
|
# #break
|
||||||
|
# noAuto = True
|
||||||
|
# self.nodes_no_autoupdater[ksub] = vsub
|
||||||
|
# #else:
|
||||||
|
# if not noAuto:
|
||||||
|
# results.update(v.getNodeCloud({}))
|
||||||
|
# else:
|
||||||
|
# self.nodes_no_geo.update(v.getNodeCloud({}))
|
||||||
print "Result:",len(results), region
|
print "Result:",len(results), region
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
|
@ -36,16 +36,8 @@ def prepareTargets(args):
|
||||||
specific_targets[k] = v
|
specific_targets[k] = v
|
||||||
return specific_targets
|
return specific_targets
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print args
|
|
||||||
|
|
||||||
targets = prepareTargets(args)
|
targets = prepareTargets(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ds = DomainSelector(nodesFile = 'nodes.json', graphFile = 'graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets)
|
|
||||||
#ds = DomainSelector(nodesFile = 'https://service.freifunk-muensterland.de/maps/data_legacy/nodes.json', graphFile = 'https://service.freifunk-muensterland.de/maps/data_legacy/graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets, branch = None)
|
|
||||||
try:
|
try:
|
||||||
ds = DomainSelector(nodesFile = args.json_path.rstrip('/')+'/nodes.json', graphFile = args.json_path.rstrip('/')+'/graph.json', printStatus = args.print_status, dataPath = args.out_path, targets = targets, branch = args.only_specific_branch)
|
ds = DomainSelector(nodesFile = args.json_path.rstrip('/')+'/nodes.json', graphFile = args.json_path.rstrip('/')+'/graph.json', printStatus = args.print_status, dataPath = args.out_path, targets = targets, branch = args.only_specific_branch)
|
||||||
except HieraException:
|
except HieraException:
|
||||||
|
|
Loading…
Reference in a new issue