mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
fix doc graph generator and add a data flow graph
This commit is contained in:
parent
6454fa224d
commit
312366434d
2 changed files with 106 additions and 60 deletions
|
@ -1,69 +1,114 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
# -*-coding:UTF-8 -*
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
content = ""
|
def main():
|
||||||
modules = {}
|
|
||||||
all_modules = []
|
|
||||||
curr_module = ""
|
|
||||||
streamingPub = {}
|
|
||||||
streamingSub = {}
|
|
||||||
|
|
||||||
path = os.path.join(os.environ['AIL_BIN'], 'packages/modules.cfg')
|
content = ""
|
||||||
path2 = os.path.join(os.environ['AIL_HOME'], 'doc/all_modules.txt')
|
modules = {}
|
||||||
with open(path, 'r') as f:
|
all_modules = []
|
||||||
for line in f:
|
curr_module = ""
|
||||||
if line[0] != '#':
|
streamingPub = {}
|
||||||
if line[0] == '[':
|
streamingSub = {}
|
||||||
curr_name = line.replace('[','').replace(']','').replace('\n', '').replace(' ', '')
|
|
||||||
all_modules.append(curr_name)
|
|
||||||
modules[curr_name] = {'sub': [], 'pub': []}
|
|
||||||
curr_module = curr_name
|
|
||||||
elif curr_module != "": # searching for sub or pub
|
|
||||||
if line.startswith("subscribe"):
|
|
||||||
curr_subscribers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')]
|
|
||||||
modules[curr_module]['sub'] = curr_subscribers
|
|
||||||
for sub in curr_subscribers:
|
|
||||||
streamingSub[sub] = curr_module
|
|
||||||
|
|
||||||
elif line.startswith("publish"):
|
path = os.path.join(os.environ['AIL_BIN'], 'packages/modules.cfg') # path to module config file
|
||||||
curr_publishers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')]
|
path2 = os.path.join(os.environ['AIL_HOME'], 'doc/all_modules.txt') # path and name of the output file, this file contain a list off all modules
|
||||||
modules[curr_module]['pub'] = curr_publishers
|
|
||||||
for pub in curr_publishers:
|
|
||||||
streamingPub[pub] = curr_module
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
output_set_graph = set()
|
|
||||||
with open(path2, 'w') as f2:
|
|
||||||
for e in all_modules:
|
|
||||||
f2.write(e+"\n")
|
|
||||||
|
|
||||||
for module in modules.keys():
|
|
||||||
for stream_in in modules[module]['sub']:
|
|
||||||
if stream_in not in streamingPub.keys():
|
|
||||||
output_set_graph.add("\"" + stream_in + "\" [color=darkorange1] ;\n")
|
|
||||||
output_set_graph.add("\"" + stream_in + "\"" + "->" + module + ";\n")
|
|
||||||
else:
|
|
||||||
output_set_graph.add("\"" + streamingPub[stream_in] + "\"" + "->" + module + ";\n")
|
|
||||||
|
|
||||||
for stream_out in modules[module]['pub']:
|
|
||||||
if stream_out not in streamingSub.keys():
|
|
||||||
output_set_graph.add("\"" + stream_out + "\" [color=darkorange1] ;\n")
|
|
||||||
output_set_graph.add("\"" + stream_out + "\"" + "->" + module + ";\n")
|
|
||||||
else:
|
|
||||||
output_set_graph.add("\"" + module + "\"" + "->" + streamingSub[stream_out] + ";\n")
|
|
||||||
|
|
||||||
|
|
||||||
output_text_graph = ""
|
parser = argparse.ArgumentParser(
|
||||||
output_text_graph += "digraph unix {\n"\
|
description='''This script is a part of the Analysis Information Leak
|
||||||
"graph [pad=\"0.5\"];\n"\
|
framework. It create a graph that represent the flow between modules".''',
|
||||||
"size=\"25,25\";\n"\
|
epilog='Example: ./generate_graph_data.py 0')
|
||||||
"node [color=lightblue2, style=filled];\n"
|
|
||||||
|
|
||||||
for elem in output_set_graph:
|
parser.add_argument('type', type=int, default=0,
|
||||||
output_text_graph += elem
|
help='''The graph type (default 0),
|
||||||
|
0: module graph,
|
||||||
|
1: data graph''',
|
||||||
|
choices=[0, 1], action='store')
|
||||||
|
|
||||||
output_text_graph += "}"
|
args = parser.parse_args()
|
||||||
print(output_text_graph)
|
|
||||||
|
with open(path, 'r') as f:
|
||||||
|
|
||||||
|
# get all modules, subscriber and publisher for each module
|
||||||
|
for line in f:
|
||||||
|
if line[0] != '#':
|
||||||
|
# module name
|
||||||
|
if line[0] == '[':
|
||||||
|
curr_name = line.replace('[','').replace(']','').replace('\n', '').replace(' ', '')
|
||||||
|
all_modules.append(curr_name)
|
||||||
|
modules[curr_name] = {'sub': [], 'pub': []}
|
||||||
|
curr_module = curr_name
|
||||||
|
elif curr_module != "": # searching for sub or pub
|
||||||
|
# subscriber list
|
||||||
|
if line.startswith("subscribe"):
|
||||||
|
curr_subscribers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')]
|
||||||
|
modules[curr_module]['sub'] = curr_subscribers
|
||||||
|
for sub in curr_subscribers:
|
||||||
|
streamingSub[sub] = curr_module
|
||||||
|
|
||||||
|
# publisher list
|
||||||
|
elif line.startswith("publish"):
|
||||||
|
curr_publishers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')]
|
||||||
|
modules[curr_module]['pub'] = curr_publishers
|
||||||
|
for pub in curr_publishers:
|
||||||
|
streamingPub[pub] = curr_module
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
output_set_graph = set()
|
||||||
|
with open(path2, 'w') as f2:
|
||||||
|
for e in all_modules:
|
||||||
|
f2.write(e+"\n")
|
||||||
|
|
||||||
|
# flow between modules
|
||||||
|
if args.type == 0:
|
||||||
|
|
||||||
|
for module in modules.keys():
|
||||||
|
for stream_in in modules[module]['sub']:
|
||||||
|
if stream_in not in streamingPub.keys():
|
||||||
|
output_set_graph.add("\"" + stream_in + "\" [color=darkorange1] ;\n")
|
||||||
|
output_set_graph.add("\"" + stream_in + "\"" + "->" + module + ";\n")
|
||||||
|
else:
|
||||||
|
output_set_graph.add("\"" + streamingPub[stream_in] + "\"" + "->" + module + ";\n")
|
||||||
|
|
||||||
|
for stream_out in modules[module]['pub']:
|
||||||
|
if stream_out not in streamingSub.keys():
|
||||||
|
#output_set_graph.add("\"" + stream_out + "\" [color=darkorange1] ;\n")
|
||||||
|
output_set_graph.add("\"" + module + "\"" + "->" + stream_out + ";\n")
|
||||||
|
else:
|
||||||
|
output_set_graph.add("\"" + module + "\"" + "->" + streamingSub[stream_out] + ";\n")
|
||||||
|
|
||||||
|
output_text_graph = ""
|
||||||
|
|
||||||
|
# flow between data
|
||||||
|
if args.type == 1:
|
||||||
|
|
||||||
|
for module in modules.keys():
|
||||||
|
for stream_in in modules[module]['sub']:
|
||||||
|
for stream_out in modules[module]['pub']:
|
||||||
|
|
||||||
|
if stream_in not in streamingPub.keys():
|
||||||
|
output_set_graph.add("\"" + stream_in + "\" [color=darkorange1] ;\n")
|
||||||
|
|
||||||
|
output_set_graph.add("\"" + stream_in + "\"" + "->" + stream_out + ";\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# graph head
|
||||||
|
output_text_graph += "digraph unix {\n"\
|
||||||
|
"graph [pad=\"0.5\"];\n"\
|
||||||
|
"size=\"25,25\";\n"\
|
||||||
|
"node [color=lightblue2, style=filled];\n"
|
||||||
|
|
||||||
|
# create final txt graph
|
||||||
|
for elem in output_set_graph:
|
||||||
|
output_text_graph += elem
|
||||||
|
|
||||||
|
output_text_graph += "}"
|
||||||
|
print(output_text_graph)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
python $AIL_HOME/doc/generate_graph_data.py | dot -T png -o $AIL_HOME/doc/module-data-flow.png
|
python3 $AIL_HOME/doc/generate_graph_data.py 0 | dot -T png -o $AIL_HOME/doc/module-data-flow.png
|
||||||
|
python3 $AIL_HOME/doc/generate_graph_data.py 1 | dot -T png -o $AIL_HOME/doc/data-flow.png
|
||||||
|
|
Loading…
Reference in a new issue