g3projects 0.1.2__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of g3projects might be problematic. Click here for more details.
- {g3projects-0.1.2 → g3projects-0.2.1}/PKG-INFO +3 -2
- {g3projects-0.1.2 → g3projects-0.2.1}/pyproject.toml +4 -3
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/_logical.py +136 -67
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/ansic_prg.tpl +1 -1
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/package_pkg_logical.tpl +1 -1
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/package_pkg_project.tpl +3 -3
- g3projects-0.2.1/src/g3projects/logical/templates/package_pkg_system.tpl +14 -0
- g3projects-0.2.1/src/g3projects/main/_main.py +86 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/_physical.py +57 -34
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/config_pkg.tpl +1 -1
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/config_sfdomain.tpl +1 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/cpu_pkg.tpl +3 -3
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/hardware_hw.tpl +1 -1
- g3projects-0.2.1/src/g3projects/utils/_utils.py +23 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects.egg-info/PKG-INFO +3 -2
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects.egg-info/requires.txt +1 -0
- g3projects-0.1.2/src/g3projects/logical/templates/package_pkg_system.tpl +0 -14
- g3projects-0.1.2/src/g3projects/main/_main.py +0 -34
- g3projects-0.1.2/src/g3projects/utils/_utils.py +0 -37
- {g3projects-0.1.2 → g3projects-0.2.1}/LICENCE +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/README.md +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/setup.cfg +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/__init__.py +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/__init__.py +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/autogenerated_block.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/config_txt.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/main_c.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/main_c_system.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/variables_var.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/variables_var_system.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/main/__init__.py +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/__init__.py +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/iomap_iom.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/physical_pkg.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/physical/templates/zone_sw.tpl +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/py.typed +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/utils/__init__.py +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects.egg-info/SOURCES.txt +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects.egg-info/dependency_links.txt +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects.egg-info/entry_points.txt +0 -0
- {g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects.egg-info/top_level.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: g3projects
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: System G3 Project PLC files generator
|
|
5
|
-
Author
|
|
5
|
+
Author: Elektroline a.s.
|
|
6
6
|
Project-URL: Homepage, https://gitlab.elektroline.cz/plc/systemg3-py/SystemG3ProjectBuilder
|
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -14,6 +14,7 @@ Requires-Dist: jinja2
|
|
|
14
14
|
Requires-Dist: g3core
|
|
15
15
|
Requires-Dist: g3elements
|
|
16
16
|
Requires-Dist: g3hardware
|
|
17
|
+
Requires-Dist: g3tables
|
|
17
18
|
|
|
18
19
|
# System G3 Project PLC files generator
|
|
19
20
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "g3projects"
|
|
3
|
-
version = "0.1
|
|
3
|
+
version = "0.2.1"
|
|
4
4
|
description = "System G3 Project PLC files generator"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = {file = "LICENSE"}
|
|
7
7
|
authors = [
|
|
8
|
-
{ name
|
|
8
|
+
{ name="Elektroline a.s." },
|
|
9
9
|
]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Programming Language :: Python :: 3",
|
|
@@ -17,7 +17,8 @@ dependencies = [
|
|
|
17
17
|
"jinja2",
|
|
18
18
|
"g3core",
|
|
19
19
|
"g3elements",
|
|
20
|
-
"g3hardware"
|
|
20
|
+
"g3hardware",
|
|
21
|
+
"g3tables"
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
[options]
|
|
@@ -2,22 +2,25 @@ import json
|
|
|
2
2
|
import os
|
|
3
3
|
import shutil
|
|
4
4
|
import logging
|
|
5
|
+
import typing
|
|
5
6
|
|
|
6
7
|
from datetime import datetime
|
|
7
8
|
from jinja2 import Environment, FileSystemLoader
|
|
8
9
|
from textwrap import indent
|
|
9
10
|
|
|
10
11
|
from g3core import G3Core
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
|
|
14
|
-
)
|
|
12
|
+
from g3tables.system_config import SWSystemDictWrapper
|
|
13
|
+
from g3tables.system_config.type_hinting import SystemDict, SWDeviceDict
|
|
14
|
+
|
|
15
15
|
|
|
16
16
|
from ..utils import (
|
|
17
17
|
format_template, combine_str, remove_multiple_newlines, write_to_file
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
logger = logging.getLogger('g3project_builder.logical')
|
|
22
|
+
|
|
23
|
+
|
|
21
24
|
env = Environment(
|
|
22
25
|
loader=FileSystemLoader(
|
|
23
26
|
os.path.join(os.path.dirname(__file__), 'templates/')
|
|
@@ -36,8 +39,6 @@ def get_system_dict(path: str) -> SystemDict:
|
|
|
36
39
|
# ZONE #
|
|
37
40
|
|
|
38
41
|
|
|
39
|
-
# ST Declarations - ! these ideally need to go to G3Core ! #
|
|
40
|
-
|
|
41
42
|
def delete_config_keys_with_default_values(
|
|
42
43
|
system_data: SWSystemDictWrapper, g3core: G3Core
|
|
43
44
|
) -> None:
|
|
@@ -72,40 +73,51 @@ def delete_config_keys_with_default_values(
|
|
|
72
73
|
'dtype': member.dtype
|
|
73
74
|
}
|
|
74
75
|
else:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
logger.info(
|
|
77
|
+
'Key "%s" at "%s/control/config" contains default '
|
|
78
|
+
'value of the "%s" member of the "%s" config '
|
|
79
|
+
'struct and will be ignored', config_key, path,
|
|
80
|
+
member.name, config_struct.name
|
|
80
81
|
)
|
|
81
|
-
logging.info(info_msg)
|
|
82
82
|
matched = True
|
|
83
83
|
break
|
|
84
84
|
if not matched:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
f'and will be ignored'
|
|
85
|
+
logger.warning(
|
|
86
|
+
'Key "%s" at "%s/control/config" was not matched with any '
|
|
87
|
+
'member of the "%s" config struct and will be ignored',
|
|
88
|
+
config_key, path, config_struct.name
|
|
90
89
|
)
|
|
91
|
-
logging.warning(err_msg)
|
|
92
90
|
config_data.clear()
|
|
93
91
|
config_data.update(config_data_updated)
|
|
94
92
|
|
|
95
93
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
# ST Declarations - ! these ideally need to go to G3Core ! #
|
|
95
|
+
|
|
96
|
+
def get_fb_declaration(
|
|
97
|
+
device_data: SWDeviceDict,
|
|
98
|
+
device_domain: typing.Literal['control', 'test']
|
|
99
|
+
) -> str:
|
|
100
|
+
if device_domain == 'control':
|
|
101
|
+
varname = device_data['general']['varname']
|
|
102
|
+
fb_name = SWSystemDictWrapper.get_device_control_fb(device_data)
|
|
103
|
+
elif device_domain == 'test':
|
|
104
|
+
varname = device_data['general']['varname_test']
|
|
105
|
+
fb_name = SWSystemDictWrapper.get_device_test_fb(device_data)
|
|
106
|
+
else:
|
|
107
|
+
raise ValueError(f'Invalid device domain: {device_domain}')
|
|
99
108
|
if not fb_name:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
logger.warning(
|
|
110
|
+
'Could not generate function block declaration for %s',
|
|
111
|
+
device_data['general']['name']
|
|
112
|
+
)
|
|
104
113
|
return ''
|
|
105
114
|
return f'fb{varname} : {fb_name.strip()};'
|
|
106
115
|
|
|
107
116
|
|
|
108
|
-
def get_dev_struct_declaration(
|
|
117
|
+
def get_dev_struct_declaration(
|
|
118
|
+
device_data: SWDeviceDict,
|
|
119
|
+
device_domain: typing.Literal['control', 'test']
|
|
120
|
+
) -> str:
|
|
109
121
|
|
|
110
122
|
def format_dict_recursive(d: dict):
|
|
111
123
|
elements = []
|
|
@@ -129,7 +141,7 @@ def get_dev_struct_declaration(device_data: SWDeviceDict) -> str:
|
|
|
129
141
|
value = value_data['value']
|
|
130
142
|
except KeyError:
|
|
131
143
|
name = device_data['general']['name']
|
|
132
|
-
|
|
144
|
+
logger.warning('Could not format dev struct value at %s', name)
|
|
133
145
|
return ''
|
|
134
146
|
|
|
135
147
|
if value is None:
|
|
@@ -156,15 +168,24 @@ def get_dev_struct_declaration(device_data: SWDeviceDict) -> str:
|
|
|
156
168
|
else:
|
|
157
169
|
return str(value)
|
|
158
170
|
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
if device_domain == 'control':
|
|
172
|
+
varname = device_data['general']['varname']
|
|
173
|
+
dev_struct_type = device_data['control'].get('devType')
|
|
174
|
+
config = device_data['control']['config']
|
|
175
|
+
elif device_domain == 'test':
|
|
176
|
+
varname = device_data['general']['varname_test']
|
|
177
|
+
dev_struct_type = device_data['test'].get('devType')
|
|
178
|
+
config = device_data['test']['config']
|
|
179
|
+
else:
|
|
180
|
+
raise ValueError(f'Invalid device domain: {device_domain}')
|
|
181
|
+
if not dev_struct_type:
|
|
161
182
|
name = device_data['general']['name']
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
183
|
+
logger.warning(
|
|
184
|
+
'Could not generate struct declaration for %s', name
|
|
185
|
+
)
|
|
165
186
|
return ''
|
|
166
187
|
config_values_formatted = []
|
|
167
|
-
for memb_name, memb_value_data in
|
|
188
|
+
for memb_name, memb_value_data in config.items():
|
|
168
189
|
if (memb_value := format_value(memb_value_data)):
|
|
169
190
|
config_values_formatted.append((memb_name, memb_value))
|
|
170
191
|
config_vals = ", ".join(
|
|
@@ -176,31 +197,53 @@ def get_dev_struct_declaration(device_data: SWDeviceDict) -> str:
|
|
|
176
197
|
return f'{varname} : {dev_struct_type} := (config := ({config_vals}));'
|
|
177
198
|
|
|
178
199
|
|
|
179
|
-
def get_fb_assignment(
|
|
180
|
-
|
|
181
|
-
|
|
200
|
+
def get_fb_assignment(
|
|
201
|
+
device_data: SWDeviceDict,
|
|
202
|
+
device_domain: typing.Literal['control', 'test']
|
|
203
|
+
) -> str:
|
|
204
|
+
if device_domain == 'control':
|
|
205
|
+
varname = device_data['general']['varname']
|
|
206
|
+
connected_fbs = device_data['control'].get('connector')
|
|
207
|
+
elif device_domain == 'test':
|
|
208
|
+
varname_control = device_data['general']['varname']
|
|
209
|
+
varname = device_data['general']['varname_test']
|
|
210
|
+
connected_fbs = device_data['test'].get('connector')
|
|
211
|
+
else:
|
|
212
|
+
raise ValueError(f'Invalid device domain: {device_domain}')
|
|
182
213
|
if not connected_fbs:
|
|
183
214
|
return ""
|
|
184
215
|
fb_assignment_lines = []
|
|
185
216
|
for conn_name, conn_fb in connected_fbs.items():
|
|
186
217
|
if conn_fb:
|
|
187
|
-
|
|
218
|
+
if device_domain == 'control':
|
|
219
|
+
conn_fb_ptr = f"&{conn_fb}"
|
|
220
|
+
else: # varname_control is needed only for a test domain device
|
|
221
|
+
conn_fb_ptr = f"&fb{varname_control}.{conn_fb}"
|
|
188
222
|
else:
|
|
189
|
-
|
|
223
|
+
logger.warning('Connector "%s" not set.', conn_name)
|
|
190
224
|
conn_fb_ptr = "NULL"
|
|
191
225
|
conn_assignment = f'fb{varname}.{conn_name} = {conn_fb_ptr};'
|
|
192
226
|
fb_assignment_lines.append(conn_assignment)
|
|
193
227
|
return '\n'.join(fb_assignment_lines)
|
|
194
228
|
|
|
195
229
|
|
|
196
|
-
def get_fb_call(
|
|
197
|
-
|
|
198
|
-
|
|
230
|
+
def get_fb_call(
|
|
231
|
+
device_data: SWDeviceDict,
|
|
232
|
+
device_domain: typing.Literal['control', 'test']
|
|
233
|
+
) -> str:
|
|
234
|
+
if device_domain == 'control':
|
|
235
|
+
varname = device_data['general']['varname']
|
|
236
|
+
fb_name = SWSystemDictWrapper.get_device_control_fb(device_data)
|
|
237
|
+
elif device_domain == 'test':
|
|
238
|
+
varname = device_data['general']['varname_test']
|
|
239
|
+
fb_name = SWSystemDictWrapper.get_device_test_fb(device_data)
|
|
240
|
+
else:
|
|
241
|
+
raise ValueError(f'Invalid device domain: {device_domain}')
|
|
199
242
|
if not fb_name:
|
|
200
243
|
name = device_data['general']['name']
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
244
|
+
logger.warning(
|
|
245
|
+
'Could not generate function block call for %s', name
|
|
246
|
+
)
|
|
204
247
|
return ''
|
|
205
248
|
return f'{fb_name}(&fb{varname});'
|
|
206
249
|
|
|
@@ -224,46 +267,54 @@ def get_route_layout_declaration(device_data: SWDeviceDict) -> str:
|
|
|
224
267
|
|
|
225
268
|
|
|
226
269
|
def generate_zone_files_contents(
|
|
227
|
-
system_config: SWSystemDictWrapper, zone_name: str
|
|
270
|
+
system_config: SWSystemDictWrapper, zone_name: str, gen_test: bool = False
|
|
228
271
|
) -> tuple[str, str]:
|
|
229
272
|
varibales_var = ''
|
|
230
273
|
main_c = ''
|
|
231
274
|
for _, path, device_data in system_config.iter_devices_zone(zone_name):
|
|
232
275
|
if not system_config.get_device_control_fb(device_data):
|
|
233
|
-
|
|
276
|
+
logger.warning('function block type is missing for "%s"', path)
|
|
234
277
|
continue
|
|
235
278
|
varibales_var = combine_str(
|
|
236
279
|
varibales_var,
|
|
237
|
-
get_fb_declaration(device_data),
|
|
238
|
-
get_dev_struct_declaration(device_data),
|
|
280
|
+
get_fb_declaration(device_data, 'control'),
|
|
281
|
+
get_dev_struct_declaration(device_data, 'control'),
|
|
239
282
|
)
|
|
240
283
|
main_c = combine_str(
|
|
241
284
|
main_c,
|
|
242
|
-
get_fb_assignment(device_data),
|
|
243
|
-
get_fb_call(device_data),
|
|
285
|
+
get_fb_assignment(device_data, 'control'),
|
|
286
|
+
get_fb_call(device_data, 'control'),
|
|
244
287
|
)
|
|
245
|
-
if
|
|
246
|
-
|
|
247
|
-
'NonSafety' in
|
|
248
|
-
|
|
288
|
+
if 'Route' in path:
|
|
289
|
+
route_fb = SWSystemDictWrapper.get_device_control_fb(device_data)
|
|
290
|
+
if route_fb and 'NonSafety' in route_fb:
|
|
291
|
+
main_c = combine_str(
|
|
292
|
+
main_c,
|
|
293
|
+
get_route_layout_declaration(device_data),
|
|
294
|
+
)
|
|
295
|
+
if gen_test:
|
|
296
|
+
varibales_var = combine_str(
|
|
297
|
+
varibales_var,
|
|
298
|
+
get_fb_declaration(device_data, 'test'),
|
|
299
|
+
get_dev_struct_declaration(device_data, 'test'),
|
|
300
|
+
)
|
|
249
301
|
main_c = combine_str(
|
|
250
302
|
main_c,
|
|
251
|
-
|
|
303
|
+
get_fb_assignment(device_data, 'test'),
|
|
304
|
+
get_fb_call(device_data, 'test'),
|
|
252
305
|
)
|
|
253
306
|
return (
|
|
254
307
|
indent(remove_multiple_newlines(varibales_var), ' '),
|
|
255
308
|
indent(remove_multiple_newlines(main_c), ' ')
|
|
256
309
|
)
|
|
257
310
|
|
|
258
|
-
|
|
259
311
|
# ZONE END #
|
|
260
312
|
|
|
261
313
|
|
|
262
314
|
# COMM #
|
|
263
315
|
|
|
264
|
-
|
|
265
316
|
def generate_comm_files_contents(
|
|
266
|
-
system_config: SWSystemDictWrapper
|
|
317
|
+
system_config: SWSystemDictWrapper, gen_test: bool = False
|
|
267
318
|
) -> tuple[str, str]:
|
|
268
319
|
varibales_var = ''
|
|
269
320
|
main_c = ''
|
|
@@ -272,19 +323,28 @@ def generate_comm_files_contents(
|
|
|
272
323
|
continue
|
|
273
324
|
varibales_var = combine_str(
|
|
274
325
|
varibales_var,
|
|
275
|
-
get_fb_declaration(device_data),
|
|
326
|
+
get_fb_declaration(device_data, 'control'),
|
|
276
327
|
)
|
|
277
328
|
main_c = combine_str(
|
|
278
329
|
main_c,
|
|
279
|
-
get_fb_assignment(device_data),
|
|
280
|
-
get_fb_call(device_data),
|
|
330
|
+
get_fb_assignment(device_data, 'control'),
|
|
331
|
+
get_fb_call(device_data, 'control'),
|
|
281
332
|
)
|
|
333
|
+
if gen_test:
|
|
334
|
+
varibales_var = combine_str(
|
|
335
|
+
varibales_var,
|
|
336
|
+
get_fb_declaration(device_data, 'test'),
|
|
337
|
+
)
|
|
338
|
+
main_c = combine_str(
|
|
339
|
+
main_c,
|
|
340
|
+
get_fb_assignment(device_data, 'test'),
|
|
341
|
+
get_fb_call(device_data, 'test'),
|
|
342
|
+
)
|
|
282
343
|
return (
|
|
283
344
|
indent(remove_multiple_newlines(varibales_var), ' '),
|
|
284
345
|
indent(remove_multiple_newlines(main_c), ' ')
|
|
285
346
|
)
|
|
286
347
|
|
|
287
|
-
|
|
288
348
|
# COMM END #
|
|
289
349
|
|
|
290
350
|
|
|
@@ -311,7 +371,7 @@ def generate_system_files_contents(
|
|
|
311
371
|
# ZONE.VAR #
|
|
312
372
|
|
|
313
373
|
def generate_zone_var_contents(
|
|
314
|
-
system_config: SWSystemDictWrapper
|
|
374
|
+
system_config: SWSystemDictWrapper, gen_test: bool = False
|
|
315
375
|
) -> str:
|
|
316
376
|
zone_var = ''
|
|
317
377
|
for *_, device_data in system_config.iter_devices_zone('Common'):
|
|
@@ -319,8 +379,13 @@ def generate_zone_var_contents(
|
|
|
319
379
|
continue
|
|
320
380
|
zone_var = combine_str(
|
|
321
381
|
zone_var,
|
|
322
|
-
get_dev_struct_declaration(device_data),
|
|
382
|
+
get_dev_struct_declaration(device_data, 'control'),
|
|
323
383
|
)
|
|
384
|
+
if gen_test:
|
|
385
|
+
zone_var = combine_str(
|
|
386
|
+
zone_var,
|
|
387
|
+
get_dev_struct_declaration(device_data, 'test'),
|
|
388
|
+
)
|
|
324
389
|
return indent(remove_multiple_newlines(zone_var), ' ')
|
|
325
390
|
|
|
326
391
|
|
|
@@ -372,7 +437,9 @@ def generate_main_variables_ansic_files(
|
|
|
372
437
|
return folder_path
|
|
373
438
|
|
|
374
439
|
|
|
375
|
-
def generate_logical_files(
|
|
440
|
+
def generate_logical_files(
|
|
441
|
+
system_config_path: str, gen_test: bool = False
|
|
442
|
+
) -> None:
|
|
376
443
|
g3core = G3Core.from_local('./Logical/Libraries')
|
|
377
444
|
system = get_system_dict(system_config_path)
|
|
378
445
|
sw_system_wrapper = SWSystemDictWrapper(system['Software'])
|
|
@@ -385,7 +452,7 @@ def generate_logical_files(system_config_path: str) -> None:
|
|
|
385
452
|
if zone_name == 'Common':
|
|
386
453
|
continue
|
|
387
454
|
varibales_var, main_c = generate_zone_files_contents(
|
|
388
|
-
sw_system_wrapper, zone_name
|
|
455
|
+
sw_system_wrapper, zone_name, gen_test
|
|
389
456
|
)
|
|
390
457
|
zone_taskname = sw_system_wrapper.get_zone_taskname(zone_name)
|
|
391
458
|
zone_tasknames.append(zone_taskname)
|
|
@@ -393,7 +460,9 @@ def generate_logical_files(system_config_path: str) -> None:
|
|
|
393
460
|
project_name, system_name, zone_taskname, main_c, varibales_var
|
|
394
461
|
)
|
|
395
462
|
# create Comm folder files
|
|
396
|
-
varibales_var, main_c = generate_comm_files_contents(
|
|
463
|
+
varibales_var, main_c = generate_comm_files_contents(
|
|
464
|
+
sw_system_wrapper, gen_test
|
|
465
|
+
)
|
|
397
466
|
generate_main_variables_ansic_files(
|
|
398
467
|
project_name, system_name, 'Comm', main_c, varibales_var
|
|
399
468
|
)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<?xml version="1.0" encoding="utf-8"?>
|
|
4
4
|
<!--autogenerated {{ timestamp }}-->
|
|
5
|
-
<?AutomationStudio
|
|
5
|
+
<?AutomationStudio FileVersion="4.9"?>
|
|
6
6
|
<Program SubType="ANSIC" xmlns="http://br-automation.co.at/AS/Program">
|
|
7
7
|
<Files>
|
|
8
8
|
<File>Main.c</File>
|
{g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/package_pkg_logical.tpl
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<?xml version="1.0" encoding="utf-8"?>
|
|
4
4
|
<?AutomationStudio FileVersion="4.9"?>
|
|
5
|
-
<Package
|
|
5
|
+
<Package xmlns="http://br-automation.co.at/AS/Package">
|
|
6
6
|
<Objects>
|
|
7
7
|
<Object Type="Package" Description="Global libraries">Libraries</Object>
|
|
8
8
|
{% for name in project_names %}
|
{g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/package_pkg_project.tpl
RENAMED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
<?xml version="1.0" encoding="utf-8"?>
|
|
4
4
|
<?AutomationStudio FileVersion="4.9"?>
|
|
5
|
-
<Package
|
|
5
|
+
<Package xmlns="http://br-automation.co.at/AS/Package">
|
|
6
6
|
<Objects>
|
|
7
|
+
<Object Type="File">config.txt</Object>
|
|
7
8
|
{% for name in system_names %}
|
|
8
|
-
<Object Type="Package"
|
|
9
|
+
<Object Type="Package">{{ name }}</Object>
|
|
9
10
|
{% endfor %}
|
|
10
|
-
<Object Type="File">config.txt</Object>
|
|
11
11
|
</Objects>
|
|
12
12
|
</Package>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{# templates/package_pkg_system.tpl #}
|
|
2
|
+
|
|
3
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
4
|
+
<?AutomationStudio FileVersion="4.9"?>
|
|
5
|
+
<Package xmlns="http://br-automation.co.at/AS/Program">
|
|
6
|
+
<Objects>
|
|
7
|
+
<Object Type="File" Private="true">Zone.var</Object>
|
|
8
|
+
<Object Type="Program" Language="ANSIC">Comm</Object>
|
|
9
|
+
<Object Type="Program" Language="ANSIC">System</Object>
|
|
10
|
+
{% for name in zone_names %}
|
|
11
|
+
<Object Type="Program" Language="ANSIC">{{ name }}</Object>
|
|
12
|
+
{% endfor %}
|
|
13
|
+
</Objects>
|
|
14
|
+
</Package>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
from ..logical import generate_logical_files
|
|
5
|
+
from ..physical import generate_physical_files
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def parse_arguments() -> argparse.Namespace:
|
|
9
|
+
parser = argparse.ArgumentParser(
|
|
10
|
+
description=(
|
|
11
|
+
'Create a G3 Project PLC files from a SystemConfig.json file.'
|
|
12
|
+
)
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
'system_config',
|
|
16
|
+
type=str,
|
|
17
|
+
help='Path to the SystemConfig.json file'
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
'--gen-physical',
|
|
21
|
+
required=False,
|
|
22
|
+
action='store_true',
|
|
23
|
+
help=(
|
|
24
|
+
'Generate physical files only. If both --gen-physical and '
|
|
25
|
+
'--gen-logical are provided or neither are provided, both '
|
|
26
|
+
'physical and logical files will be generated.'
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
'--gen-logical',
|
|
31
|
+
required=False,
|
|
32
|
+
action='store_true',
|
|
33
|
+
help=(
|
|
34
|
+
'Generate logical files only. If both --gen-logical and '
|
|
35
|
+
'--gen-physical are provided or neither are provided, both '
|
|
36
|
+
'logical and physical files will be generated.'
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
'--gen-test',
|
|
41
|
+
required=False,
|
|
42
|
+
action='store_true',
|
|
43
|
+
help=(
|
|
44
|
+
'Generate test devices in logical files. Such devices act as '
|
|
45
|
+
'digital twins for testing purposes and are directly connected '
|
|
46
|
+
'to the control devices. This option requires --gen-logical.'
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
'--log-level',
|
|
51
|
+
type=str,
|
|
52
|
+
required=False,
|
|
53
|
+
default='INFO',
|
|
54
|
+
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
|
|
55
|
+
help='Set the logging level.'
|
|
56
|
+
)
|
|
57
|
+
args = parser.parse_args()
|
|
58
|
+
if not args.gen_physical and not args.gen_logical:
|
|
59
|
+
args.gen_physical = True
|
|
60
|
+
args.gen_logical = True
|
|
61
|
+
if not args.gen_logical and args.gen_test:
|
|
62
|
+
parser.error('--gen-test requires --gen-logical')
|
|
63
|
+
return args
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def generate_project_files(
|
|
67
|
+
system_config_path: str,
|
|
68
|
+
gen_physical: bool = True,
|
|
69
|
+
gen_logical: bool = True,
|
|
70
|
+
generate_test: bool = False
|
|
71
|
+
) -> None:
|
|
72
|
+
if gen_logical:
|
|
73
|
+
generate_logical_files(system_config_path)
|
|
74
|
+
if gen_physical:
|
|
75
|
+
generate_physical_files(system_config_path)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def main() -> None:
|
|
79
|
+
args = parse_arguments()
|
|
80
|
+
logging.basicConfig(
|
|
81
|
+
level=args.log_level,
|
|
82
|
+
format='[%(name)s] %(levelname)s:%(message)s'
|
|
83
|
+
)
|
|
84
|
+
generate_project_files(
|
|
85
|
+
args.system_config, args.gen_physical, args.gen_logical, args.gen_test
|
|
86
|
+
)
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import os
|
|
3
3
|
import shutil
|
|
4
|
-
|
|
4
|
+
import logging
|
|
5
5
|
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
from jinja2 import Environment, FileSystemLoader
|
|
8
8
|
from textwrap import indent
|
|
9
9
|
|
|
10
|
-
from
|
|
11
|
-
from
|
|
10
|
+
from g3tables.system_config import SWSystemDictWrapper
|
|
11
|
+
from g3tables.system_config.type_hinting import SystemDict
|
|
12
12
|
|
|
13
13
|
from ..utils import (
|
|
14
14
|
format_template, write_to_file
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
-
from g3hardware import
|
|
17
|
+
from g3hardware import HardwareModule, HardwareIsle, format_type, is_cpu_type
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger('g3project_builder.physical')
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
env = Environment(
|
|
@@ -42,7 +45,7 @@ def makedirs_physical(system_name: str) -> str:
|
|
|
42
45
|
return path
|
|
43
46
|
|
|
44
47
|
|
|
45
|
-
# TODO: Would be nice to
|
|
48
|
+
# TODO: Would be nice to move to some kind of wrapper
|
|
46
49
|
|
|
47
50
|
def is_safety_configuration(config_hw: list[dict]) -> bool:
|
|
48
51
|
for isle in config_hw:
|
|
@@ -59,44 +62,51 @@ def get_hardware_module_name(module_type: str, config_hw: list[dict]) -> str:
|
|
|
59
62
|
return f"{head['type']}_{head['cabinet']}_{head['name_suffix']}"
|
|
60
63
|
raise ValueError(f'Module "{module_type}" data was not found')
|
|
61
64
|
|
|
65
|
+
|
|
66
|
+
def get_cpu_module_name_default(module_name) -> str:
|
|
67
|
+
module_name_formatted = format_type(module_name)
|
|
68
|
+
if not is_cpu_type(module_name_formatted):
|
|
69
|
+
raise ValueError(f'Module "{module_name}" is not a CPU module')
|
|
70
|
+
return module_name_formatted
|
|
71
|
+
|
|
62
72
|
# END TODO ##
|
|
63
73
|
|
|
64
74
|
|
|
65
75
|
# Hardware.hw #
|
|
66
76
|
|
|
67
|
-
def create_hw_isles(config_hw: dict) ->
|
|
68
|
-
isles: list[
|
|
77
|
+
def create_hw_isles(config_hw: dict) -> HardwareIsle | None:
|
|
78
|
+
isles: list[HardwareIsle] = []
|
|
69
79
|
for isle_data in config_hw:
|
|
70
80
|
module_type = isle_data['head']['type']
|
|
71
81
|
cabinet = isle_data['head']['cabinet']
|
|
72
82
|
name_suffix = isle_data['head']['name_suffix']
|
|
73
|
-
head =
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
head = HardwareModule.new(
|
|
84
|
+
type_=module_type,
|
|
85
|
+
name_suffix=f"{cabinet}_{name_suffix}"
|
|
76
86
|
)
|
|
77
87
|
tail = []
|
|
78
88
|
for module_data in isle_data['tail']:
|
|
79
89
|
module_type = module_data['type']
|
|
80
90
|
cabinet = module_data['cabinet']
|
|
81
91
|
name_suffix = module_data['name_suffix']
|
|
82
|
-
module =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
module = HardwareModule.new(
|
|
93
|
+
type_=module_type,
|
|
94
|
+
name_suffix=f"{cabinet}_{name_suffix}"
|
|
95
|
+
)
|
|
86
96
|
tail.append(module)
|
|
87
|
-
isles.append(
|
|
97
|
+
isles.append(HardwareIsle(head, *tail))
|
|
88
98
|
# move the CPU isle to the start of the isle list
|
|
89
|
-
|
|
99
|
+
cpu_isle_i = -1
|
|
90
100
|
for i, isle in enumerate(isles):
|
|
91
|
-
if isle.head.
|
|
92
|
-
|
|
101
|
+
if is_cpu_type(isle.head.type_):
|
|
102
|
+
cpu_isle_i = i
|
|
93
103
|
break
|
|
94
|
-
if
|
|
104
|
+
if cpu_isle_i == -1:
|
|
95
105
|
raise ValueError(
|
|
96
|
-
"
|
|
106
|
+
"CPU module was not found in the hardware configuration"
|
|
97
107
|
)
|
|
98
|
-
if
|
|
99
|
-
isles.insert(0, isles.pop(
|
|
108
|
+
if cpu_isle_i != 0:
|
|
109
|
+
isles.insert(0, isles.pop(cpu_isle_i))
|
|
100
110
|
# connect the isles
|
|
101
111
|
for i, isle in enumerate(isles[:-1]):
|
|
102
112
|
isle.next_isle = isles[i + 1]
|
|
@@ -110,12 +120,18 @@ def generate_hardware_hw_contents(
|
|
|
110
120
|
) -> str:
|
|
111
121
|
if not (hw_isle := create_hw_isles(config_hw)):
|
|
112
122
|
return ''
|
|
113
|
-
contents = hw_isle.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
contents = hw_isle.to_str()
|
|
124
|
+
assert isinstance(contents, str)
|
|
125
|
+
contents_formatted = contents.replace(
|
|
126
|
+
r'{{ cpuname }}', cp1584_name
|
|
127
|
+
)
|
|
128
|
+
contents_formatted = contents_formatted.replace(
|
|
129
|
+
r'{{ cpuhostname }}', f'{system_name}_plc'
|
|
130
|
+
)
|
|
131
|
+
contents_formatted = contents_formatted.replace(
|
|
132
|
+
r'{{ cpuconfigurationid }}', f'cfg_{system_name}'
|
|
133
|
+
)
|
|
134
|
+
return contents_formatted
|
|
119
135
|
|
|
120
136
|
# END Hardware.hw #
|
|
121
137
|
|
|
@@ -170,12 +186,19 @@ def generate_physical_files(system_config_path: str) -> None:
|
|
|
170
186
|
format_template(env, 'config_pkg.tpl', cpu_type='CPU')
|
|
171
187
|
)
|
|
172
188
|
# create Hardware.hw and Hardware.hwl files
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
189
|
+
try:
|
|
190
|
+
cpu_name = get_hardware_module_name(
|
|
191
|
+
'cp1584', system['Hardware'] # type: ignore
|
|
192
|
+
)
|
|
193
|
+
hardware_hw = generate_hardware_hw_contents(
|
|
194
|
+
system['Hardware'], system_name, cpu_name # type: ignore
|
|
195
|
+
)
|
|
196
|
+
except ValueError:
|
|
197
|
+
logger.warning(
|
|
198
|
+
'Hardware configuration does not contain a CPU module. '
|
|
199
|
+
'Hardware.hw file will not be generated.'
|
|
200
|
+
)
|
|
201
|
+
hardware_hw = ''
|
|
179
202
|
write_to_file(
|
|
180
203
|
physical_path,
|
|
181
204
|
'Hardware.hw',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{# templates/config_pkg.tpl #}
|
|
2
2
|
|
|
3
3
|
<?xml version="1.0" encoding="utf-8"?>
|
|
4
|
-
<?AutomationStudio
|
|
4
|
+
<?AutomationStudio FileVersion="4.9"?>
|
|
5
5
|
<!--autogenerated {{ timestamp }}-->
|
|
6
6
|
<Configuration xmlns="http://br-automation.co.at/AS/Configuration">
|
|
7
7
|
<Objects>
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
{% endif %}
|
|
16
16
|
</Objects>
|
|
17
17
|
<Configuration ModuleId="X20cCP1584">
|
|
18
|
-
<AutomationRuntime Version="
|
|
19
|
-
<Build AdditionalBuildOptions="-D _HAS_GIT_VERSION" GccVersion="6.3.0" PreBuildStep="$(AS_PROJECT_PATH)/Scripts/as_build/prebuild.bat $(AS_PROJECT_PATH)"/>
|
|
18
|
+
<AutomationRuntime Version="F4.92"/>
|
|
19
|
+
<Build AdditionalBuildOptions="-D _HAS_GIT_VERSION" GccVersion="6.3.0" PreBuildStep="$(AS_PROJECT_PATH)/Scripts/as_build/prebuild.bat $(AS_PROJECT_PATH)" />
|
|
20
20
|
<DefaultTargetMemory Tasks="UserROM"/>
|
|
21
21
|
<Io Supervision="False"/>
|
|
22
22
|
<Opc WindowsServer="False"/>
|
|
23
23
|
<Safety SafetyRelease="0.0"/>
|
|
24
24
|
<Transfer AddToUserPart="True" AdditionalUserDir="\Scripts\as_build\user_partition" AllowDowngrade="True" AllowInitialTransfer="False" AllowPartitioning="False" ExecuteInitExitProgram="True" ForceInitialTransfer="False" GenerateRUCPackage="True" IdentificationTypeValue="" IgnoreVersion="True" KeepNonVolatileMemory="False" PreserveVariableValues="False" ProjectConsistent="False" RebootDuringTransfer="True" SavedOfflineInstallationFolder="" SavedPipDestinationFolder="" SavedRuntimeUtilityCenterPackagePath="" TargetIdentificationType="Always" TryToBootInRunMode="False" UserFilesIgnoreDifference="False"/>
|
|
25
25
|
<Vc FirmwareVersion=""/>
|
|
26
|
-
<OnlineConfiguration Name="
|
|
26
|
+
<OnlineConfiguration Name="PLC_Local" DeviceType="TCPIP" DeviceParameters="/IF=tcpip /LOPO=11159 /SA=1" ConnectionParameters="/COMT=2500 /RT=1000 /AM=* /SDT=5 /DAIP=192.168.1.10 /REPO=11169 /ANSL=1 /PT=11169" Description=""/>
|
|
27
27
|
</Configuration>
|
|
28
28
|
</Cpu>
|
|
29
29
|
<!--end of autogenerated-->
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{# templates/hardware_hw.tpl #}
|
|
2
2
|
|
|
3
3
|
<?xml version="1.0" encoding="utf-8"?>
|
|
4
|
-
<?AutomationStudio
|
|
4
|
+
<?AutomationStudio FileVersion="4.9"?>
|
|
5
5
|
<!--autogenerated {{ timestamp }}-->
|
|
6
6
|
<Hardware xmlns="http://br-automation.co.at/AS/Hardware">
|
|
7
7
|
{{ hardware }}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from jinja2 import Environment
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def combine_str(*strings: str) -> str:
|
|
8
|
+
return "\n".join(s for s in strings if s) + '\n'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def remove_multiple_newlines(string: str) -> str:
|
|
12
|
+
return re.sub('\n{3,}', '\n', string).strip()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def format_template(env: Environment, tpl_name: str, **kwargs) -> str:
|
|
16
|
+
template = env.get_template(tpl_name)
|
|
17
|
+
rendered = template.render(kwargs)
|
|
18
|
+
return remove_multiple_newlines(rendered)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def write_to_file(path: str, name: str, contents: str) -> None:
|
|
22
|
+
with open(os.path.join(path, name), 'w', encoding='utf-8') as file:
|
|
23
|
+
file.write(contents)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: g3projects
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: System G3 Project PLC files generator
|
|
5
|
-
Author
|
|
5
|
+
Author: Elektroline a.s.
|
|
6
6
|
Project-URL: Homepage, https://gitlab.elektroline.cz/plc/systemg3-py/SystemG3ProjectBuilder
|
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -14,6 +14,7 @@ Requires-Dist: jinja2
|
|
|
14
14
|
Requires-Dist: g3core
|
|
15
15
|
Requires-Dist: g3elements
|
|
16
16
|
Requires-Dist: g3hardware
|
|
17
|
+
Requires-Dist: g3tables
|
|
17
18
|
|
|
18
19
|
# System G3 Project PLC files generator
|
|
19
20
|
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{# templates/package_pkg_system.tpl #}
|
|
2
|
-
|
|
3
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
4
|
-
<?AutomationStudio FileVersion="4.9"?>
|
|
5
|
-
<Package xmlns="http://br-automation.co.at/AS/Program">
|
|
6
|
-
<Objects>
|
|
7
|
-
<Object Type="Program" Language="ANSIC" Description="ZoneTask">System</Object>
|
|
8
|
-
<Object Type="Program" Language="ANSIC" Description="ZoneTask">Comm</Object>
|
|
9
|
-
{% for name in zone_names %}
|
|
10
|
-
<Object Type="Program" Language="ANSIC" Description="ZoneTask">{{ name }}</Object>
|
|
11
|
-
{% endfor %}
|
|
12
|
-
<Object Type="File" Description="Global project variables" Private="true">Zone.var</Object>
|
|
13
|
-
</Objects>
|
|
14
|
-
</Package>
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
|
|
3
|
-
from ..logical import generate_logical_files
|
|
4
|
-
from ..physical import generate_physical_files
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def parse_arguments() -> argparse.Namespace:
|
|
8
|
-
parser = argparse.ArgumentParser(
|
|
9
|
-
description=(
|
|
10
|
-
'Create a G3 Project PLC files from a SystemConfig.json file.'
|
|
11
|
-
)
|
|
12
|
-
)
|
|
13
|
-
parser.add_argument(
|
|
14
|
-
'-s',
|
|
15
|
-
'--system-config',
|
|
16
|
-
type=str,
|
|
17
|
-
required=True,
|
|
18
|
-
help='Path to the SystemConfig.json file'
|
|
19
|
-
)
|
|
20
|
-
return parser.parse_args()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def generate_project_files(system_config_path: str) -> None:
|
|
24
|
-
generate_logical_files(system_config_path)
|
|
25
|
-
generate_physical_files(system_config_path)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def main() -> None:
|
|
29
|
-
args = parse_arguments()
|
|
30
|
-
generate_project_files(args.system_config)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if __name__ == "__main__":
|
|
34
|
-
main()
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import re
|
|
3
|
-
# import inspect
|
|
4
|
-
|
|
5
|
-
from jinja2 import Environment
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# def get_template(template_name: str) -> str:
|
|
9
|
-
# if (current_frame := inspect.currentframe()) is None:
|
|
10
|
-
# raise RuntimeError("Cannot determine caller frame")
|
|
11
|
-
# if (caller_frame := current_frame.f_back) is None:
|
|
12
|
-
# err = f'Unexpected error while fetching template "{template_name}"'
|
|
13
|
-
# raise RuntimeError(err)
|
|
14
|
-
# caller_filename = caller_frame.f_globals["__file__"]
|
|
15
|
-
# file_dir = os.path.dirname(os.path.abspath(caller_filename))
|
|
16
|
-
# file_path = os.path.join(file_dir, 'templates', template_name)
|
|
17
|
-
# with open(file_path, 'r') as file:
|
|
18
|
-
# return file.read()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def combine_str(*strings: str) -> str:
|
|
22
|
-
return "\n".join(s for s in strings if s) + '\n'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def remove_multiple_newlines(string: str) -> str:
|
|
26
|
-
return re.sub('\n{3,}', '\n', string).strip()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def format_template(env: Environment, tpl_name: str, **kwargs) -> str:
|
|
30
|
-
template = env.get_template(tpl_name)
|
|
31
|
-
rendered = template.render(kwargs)
|
|
32
|
-
return remove_multiple_newlines(rendered)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def write_to_file(path: str, name: str, contents: str) -> None:
|
|
36
|
-
with open(os.path.join(path, name), 'w', encoding='utf-8') as file:
|
|
37
|
-
file.write(contents)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/autogenerated_block.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{g3projects-0.1.2 → g3projects-0.2.1}/src/g3projects/logical/templates/variables_var_system.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|