Skip to content
Snippets Groups Projects
Commit 1d80cda7fe93 authored by Anton Shestakov's avatar Anton Shestakov
Browse files

test2rst: minor improvements

parent 5affbb44f135
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import argparse
import os
import re
......@@ -3,6 +4,5 @@
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,7 +60,12 @@
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)
......@@ -64,8 +70,8 @@
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__':
......@@ -67,9 +73,6 @@
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment