forked from cewing/training.python_web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
36 lines (32 loc) · 1.12 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Tools for manipulating documentation
"""
def build_typealong(rstfile, outfile):
"""extract indented code sample sections along with slide headers
builds a type-along file that provides cut-and-paste for all code samples
in a slide presentation.
"""
in_lines = rstfile.readlines()
type_buffer = []
prev_line = ''
def get_header(cur, prev):
if cur.startswith('----'):
return (prev, cur, '\n')
return ()
for line in in_lines:
header = get_header(line, prev_line)
if header:
print "outputting a slide header"
outfile.writelines(header)
else:
if line.startswith(' '):
# omit ` :class: blah' type lines
if not line[4] == ':':
type_buffer.append(line)
elif line.startswith('\n'):
if type_buffer:
print "outputting a typeable section"
type_buffer.extend(['\n', '\n'])
outfile.writelines(type_buffer)
type_buffer = []
prev_line = line