forked from iterorganization/imas-data-dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
195 lines (167 loc) · 5.5 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from setuptools_scm import get_version
import os
import re
import shutil
import subprocess
PWD = os.path.realpath(os.path.dirname(__file__))
UAL = os.path.dirname(PWD)
def join_path(path1="", path2=""):
return os.path.normpath(os.path.join(path1, path2))
DD_GIT_DESCRIBE = get_version()
def saxon_version(verb=False) -> int:
cmd = ["java", "net.sf.saxon.Transform", "-t"]
try:
out = subprocess.run(cmd, capture_output=True, text=True, check=False)
line = out.stderr.split("\n")[0]
version = re.search(r"Saxon.* +(\d+)\.(\d+)", line)
if verb:
print("Got Saxon version:", version.group(1), version.group(2))
major = int(version.group(1)) * 100
minor = int(version.group(2))
version = major + minor
except Exception as e:
if verb:
print(f"Error: can't get Saxon version. {e}")
version = 0
return version
def generate_dd_data_dictionary(extra_opts=""):
print("generating dd_data_dictionary.xml")
dd_data_dictionary_generation_command = (
"java"
+ " net.sf.saxon.Transform"
+ extra_opts
+ " -t -warnings:fatal -s:"
+ "dd_data_dictionary.xml.xsd"
+ " -xsl:"
+ "dd_data_dictionary.xml.xsl"
+ " -o:"
+ "dd_data_dictionary.xml"
+ " DD_GIT_DESCRIBE="
+ DD_GIT_DESCRIBE
)
proc = subprocess.Popen(
dd_data_dictionary_generation_command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
# env=env,
universal_newlines=True,
)
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
assert False, stderr
else:
try:
if not os.path.islink(join_path(PWD, "IDSDef.xml")):
os.symlink(
"dd_data_dictionary.xml",
"IDSDef.xml",
)
except Exception as _: # noqa: F841
shutil.copy("dd_data_dictionary.xml", "IDSDef.xml")
def generate_html_documentation(extra_opts=""):
print("generating html_documentation.html")
html_documentation_generation_command = (
"java"
+ " net.sf.saxon.Transform"
+ extra_opts
+ " -t -warnings:fatal -s:"
+ "dd_data_dictionary.xml"
+ " -xsl:"
+ "dd_data_dictionary_html_documentation.xsl"
+ " -o:"
+ "html_documentation.html"
+ " DD_GIT_DESCRIBE="
+ DD_GIT_DESCRIBE
)
proc = subprocess.Popen(
html_documentation_generation_command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
# env=env,
universal_newlines=True,
)
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
assert False, stderr
shutil.copy(
"schemas/utilities/coordinate_identifier.xml",
"html_documentation/utilities/coordinate_identifier.xml",
)
def generate_ids_cocos_transformations_symbolic_table(extra_opts=""):
print("generating html_documentation/cocos/ids_cocos_transformations_symbolic_table.csv")
ids_cocos_transformations_symbolic_table_generation_command = (
"java"
+ " net.sf.saxon.Transform"
+ extra_opts
+ " -t -warnings:fatal -s:"
+ "dd_data_dictionary.xml"
+ " -xsl:"
+ "ids_cocos_transformations_symbolic_table.csv.xsl"
+ " -o:"
+ "html_documentation/cocos/ids_cocos_transformations_symbolic_table.csv"
+ " DD_GIT_DESCRIBE="
+ DD_GIT_DESCRIBE
)
proc = subprocess.Popen(
ids_cocos_transformations_symbolic_table_generation_command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
# env=env,
universal_newlines=True,
)
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
assert False, stderr
def generate_idsnames():
print("generating IDSNames.txt")
idsnames_command = (
"java"
+ " net.sf.saxon.Transform"
+ " -t -warnings:fatal -s:"
+ "dd_data_dictionary.xml"
+ " -xsl:"
+ "IDSNames.txt.xsl"
+ " -o:"
+ "IDSNames.txt"
)
proc = subprocess.Popen(
idsnames_command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
assert False, stderr
def generate_dd_data_dictionary_validation(extra_opts=""):
print("dd_data_dictionary_validation.txt")
dd_data_dictionary_validation_generation_command = (
"java"
+ " net.sf.saxon.Transform"
+ extra_opts
+ " -t -warnings:fatal -s:"
+ "dd_data_dictionary.xml"
+ " -xsl:"
+ "dd_data_dictionary_validation.txt.xsl"
+ " -o:"
+ "dd_data_dictionary_validation.txt"
)
proc = subprocess.Popen(
dd_data_dictionary_validation_generation_command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
assert False, stderr
if __name__ == "__main__":
# Can we use threads in this version of Saxon?
threads = ""
if saxon_version() >= 904:
threads = " -threads:4"
generate_dd_data_dictionary(extra_opts=threads)
generate_html_documentation(extra_opts=threads)
generate_ids_cocos_transformations_symbolic_table(extra_opts=threads)
generate_idsnames()
generate_dd_data_dictionary_validation(extra_opts=threads)