Newer
Older
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
from __future__ import print_function
import fnmatch
import os
import sys
try:
from titlecase import titlecase
except ImportError:
print("Please install titlecase")
def main(location):
# Open the file and read the lines as a list
with open(location) as f:
lines = f.readlines()
# Loop through the list of lines and titlecase
# any line beginning with '#'.
return_value = 0
prev_line = lines.pop(0)
disabled = 0
print(`location`)
for line in lines:
if line.startswith("``") and disabled == 0:
disabled = 1
else:
if line.startswith("``") and disabled == 1:
disabled = 0
if line.startswith('#') and disabled == 0:
if line != titlecase(line):
print()
print("-"+line,end="")
print("+"+titlecase(line[:(line.find("]"))])+line[(line.find("]")):],end="")
return_value = 1
if line.startswith('---') or line.startswith('==='):
if prev_line != titlecase(prev_line):
print()
print("-"+prev_line,end="")
print("+"+titlecase(prev_line[:(prev_line.find("]"))])+prev_line[(prev_line.find("]")):],end="")
return_value = 1
prev_line = line
if return_value == 0:
print("==Ok==")
exit(return_value)
if __name__ == "__main__":
try:
main(sys.argv[1])
except IndexError:
main('.')