1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 |
2 |
3 import os, os.path as op, re, sys |
3 import os |
|
4 import os.path as op |
|
5 import re |
|
6 import sys |
4 |
7 |
5 # line starts with two chars one of which is not a space (and both are not |
8 # line starts with two chars one of which is not a space (and both are not |
6 # newlines obviously) and ends with one or more newlines followed by two spaces |
9 # newlines obviously) and ends with one or more newlines followed by two spaces |
7 # on a next line (indented text) |
10 # on a next line (indented text) |
8 CODEBLOCK = re.compile(r'()\n(([^ \n][^\n]|[^\n][^ \n])[^\n]*)\n+ ') |
11 CODEBLOCK = re.compile(r'()\n(([^ \n][^\n]|[^\n][^ \n])[^\n]*)\n+ ') |
30 one_file(base) |
33 one_file(base) |
31 |
34 |
32 |
35 |
33 def one_dir(base): |
36 def one_dir(base): |
34 index = INDEX |
37 index = INDEX |
35 #doc = lambda x: op.join(op.dirname(__file__), 'docs', x) |
38 # doc = lambda x: op.join(op.dirname(__file__), 'docs', x) |
36 |
39 |
37 for fn in sorted(os.listdir(base)): |
40 for fn in sorted(os.listdir(base)): |
38 if not fn.endswith('.t'): |
41 if not fn.endswith('.t'): |
39 continue |
42 continue |
40 name = os.path.splitext(fn)[0] |
43 name = os.path.splitext(fn)[0] |
41 content = one_file(op.join(base, fn)) |
44 content = one_file(op.join(base, fn)) |
42 target = op.join(base, name + '.rst') |
45 target = op.join(base, name + '.rst') |
43 #with file(doc(name + '.rst'), 'w') as f: |
46 # with file(doc(name + '.rst'), 'w') as f: |
44 with file(target, 'w') as f: |
47 with open(target, 'w') as f: |
45 f.write(content) |
48 f.write(content) |
46 |
49 |
47 index += '\n ' + name |
50 index += '\n ' + name |
48 |
51 |
49 #with file(doc('index.rst'), 'w') as f: |
52 # with file(doc('index.rst'), 'w') as f: |
50 # f.write(index) |
53 # f.write(index) |
51 |
54 |
52 |
55 |
53 def one_file(path): |
56 def one_file(path): |
54 name = os.path.basename(path)[:-2] |
57 name = os.path.basename(path)[:-2] |
55 return rstify(file(path).read(), name) |
58 return rstify(open(path).read(), name) |
56 |
59 |
57 |
60 |
58 if __name__ == '__main__': |
61 if __name__ == '__main__': |
59 if len(sys.argv) != 2: |
62 if len(sys.argv) != 2: |
60 print 'Please supply a path to tests dir as parameter' |
63 print('Please supply a path to tests dir as parameter') |
61 sys.exit() |
64 sys.exit() |
62 main(sys.argv[1]) |
65 main(sys.argv[1]) |