mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
[refactor][uorb-graph] add a pythonic __main__ idiom to the uorb-graph tool script
This commit is contained in:
committed by
Lorenz Meier
parent
aef3c474e2
commit
8c87ef4272
@@ -581,41 +581,42 @@ class OutputJSON(object):
|
|||||||
json.dump(data, outfile) # add indent=2 for readable formatting
|
json.dump(data, outfile) # add indent=2 for readable formatting
|
||||||
|
|
||||||
|
|
||||||
|
if "__main__" == __name__:
|
||||||
|
|
||||||
# ignore topics that are subscribed/published by many topics, but are not really
|
# ignore topics that are subscribed/published by many topics, but are not really
|
||||||
# useful to show in the graph
|
# useful to show in the graph
|
||||||
topic_blacklist = [ 'parameter_update', 'mavlink_log', 'log_message' ]
|
topic_blacklist = [ 'parameter_update', 'mavlink_log', 'log_message' ]
|
||||||
print('Excluded topics: '+str(topic_blacklist))
|
print('Excluded topics: '+str(topic_blacklist))
|
||||||
|
|
||||||
if len(args.modules) == 0:
|
if len(args.modules) == 0:
|
||||||
module_whitelist = []
|
module_whitelist = []
|
||||||
else:
|
else:
|
||||||
module_whitelist = [ m.strip() for m in args.modules.split(',')]
|
module_whitelist = [ m.strip() for m in args.modules.split(',')]
|
||||||
|
|
||||||
graph = Graph(module_whitelist=module_whitelist, topic_blacklist=topic_blacklist)
|
graph = Graph(module_whitelist=module_whitelist, topic_blacklist=topic_blacklist)
|
||||||
if len(args.src_path) == 0:
|
if len(args.src_path) == 0:
|
||||||
args.src_path = ['src']
|
args.src_path = ['src']
|
||||||
graph.build(args.src_path, args.exclude_path, use_topic_pubsub_union=args.use_topic_union)
|
|
||||||
|
|
||||||
|
graph.build(args.src_path, args.exclude_path, use_topic_pubsub_union=args.use_topic_union)
|
||||||
|
|
||||||
if args.output == 'json':
|
if args.output == 'json':
|
||||||
output_json = OutputJSON(graph)
|
output_json = OutputJSON(graph)
|
||||||
output_json.write(args.file+'.json')
|
output_json.write(args.file+'.json')
|
||||||
|
|
||||||
elif args.output == 'graphviz':
|
elif args.output in ('graphviz','gv'):
|
||||||
try:
|
try:
|
||||||
from graphviz import Digraph
|
from graphviz import Digraph
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print("Failed to import graphviz: " + e)
|
print("Failed to import graphviz: " + e)
|
||||||
print("")
|
print("")
|
||||||
print("You may need to install it with:")
|
print("You may need to install it with:")
|
||||||
print(" pip3 install --user graphviz")
|
print(" pip3 install --user graphviz")
|
||||||
print("")
|
print("")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
output_graphviz = OutputGraphviz(graph)
|
output_graphviz = OutputGraphviz(graph)
|
||||||
engine='fdp' # use neato or fdp
|
engine='fdp' # use neato or fdp
|
||||||
output_graphviz.write(args.file+'.fv', engine=engine)
|
output_graphviz.write(args.file+'.fv', engine=engine)
|
||||||
output_graphviz.write(args.file+'_subs.fv', show_publications=False, engine=engine)
|
output_graphviz.write(args.file+'_subs.fv', show_publications=False, engine=engine)
|
||||||
output_graphviz.write(args.file+'_pubs.fv', show_subscriptions=False, engine=engine)
|
output_graphviz.write(args.file+'_pubs.fv', show_subscriptions=False, engine=engine)
|
||||||
else:
|
else:
|
||||||
print('Error: unknown output format '+args.output)
|
print('Error: unknown output format '+args.output)
|
||||||
|
|||||||
Reference in New Issue
Block a user