-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
41 lines (28 loc) · 1 KB
/
generate.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
#! /usr/bin/python3
import inflection
import os
import sys
from functions import get_source_files, get_namespace, get_glob_lines, get_definitions
def get_substitutions(kinds, search_dir, project_root, glob_root):
old_dir = os.getcwd()
os.chdir(project_root)
lines = set()
i = 0
substitutions = {}
for path, name in get_source_files(search_dir):
namespace = get_namespace(path, name)
definitions = get_definitions(kinds, get_glob_lines(glob_root, path, name))
for end, name in definitions:
snake_name = inflection.underscore(name)
if snake_name == name: continue
lines.add(f'{namespace} {snake_name} {name}')
os.chdir(old_dir)
return sorted(list(set(lines)))
substitutions = get_substitutions(
["def", "coe", "prf", "thm"],
sys.argv[1] if len(sys.argv) > 1 else ".",
sys.argv[2] if len(sys.argv) > 2 else ".",
sys.argv[3] if len(sys.argv) > 3 else "_build/default",
)
with open("changes.txt", "w+") as output_file:
output_file.write("\n".join(substitutions))