-
Notifications
You must be signed in to change notification settings - Fork 3
/
davis_one_maker.py
170 lines (146 loc) · 4.86 KB
/
davis_one_maker.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
#################################################
########### CONSTANTS ###########
#################################################
LICENSE_HEADER = """/* Copyright (c) 2024 The DevTools Authors. All rights reserved.
* This Source Code Form is subject to the terms of the MIT licence.
* https://github.com/DevToolsOrganization/matrix-data-visualization-DAVIS
*/
"""
GENERATED_INFO_HEADER = """
//This file was generated by davis_one_maker.py script.
//Use davis_files.txt and special comments to change generated davis.h and davis.cpp
"""
START_DAVIS_H = """#ifndef DAVIS_H_
#define DAVIS_H_
"""
END_DAVIS_H = """
#endif // DAVIS_H_"""
START_DAVIS_CPP = """#include "davis.h"
"""
START_NAME_SPACE_DAVIS = """namespace dvs {
"""
END_NAME_SPACE_DAVIS = """
} // namespace dvs end\n
"""
START_NAME_SPACE_PUBLIC_DAVIS = """namespace dv {
"""
END_NAME_SPACE_PUBLIC_DAVIS = """
} // namespace dv end\n"""
START_NAME_SPACE = """namespace {
"""
END_NAME_SPACE = """
}// namespace end\n"""
OUTPUT_H_FILE_NAME = "davis_one/davis.h"
OUTPUT_CPP_FILE_NAME = "davis_one/davis.cpp"
SRC_LIST_FILE = "davis_files.txt"
START_GRAB_INCLUDES = """#START_GRAB_TO_INCLUDES_LIST"""
STOP_GRAB_INCLUDES = """#STOP_GRAB_TO_INCLUDES_LIST"""
START_GRAB_DAVIS_NAMESPACE = """#START_GRAB_TO_DVS_NAMESPACE"""
STOP_GRAB_DAVIS_NAMESPACE = """#STOP_GRAB_TO_DVS_NAMESPACE"""
START_GRAB_PUBLIC_DAVIS_NAMESPACE = """#START_GRAB_TO_DV_NAMESPACE"""
STOP_GRAB_PUBLIC_DAVIS_NAMESPACE = """#STOP_GRAB_TO_DV_NAMESPACE"""
START_GRAB_NAMESPACE = """#START_GRAB_TO_NAMESPACE"""
STOP_GRAB_NAMESPACE = """#STOP_GRAB_TO_NAMESPACE"""
#################################################
########### FUNCTIONS ###########
#################################################
def delete_file_if_exists(file_name):
if os.path.exists(file_name):
os.remove(file_name)
def grab_namespace_code(namespace_text_start,
namespace_text_end,
start_grab_text,
stop_grab_text,
file):
#for el in files:
all_text = open(file).read()
if not start_grab_text in all_text:
return
if '.h' in file:
file_h.write(namespace_text_start)
if '.cpp' in file:
file_cpp.write(namespace_text_start)
is_grab_davis = False
file_src = all_text.splitlines()
for f in file_src:
if start_grab_text in f:
is_grab_davis = True
continue
if stop_grab_text in f:
is_grab_davis = False
continue
if is_grab_davis:
if '.h' in file:
file_h.write(f + "\n")
if '.cpp' in file:
file_cpp.write(f + "\n")
if '.h' in file:
file_h.write(namespace_text_end)
if '.cpp' in file:
file_cpp.write(namespace_text_end)
print("""
########################################
######## DAVIS MAKER SCRIPT ########
########################################
""")
includes_h_set = set("")
includes_cpp_set = set("")
delete_file_if_exists(OUTPUT_H_FILE_NAME)
delete_file_if_exists(OUTPUT_CPP_FILE_NAME)
file_h = open(OUTPUT_H_FILE_NAME, 'a')
file_h.write(LICENSE_HEADER)
file_h.write(GENERATED_INFO_HEADER)
file_h.write(START_DAVIS_H)
file_cpp = open(OUTPUT_CPP_FILE_NAME, 'a')
file_cpp.write(LICENSE_HEADER)
file_cpp.write(GENERATED_INFO_HEADER)
file_cpp.write(START_DAVIS_CPP)
is_grab_includes = False
file_src_list = open(SRC_LIST_FILE,'r').read().splitlines()
for el in file_src_list:
#print(el)
file_src = open(el).read().splitlines()
for f in file_src:
if START_GRAB_INCLUDES in f:
is_grab_includes = True
continue
if STOP_GRAB_INCLUDES in f:
is_grab_includes = False
continue
if is_grab_includes:
if '.h' in el:
includes_h_set.add(f)
#print('h: -->',f)
if '.cpp' in el:
includes_cpp_set.add(f)
#print('cpp: -->',f)
sorted_h_includes = sorted(includes_h_set)
sorted_cpp_includes = sorted(includes_cpp_set)
print("ALL H INCLUDES: ")
for hs in sorted_h_includes:
print(hs)
file_h.write(hs+"\n")
print("ALL CPP INCLUDES: ")
for cpps in sorted_cpp_includes:
print(cpps)
file_cpp.write(cpps+"\n")
for file in file_src_list:
grab_namespace_code(START_NAME_SPACE,
END_NAME_SPACE,
START_GRAB_NAMESPACE,
STOP_GRAB_NAMESPACE,
file)
grab_namespace_code(START_NAME_SPACE_DAVIS,
END_NAME_SPACE_DAVIS,
START_GRAB_DAVIS_NAMESPACE,
STOP_GRAB_DAVIS_NAMESPACE,
file)
grab_namespace_code(START_NAME_SPACE_PUBLIC_DAVIS,
END_NAME_SPACE_PUBLIC_DAVIS,
START_GRAB_PUBLIC_DAVIS_NAMESPACE,
STOP_GRAB_PUBLIC_DAVIS_NAMESPACE,
file)
file_h.write(END_DAVIS_H) #DAVIS HEADER_GUARD END
file_h.close()
file_cpp.close()