-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_smart_data_models.py
65 lines (53 loc) · 2.28 KB
/
generate_smart_data_models.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
import os
import sys
import importlib
import traceback
from besser_generator.smart_data_model.json_schema_generator import JSONSchemaGenerator
def process_model_file(model_file, models_dir, output_base_dir):
model_name = os.path.splitext(model_file)[0]
model_output_dir = os.path.join(output_base_dir, model_name)
try:
# Add the models directory to Python path if not already there
if models_dir not in sys.path:
sys.path.append(os.path.dirname(models_dir))
# Import the domain model dynamically
module = importlib.import_module(f"buml_generated_models.{model_name}")
if hasattr(module, 'domain_model'):
os.makedirs(model_output_dir, exist_ok=True)
generator = JSONSchemaGenerator(module.domain_model, model_output_dir)
generator.generate()
print(f"Successfully generated schema for {model_name}")
return True
else:
print(f"Skipping {model_name} - no domain_model found")
return False
except ImportError as e:
# Skip files with missing dependencies for now
print(f"Skipping {model_name} - missing dependency: {str(e)}")
return False
except Exception as e:
print(f"Error processing {model_name}: {str(e)}")
print(traceback.format_exc())
return False
def create_smart_data_models():
current_dir = os.path.dirname(os.path.abspath(__file__))
models_dir = os.path.join(current_dir, "buml_generated_models")
output_base_dir = os.path.join(current_dir, "generatedsmartdata")
os.makedirs(output_base_dir, exist_ok=True)
# Process core type modules first
core_modules = [
'_3gpp_common_yang_types.py',
'_3gpp_5g_common_yang_types.py'
]
model_files = [f for f in os.listdir(models_dir)
if f.endswith('.py') and not f.startswith('__')]
# Process core modules first
for core_module in core_modules:
if core_module in model_files:
process_model_file(core_module, models_dir, output_base_dir)
model_files.remove(core_module)
# Then process remaining modules
for model_file in model_files:
process_model_file(model_file, models_dir, output_base_dir)
if __name__ == "__main__":
create_smart_data_models()