-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresolve-and-validate.py
More file actions
59 lines (46 loc) · 1.74 KB
/
resolve-and-validate.py
File metadata and controls
59 lines (46 loc) · 1.74 KB
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
# import
import os
import sys
import cellml
#
# load a CellML model, resolve any imports, and validate the full model.
#
# usage:
# python resolve-and-validate.py <CellML model filename> [strict]
#
# strict (optional) = false, use a non-strict parser and importer (i.e., allow CellML 1.0 and 1.1 models)
# default is strict mode (i.e., only allow CellML 2.0 models)
#
cellml_file = sys.argv[1]
cellml_file_dir = os.path.dirname(cellml_file)
print('Working on the CellML file: {}; resolving imports with the context: {}'.format(cellml_file, cellml_file_dir))
cellml_strict_mode = True
if len(sys.argv) > 2:
strict_mode = sys.argv[2]
if strict_mode == 'false':
cellml_strict_mode = False
if cellml_strict_mode:
print(' Parsing files in STRICT mode (only CellML 2.0 models accepted)')
else:
print(' Parsing files in NON-STRICT mode (any CellML models accepted)')
model = cellml.parse_model(cellml_file, cellml_strict_mode)
if cellml.validate_model(model) > 0:
exit(-1)
importer = cellml.resolve_imports(model, cellml_file_dir, cellml_strict_mode)
if model.hasUnresolvedImports():
print("unresolved imports?")
exit(-2)
if cellml.validate_model(model) > 0:
print('Validation issues found')
exit(-3)
print('Model was parsed, resolved, and validated without any issues.')
# need a flattened model for analysing
flat_model = cellml.flatten_model(model, importer)
if cellml.validate_model(flat_model) > 0:
print('Validation issues found in flattened model')
exit(-4)
print('Model was flattened without any issues.')
# this will report any issues that come up in analysing the model to prepare for code generation
analysed_model = cellml.analyse_model(flat_model)
cellml.generate_code(analysed_model)
print('Done.')