Skip to content

Commit 58a1ab4

Browse files
Oleksandr Muzyka (EPAM)Hanna-Shalamitskaya-EPAM
authored andcommitted
Fix SAMM CLI usage
1 parent 6f4fcac commit 58a1ab4

File tree

12 files changed

+328
-106
lines changed

12 files changed

+328
-106
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
13+
SAMM_VERSION = "2.2.0"
14+
JAVA_CLI_VERSION = "2.10.2"

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/loader/model_element_factory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ def create_element(self, element_node: Node) -> Union[Type[Base], DataType, Type
9393
"""
9494
element_type = self._get_element_type(element_node)
9595
instantiator_class = self._instantiators.get(element_type, self._create_instantiator(element_type))
96-
instance = instantiator_class.get_instance(element_node)
96+
try:
97+
instance = instantiator_class.get_instance(element_node)
98+
except Exception as error:
99+
print(error)
100+
raise
101+
97102
self._add_to_cache(instance)
98103

99104
return instance

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Any
1616

1717
from esmf_aspect_meta_model_python.samm_cli.constants import SAMMCLICommands, SAMMCLICommandTypes
18-
from scripts.download_samm_cli import download_samm_cli
18+
from esmf_aspect_meta_model_python.samm_cli.download import download_samm_cli
1919

2020

2121
class SammCli:
@@ -33,7 +33,7 @@ def __init__(self):
3333
def _get_client_path():
3434
"""Get path to the SAMM CLI executable file."""
3535
base_path = Path(__file__).resolve()
36-
cli_path = join(base_path.parents[2], "samm-cli", "samm.exe")
36+
cli_path = join(base_path.parents[0], "samm-cli", "samm.exe")
3737

3838
return cli_path
3939

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/constants.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
# SPDX-License-Identifier: MPL-2.0
1111
"""Constants for SAMM CLI commands and types."""
1212

13+
from string import Template
14+
15+
from esmf_aspect_meta_model_python.constants import JAVA_CLI_VERSION, SAMM_VERSION
16+
17+
18+
class SAMMCliConstants:
19+
BASE_PATH = Template("https://github.com/eclipse-esmf/esmf-sdk/releases/download/v$version_number/$file_name")
20+
JAVA_CLI_VERSION = JAVA_CLI_VERSION
21+
LINUX_FILE_NAME = Template("samm-cli-$version_number-linux-x86_64.tar.gz")
22+
SAMM_VERSION = SAMM_VERSION
23+
WIN_FILE_NAME = Template("samm-cli-$version_number-windows-x86_64.zip")
24+
1325

1426
class SAMMCLICommands:
1527
"""SAMM CLI command names."""
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""Download SAMM CLI.
2+
3+
Windows: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-windows-x86_64.zip
4+
Linux: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-linux-x86_64.tar.gz
5+
JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2.jar
6+
"""
7+
8+
import os
9+
import platform
10+
import sys
11+
import zipfile
12+
13+
from pathlib import Path
14+
15+
import requests
16+
17+
from esmf_aspect_meta_model_python.samm_cli.constants import SAMMCliConstants as Const
18+
19+
20+
def get_samm_cli_file_name():
21+
"""Get a SAMM CLI file name for the current platform."""
22+
23+
if platform.system() == "Windows":
24+
file_name = Const.WIN_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
25+
elif platform.system() == "Linux":
26+
file_name = Const.LINUX_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
27+
else:
28+
raise NotImplementedError(
29+
f"Please download a SAMM CLI manually for your operation system from '{Const.BASE_PATH}'"
30+
)
31+
32+
return file_name
33+
34+
35+
def download_archive_file(url, archive_file):
36+
"""Download an archive file."""
37+
with open(archive_file, "wb") as f:
38+
print("Downloading %s" % archive_file)
39+
response = requests.get(url, allow_redirects=True, stream=True)
40+
content_len = response.headers.get("content-length")
41+
42+
if content_len is None:
43+
f.write(response.content)
44+
else:
45+
total_len = int(content_len)
46+
data_len = 0
47+
chunk = 4096
48+
progress_bar_len = 50
49+
50+
for content_data in response.iter_content(chunk_size=chunk):
51+
data_len += len(content_data)
52+
53+
f.write(content_data)
54+
55+
curr_progress = int(50 * data_len / total_len)
56+
sys.stdout.write(f"\r[{'*' * curr_progress}{' ' * (progress_bar_len - curr_progress)}]")
57+
sys.stdout.flush()
58+
59+
60+
def download_samm_cli():
61+
try:
62+
samm_cli_file_name = get_samm_cli_file_name()
63+
except NotImplementedError as error:
64+
print(error)
65+
else:
66+
print(f"Start downloading SAMM CLI {samm_cli_file_name}")
67+
url = Const.BASE_PATH.substitute(version_number=Const.JAVA_CLI_VERSION, file_name=samm_cli_file_name)
68+
dir_path = Path(__file__).resolve().parents[0]
69+
archive_file = os.path.join(dir_path, samm_cli_file_name)
70+
71+
download_archive_file(url, archive_file)
72+
print("\nSAMM CLI archive file downloaded")
73+
74+
print("Start extracting files")
75+
archive = zipfile.ZipFile(archive_file)
76+
extracted_files_path = os.path.join(dir_path, "samm-cli")
77+
for file in archive.namelist():
78+
archive.extract(file, extracted_files_path)
79+
archive.close()
80+
print("Done extracting files")
81+
82+
print("Deleting SAMM CLI archive file")
83+
os.remove(archive_file)

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_meta_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
import rdflib
1818

19+
import esmf_aspect_meta_model_python.constants as const
20+
1921

2022
class SammUnitsGraph:
2123
"""Model units graph."""
2224

23-
SAMM_VERSION = "2.2.0"
25+
SAMM_VERSION = const.SAMM_VERSION
2426
UNIT_FILE_PATH = f"samm_aspect_meta_model/samm/unit/{SAMM_VERSION}/units.ttl"
2527
QUERY_TEMPLATE = Template("SELECT ?key ?value WHERE {$unit ?key ?value .}")
2628

core/esmf-aspect-meta-model-python/scripts/constants.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,7 @@
1212
from os.path import join
1313
from string import Template
1414

15-
16-
SAMM_VERSION = "2.2.0"
17-
JAVA_CLI_VERSION = "2.10.2"
18-
19-
20-
class SAMMCliConstants:
21-
BASE_PATH = Template("https://github.com/eclipse-esmf/esmf-sdk/releases/download/v$version_number/$file_name")
22-
JAVA_CLI_VERSION = JAVA_CLI_VERSION
23-
LINUX_FILE_NAME = Template("samm-cli-$version_number-linux-x86_64.tar.gz")
24-
SAMM_VERSION = SAMM_VERSION
25-
WIN_FILE_NAME = Template("samm-cli-$version_number-windows-x86_64.zip")
15+
from esmf_aspect_meta_model_python.constants import JAVA_CLI_VERSION, SAMM_VERSION
2616

2717

2818
class TestModelConstants:

core/esmf-aspect-meta-model-python/scripts/download_samm_cli.py

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,7 @@
55
JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2.jar
66
"""
77

8-
import os
9-
from pathlib import Path
10-
import platform
11-
import requests
12-
import sys
13-
import zipfile
14-
15-
from scripts.constants import SAMMCliConstants as Const
16-
17-
18-
def get_samm_cli_file_name():
19-
"""Get a SAMM CLI file name for the current platform."""
20-
21-
if platform.system() == "Windows":
22-
file_name = Const.WIN_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
23-
elif platform.system() == "Linux":
24-
file_name = Const.LINUX_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
25-
else:
26-
raise NotImplementedError(
27-
f"Please download a SAMM CLI manually for your operation system from '{Const.BASE_PATH}'"
28-
)
29-
30-
return file_name
31-
32-
33-
def download_archive_file(url, archive_file):
34-
"""Download an archive file."""
35-
with open(archive_file, "wb") as f:
36-
print("Downloading %s" % archive_file)
37-
response = requests.get(url, allow_redirects=True, stream=True)
38-
content_len = response.headers.get('content-length')
39-
40-
if content_len is None:
41-
f.write(response.content)
42-
else:
43-
total_len = int(content_len)
44-
data_len = 0
45-
chunk = 4096
46-
progress_bar_len = 50
47-
48-
for content_data in response.iter_content(chunk_size=chunk):
49-
data_len += len(content_data)
50-
51-
f.write(content_data)
52-
53-
curr_progress = int(50 * data_len / total_len)
54-
sys.stdout.write(f"\r[{'*' * curr_progress}{' ' * (progress_bar_len - curr_progress)}]")
55-
sys.stdout.flush()
56-
57-
58-
def download_samm_cli():
59-
try:
60-
samm_cli_file_name = get_samm_cli_file_name()
61-
except NotImplementedError as error:
62-
print(error)
63-
else:
64-
print(f"Start downloading SAMM CLI {samm_cli_file_name}")
65-
url = Const.BASE_PATH.substitute(version_number=Const.JAVA_CLI_VERSION, file_name=samm_cli_file_name)
66-
dir_path = Path(__file__).resolve().parents[1]
67-
archive_file = os.path.join(dir_path, samm_cli_file_name)
68-
69-
download_archive_file(url, archive_file)
70-
print("\nSAMM CLI archive file downloaded")
71-
72-
print("Start extracting files")
73-
archive = zipfile.ZipFile(archive_file)
74-
for file in archive.namelist():
75-
archive.extract(file, "samm-cli")
76-
archive.close()
77-
print("Done extracting files.")
78-
79-
print("Deleting SAMM CLI archive file.")
80-
os.remove(archive_file)
8+
from esmf_aspect_meta_model_python.samm_cli.download import download_samm_cli
819

8210

8311
if __name__ == "__main__":

core/esmf-aspect-meta-model-python/scripts/samm/download_samm_release.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
import requests
1717

18-
SAMM_VERSION_TO_DOWNLOAD = "2.2.0"
18+
from esmf_aspect_meta_model_python.constants import SAMM_VERSION
1919

2020

2121
def main():
2222
"""Downloads the release .jar of the samm for the selected version and extracts the SAMM files"""
23-
download_jar(SAMM_VERSION_TO_DOWNLOAD)
24-
extract_jar(SAMM_VERSION_TO_DOWNLOAD)
23+
download_jar(SAMM_VERSION)
24+
extract_jar(SAMM_VERSION)
2525
print("current path: ", pathlib.Path().resolve())
2626

2727

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
1-
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
21
#
3-
# See the AUTHORS file(s) distributed with this work for additional
4-
# information regarding authorship.
2+
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
53
#
6-
# This Source Code Form is subject to the terms of the Mozilla Public
7-
# License, v. 2.0. If a copy of the MPL was not distributed with this
8-
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9-
#
10-
# SPDX-License-Identifier: MPL-2.0
114

12-
@prefix : <urn:samm:org.eclipse.esmf.test.general:2.1.0#> .
135
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
146
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
15-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
7+
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#> .
168
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
9+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
10+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
11+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
12+
@prefix : <urn:samm:org.eclipse.esmf.test.general:2.1.0#> .
1713

18-
:Aspect a samm:Aspect ;
14+
:TestAspect a samm:Aspect ;
1915
samm:preferredName "Test Aspect"@en ;
20-
samm:description "This is a test description"@en ;
21-
samm:properties ( ) ;
16+
samm:description "A test aspect for integration testing"@en ;
17+
samm:properties ( :testProperty :testComplexProperty ) ;
2218
samm:operations ( ) .
19+
20+
:testProperty a samm:Property ;
21+
samm:preferredName "Test Property"@en ;
22+
samm:description "A simple test property"@en ;
23+
samm:characteristic samm-c:Text .
24+
25+
:testComplexProperty a samm:Property ;
26+
samm:preferredName "Test Complex Property"@en ;
27+
samm:description "A complex test property"@en ;
28+
samm:characteristic :TestCharacteristic .
29+
30+
:TestCharacteristic a samm-c:SingleEntity ;
31+
samm:preferredName "Test Characteristic"@en ;
32+
samm:description "A test characteristic"@en ;
33+
samm:dataType :TestEntity .
34+
35+
:TestEntity a samm:Entity ;
36+
samm:preferredName "Test Entity"@en ;
37+
samm:description "A test entity"@en ;
38+
samm:properties ( :entityProperty1 :entityProperty2 ) .
39+
40+
:entityProperty1 a samm:Property ;
41+
samm:preferredName "Entity Property 1"@en ;
42+
samm:characteristic samm-c:Text .
43+
44+
:entityProperty2 a samm:Property ;
45+
samm:preferredName "Entity Property 2"@en ;
46+
samm:characteristic :NumberCharacteristic .
47+
48+
:NumberCharacteristic a samm:Characteristic ;
49+
samm:preferredName "Number Characteristic"@en ;
50+
samm:dataType xsd:integer .

0 commit comments

Comments
 (0)