mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
FSM visualisation script: use argparse instead of optionparse and some minor cleanup
This commit is contained in:
+14
-15
@@ -1,15 +1,14 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""draw_fsm_diagram.py: Create dot code from a state transition table
|
"""draw_fsm_diagram.py: Create dot code and dokuwiki table from a state transition table
|
||||||
|
|
||||||
convert dot code to png using graphviz:
|
convert dot code to png using graphviz:
|
||||||
|
|
||||||
dot fsm.dot -Tpng -o fsm.png
|
dot fsm.dot -Tpng -o fsm.png
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from optparse import OptionParser
|
import argparse
|
||||||
import re
|
import re
|
||||||
import subprocess
|
|
||||||
|
|
||||||
__author__ = "Julian Oes"
|
__author__ = "Julian Oes"
|
||||||
|
|
||||||
@@ -27,16 +26,16 @@ def get_dot_footer():
|
|||||||
def main():
|
def main():
|
||||||
|
|
||||||
# parse input arguments
|
# parse input arguments
|
||||||
parser = OptionParser()
|
parser = argparse.ArgumentParser(description='Create dot code and dokuwiki table from a state transition table.')
|
||||||
parser.add_option("-i", "--input-file", default=None, help="choose file to parse")
|
parser.add_argument("-i", "--input-file", default=None, help="choose file to parse")
|
||||||
parser.add_option("-d", "--dot-file", default=None, help="choose file for output dot file")
|
parser.add_argument("-d", "--dot-file", default=None, help="choose file for output dot file")
|
||||||
parser.add_option("-t", "--table-file", default=None, help="choose file for output of table")
|
parser.add_argument("-t", "--table-file", default=None, help="choose file for output of table")
|
||||||
(options, args) = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# open source file
|
# open source file
|
||||||
if options.input_file == None:
|
if args.input_file == None:
|
||||||
exit('please specify file')
|
exit('please specify file')
|
||||||
f = open(options.input_file,'r')
|
f = open(args.input_file,'r')
|
||||||
source = f.read()
|
source = f.read()
|
||||||
|
|
||||||
# search for state transition table and extract the table itself
|
# search for state transition table and extract the table itself
|
||||||
@@ -157,8 +156,8 @@ def main():
|
|||||||
dot_code = get_dot_header() + dot_code + get_dot_footer()
|
dot_code = get_dot_header() + dot_code + get_dot_footer()
|
||||||
|
|
||||||
# write or print dot file
|
# write or print dot file
|
||||||
if options.dot_file:
|
if args.dot_file:
|
||||||
f = open(options.dot_file,'w')
|
f = open(args.dot_file,'w')
|
||||||
f.write(dot_code)
|
f.write(dot_code)
|
||||||
print('Wrote dot file')
|
print('Wrote dot file')
|
||||||
else:
|
else:
|
||||||
@@ -183,8 +182,8 @@ def main():
|
|||||||
table_code += '\n'
|
table_code += '\n'
|
||||||
|
|
||||||
# write or print wiki table
|
# write or print wiki table
|
||||||
if options.table_file:
|
if args.table_file:
|
||||||
f = open(options.table_file,'w')
|
f = open(args.table_file,'w')
|
||||||
f.write(table_code)
|
f.write(table_code)
|
||||||
print('Wrote table file')
|
print('Wrote table file')
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user