-
Notifications
You must be signed in to change notification settings - Fork 6
Fix SAMM CLI usage #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/constants.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH | ||
| # | ||
| # See the AUTHORS file(s) distributed with this work for additional | ||
| # information regarding authorship. | ||
| # | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| # | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
|
|
||
| SAMM_VERSION = "2.2.0" | ||
| JAVA_CLI_VERSION = "2.11.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/download.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """Download SAMM CLI. | ||
|
|
||
| Windows: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-windows-x86_64.zip | ||
| Linux: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-linux-x86_64.tar.gz | ||
| JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2.jar | ||
| """ | ||
|
|
||
| import os | ||
| import platform | ||
| import sys | ||
| import zipfile | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import requests | ||
|
|
||
| from esmf_aspect_meta_model_python.samm_cli.constants import SAMMCliConstants as Const | ||
|
|
||
|
|
||
| def get_samm_cli_file_name(): | ||
| """Get a SAMM CLI file name for the current platform.""" | ||
|
|
||
| if platform.system() == "Windows": | ||
| file_name = Const.WIN_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION) | ||
| elif platform.system() == "Linux": | ||
| file_name = Const.LINUX_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION) | ||
| else: | ||
| raise NotImplementedError( | ||
| f"Please download a SAMM CLI manually for your operation system from '{Const.BASE_PATH}'" | ||
| ) | ||
|
|
||
| return file_name | ||
|
|
||
|
|
||
| def download_archive_file(url, archive_file): | ||
| """Download an archive file.""" | ||
| with open(archive_file, "wb") as f: | ||
| print("Downloading %s" % archive_file) | ||
| response = requests.get(url, allow_redirects=True, stream=True) | ||
| content_len = response.headers.get("content-length") | ||
|
|
||
| if content_len is None: | ||
| f.write(response.content) | ||
| else: | ||
| total_len = int(content_len) | ||
| data_len = 0 | ||
| chunk = 4096 | ||
| progress_bar_len = 50 | ||
|
|
||
| for content_data in response.iter_content(chunk_size=chunk): | ||
| data_len += len(content_data) | ||
|
|
||
| f.write(content_data) | ||
|
|
||
| curr_progress = int(50 * data_len / total_len) | ||
| sys.stdout.write(f"\r[{'*' * curr_progress}{' ' * (progress_bar_len - curr_progress)}]") | ||
| sys.stdout.flush() | ||
|
|
||
|
|
||
| def download_samm_cli(): | ||
| try: | ||
| samm_cli_file_name = get_samm_cli_file_name() | ||
| except NotImplementedError as error: | ||
| print(error) | ||
| else: | ||
| print(f"Start downloading SAMM CLI {samm_cli_file_name}") | ||
| url = Const.BASE_PATH.substitute(version_number=Const.JAVA_CLI_VERSION, file_name=samm_cli_file_name) | ||
| dir_path = Path(__file__).resolve().parents[0] | ||
| archive_file = os.path.join(dir_path, samm_cli_file_name) | ||
|
|
||
| download_archive_file(url, archive_file) | ||
| print("\nSAMM CLI archive file downloaded") | ||
|
|
||
| print("Start extracting files") | ||
| archive = zipfile.ZipFile(archive_file) | ||
| extracted_files_path = os.path.join(dir_path, "samm-cli") | ||
| for file in archive.namelist(): | ||
| archive.extract(file, extracted_files_path) | ||
| archive.close() | ||
| print("Done extracting files") | ||
|
|
||
| print("Deleting SAMM CLI archive file") | ||
| os.remove(archive_file) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 4 additions & 76 deletions
80
core/esmf-aspect-meta-model-python/scripts/download_samm_cli.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.