# HG changeset patch # User Anton Shestakov # Date 1606110209 -28800 # Node ID 1d80cda7fe935b2bf3e496906d6eb5782c4cf54f # Parent 5affbb44f135c729aba9a327bf1cc494357f6ed1 test2rst: minor improvements diff -r 5affbb44f135 -r 1d80cda7fe93 docs/test2rst.py --- a/docs/test2rst.py Wed Nov 11 18:34:15 2020 +0800 +++ b/docs/test2rst.py Mon Nov 23 13:43:29 2020 +0800 @@ -1,8 +1,8 @@ #!/usr/bin/env python3 +import argparse import os import re -import sys ignored_patterns = [ @@ -14,6 +14,7 @@ def rstify(orig): + """Take contents of a .t file and produce reStructuredText""" newlines = [] code_block_mode = False @@ -21,7 +22,7 @@ for line in orig.splitlines(): - # Emtpy lines doesn't change output + # Empty lines doesn't change output if not line: newlines.append(line) code_block_mode = False @@ -59,17 +60,19 @@ return "\n".join(newlines) -def main(path): - with open(path) as f: +def main(): + ap = argparse.ArgumentParser() + ap.add_argument('testfile', help='.t file to transform') + + opts = ap.parse_args() + + with open(opts.testfile) as f: content = f.read() rst = rstify(content) - target = os.path.splitext(path)[0] + '.rst' + target = os.path.splitext(opts.testfile)[0] + '.rst' with open(target, 'w') as f: f.write(rst) if __name__ == '__main__': - if len(sys.argv) != 2: - print('Please supply a path to tests dir as parameter') - sys.exit() - main(sys.argv[1]) + main()