forked from SMTorg/smt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.py
53 lines (38 loc) · 1.47 KB
/
preprocess.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Author: Dr. John T. Hwang <[email protected]>
This package is distributed under New BSD license.
"""
import os
from preprocess_test import process_test
from preprocess_options import process_options
def get_file_paths():
file_paths_list = []
file_paths_list_rstx = []
file_paths_list_py = []
for root, dirs, files in os.walk("."):
for file_name in files:
file_paths_list.append((root, file_name))
if file_name[-5:] == ".rstx":
file_paths_list_rstx.append((root, file_name))
if file_name[-3:] == ".py":
file_paths_list_py.append((root, file_name))
return file_paths_list, file_paths_list_rstx, file_paths_list_py
file_paths_list, file_paths_list_rstx, file_paths_list_py = get_file_paths()
for root, file_name in file_paths_list_rstx:
file_path = root + "/" + file_name
with open(file_path, "r") as f:
lines = f.readlines()
for iline, line in enumerate(lines):
if ".. embed-test" in line:
lines[iline] = process_test(root, file_name, iline, line)
elif ".. embed-options-table" in line:
lines[iline] = process_options(root, file_name, iline, line)
new_lines = []
for line in lines:
if isinstance(line, list):
new_lines.extend(line)
else:
new_lines.append(line)
new_file_path = file_path[:-5] + ".rst"
with open(new_file_path, "w") as f:
f.writelines(new_lines)