aboutsummaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorJulian Oes <julian@oes.ch>2014-01-28 10:46:44 +0100
committerJulian Oes <julian@oes.ch>2014-01-28 10:46:44 +0100
commitc5a3dd916899ddd8409380c27c05a8b2d903c8f4 (patch)
tree87d6c7b28b693d72b8bdcff7baadddc9516a1b6a /Tools
parent6002819f8fccb491dcfbe23de892a827cd9f4618 (diff)
downloadpx4-firmware-c5a3dd916899ddd8409380c27c05a8b2d903c8f4.tar.gz
px4-firmware-c5a3dd916899ddd8409380c27c05a8b2d903c8f4.tar.bz2
px4-firmware-c5a3dd916899ddd8409380c27c05a8b2d903c8f4.zip
FSM visualisation script: use argparse instead of optionparse and some minor cleanup
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/draw_fsm_diagram.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/Tools/draw_fsm_diagram.py b/Tools/draw_fsm_diagram.py
index a36d39b41..fe37b6ba3 100755
--- a/Tools/draw_fsm_diagram.py
+++ b/Tools/draw_fsm_diagram.py
@@ -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:
dot fsm.dot -Tpng -o fsm.png
"""
-from optparse import OptionParser
+import argparse
import re
-import subprocess
__author__ = "Julian Oes"
@@ -27,16 +26,16 @@ def get_dot_footer():
def main():
# parse input arguments
- parser = OptionParser()
- parser.add_option("-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_option("-t", "--table-file", default=None, help="choose file for output of table")
- (options, args) = parser.parse_args()
+ parser = argparse.ArgumentParser(description='Create dot code and dokuwiki table from a state transition table.')
+ parser.add_argument("-i", "--input-file", default=None, help="choose file to parse")
+ parser.add_argument("-d", "--dot-file", default=None, help="choose file for output dot file")
+ parser.add_argument("-t", "--table-file", default=None, help="choose file for output of table")
+ args = parser.parse_args()
# open source file
- if options.input_file == None:
+ if args.input_file == None:
exit('please specify file')
- f = open(options.input_file,'r')
+ f = open(args.input_file,'r')
source = f.read()
# 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()
# write or print dot file
- if options.dot_file:
- f = open(options.dot_file,'w')
+ if args.dot_file:
+ f = open(args.dot_file,'w')
f.write(dot_code)
print('Wrote dot file')
else:
@@ -183,8 +182,8 @@ def main():
table_code += '\n'
# write or print wiki table
- if options.table_file:
- f = open(options.table_file,'w')
+ if args.table_file:
+ f = open(args.table_file,'w')
f.write(table_code)
print('Wrote table file')
else: