-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from sw360/have_more_type_support
Have more type support
- Loading branch information
Showing
117 changed files
with
3,115 additions
and
1,673 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -28,10 +28,7 @@ htmlcov/ | |
coverage.xml | ||
|
||
# preliminary | ||
sw360/ | ||
cli/ | ||
xxsw360/ | ||
xxcli/ | ||
Releases/ | ||
|
||
# internal stuff | ||
|
This file contains 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 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 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2019-23 Siemens | ||
# Copyright (c) 2019-2024 Siemens | ||
# All Rights Reserved. | ||
# Author: [email protected] | ||
# | ||
|
@@ -9,12 +9,13 @@ | |
import logging | ||
import os | ||
import sys | ||
from typing import Any, Dict, Optional | ||
|
||
import requests | ||
import sw360.sw360_api | ||
from colorama import Fore, Style | ||
from cyclonedx.model.bom import Bom | ||
from cyclonedx.model.component import Component | ||
from sw360 import SW360Error | ||
|
||
import capycli.common.script_base | ||
from capycli.common.capycli_bom_support import CaPyCliBom, CycloneDxSupport | ||
|
@@ -39,57 +40,73 @@ def _bom_has_items_without_id(self, bom: Bom) -> bool: | |
|
||
return False | ||
|
||
def _find_by_id(self, component: Component) -> dict: | ||
def _find_by_id(self, component: Component) -> Optional[Dict[str, Any]]: | ||
if not self.client: | ||
print_red(" No client!") | ||
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360) | ||
|
||
sw360id = CycloneDxSupport.get_property_value(component, CycloneDxSupport.CDX_PROP_SW360ID) | ||
version = component.version or "" | ||
for step in range(3): | ||
try: | ||
release_details = self.client.get_release(sw360id) | ||
return release_details | ||
except sw360.sw360_api.SW360Error as swex: | ||
if swex.response.status_code == requests.codes['not_found']: | ||
except SW360Error as swex: | ||
if swex.response is None: | ||
print_red(" Unknown error: " + swex.message) | ||
elif swex.response.status_code == requests.codes['not_found']: | ||
print_yellow( | ||
" Not found " + component.name + | ||
", " + component.version + ", " + sw360id) | ||
", " + version + ", " + sw360id) | ||
break | ||
|
||
# only report other errors if this is the third attempt | ||
if step >= 2: | ||
print(Fore.LIGHTRED_EX + " Error retrieving release data: ") | ||
print( | ||
" " + component.name + ", " + component.version + | ||
" " + component.name + ", " + version + | ||
", " + sw360id) | ||
print(" Status Code: " + str(swex.response.status_code)) | ||
if swex.response: | ||
print(" Status Code: " + str(swex.response.status_code)) | ||
if swex.message: | ||
print(" Message: " + swex.message) | ||
print(Style.RESET_ALL) | ||
|
||
return None | ||
|
||
def _find_by_name(self, component: Component) -> dict: | ||
def _find_by_name(self, component: Component) -> Optional[Dict[str, Any]]: | ||
if not self.client: | ||
print_red(" No client!") | ||
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360) | ||
|
||
version = component.version or "" | ||
for step in range(3): | ||
try: | ||
releases = self.client.get_releases_by_name(component.name) | ||
if not releases: | ||
return None | ||
|
||
for r in releases: | ||
if r.get("version", "") == component.version: | ||
if r.get("version", "") == version: | ||
return r | ||
|
||
return None | ||
except sw360.sw360_api.SW360Error as swex: | ||
if swex.response.status_code == requests.codes['not_found']: | ||
except SW360Error as swex: | ||
if swex.response is None: | ||
print_red(" Unknown error: " + swex.message) | ||
elif swex.response.status_code == requests.codes['not_found']: | ||
print_yellow( | ||
" Not found " + component.name + | ||
", " + component.version) | ||
", " + version) | ||
break | ||
|
||
# only report other errors if this is the third attempt | ||
if step >= 2: | ||
print(Fore.LIGHTRED_EX + " Error retrieving release data: ") | ||
print( | ||
" " + component.name + ", " + component.version) | ||
print(" Status Code: " + str(swex.response.status_code)) | ||
" " + component.name + ", " + version) | ||
if swex.response: | ||
print(" Status Code: " + str(swex.response.status_code)) | ||
if swex.message: | ||
print(" Message: " + swex.message) | ||
print(Style.RESET_ALL) | ||
|
@@ -99,6 +116,10 @@ def _find_by_name(self, component: Component) -> dict: | |
def check_releases(self, bom: Bom) -> int: | ||
"""Checks for each release in the list whether it can be found on the specified | ||
SW360 instance.""" | ||
if not self.client: | ||
print_red(" No client!") | ||
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360) | ||
|
||
found_count = 0 | ||
for component in bom.components: | ||
release_details = None | ||
|
@@ -116,7 +137,7 @@ def check_releases(self, bom: Bom) -> int: | |
found_count += 1 | ||
continue | ||
|
||
if not id: | ||
if not sw360id: | ||
print_yellow( | ||
" " + component.name + | ||
", " + component.version + | ||
|
@@ -125,7 +146,7 @@ def check_releases(self, bom: Bom) -> int: | |
|
||
return found_count | ||
|
||
def run(self, args): | ||
def run(self, args: Any) -> None: | ||
"""Main method()""" | ||
if args.debug: | ||
global LOG | ||
|
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2019-23 Siemens | ||
# Copyright (c) 2019-2024 Siemens | ||
# All Rights Reserved. | ||
# Author: [email protected] | ||
# | ||
|
@@ -12,10 +12,10 @@ | |
from typing import Any, Dict, Optional | ||
|
||
import requests | ||
import sw360.sw360_api | ||
from colorama import Fore, Style | ||
from cyclonedx.model.bom import Bom | ||
from cyclonedx.model.component import Component | ||
from sw360 import SW360Error | ||
|
||
import capycli.common.script_base | ||
from capycli.common.capycli_bom_support import CaPyCliBom, CycloneDxSupport | ||
|
@@ -39,20 +39,26 @@ def _bom_has_items_without_id(self, bom: Bom) -> bool: | |
return False | ||
|
||
def _find_by_id(self, component: Component) -> Optional[Dict[str, Any]]: | ||
if not self.client: | ||
print_red(" No client!") | ||
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360) | ||
|
||
sw360id = CycloneDxSupport.get_property_value(component, CycloneDxSupport.CDX_PROP_SW360ID) | ||
version = component.version or "" | ||
try: | ||
release_details = self.client.get_release(sw360id) | ||
return release_details | ||
except sw360.sw360_api.SW360Error as swex: | ||
if swex.response.status_code == requests.codes['not_found']: | ||
except SW360Error as swex: | ||
if swex.response is None: | ||
print_red(" Unknown error: " + swex.message) | ||
elif swex.response.status_code == requests.codes['not_found']: | ||
print( | ||
Fore.LIGHTYELLOW_EX + " Not found " + component.name + | ||
", " + component.version + ", " + | ||
sw360id + Style.RESET_ALL) | ||
", " + version + ", " + sw360id + Style.RESET_ALL) | ||
else: | ||
print(Fore.LIGHTRED_EX + " Error retrieving release data: ") | ||
print( | ||
" " + str(component.name) + ", " + str(component.version) + | ||
" " + component.name + ", " + version + | ||
", " + sw360id) | ||
print(" Status Code: " + str(swex.response.status_code)) | ||
if swex.message: | ||
|
@@ -62,25 +68,32 @@ def _find_by_id(self, component: Component) -> Optional[Dict[str, Any]]: | |
return None | ||
|
||
def _find_by_name(self, component: Component) -> Optional[Dict[str, Any]]: | ||
if not self.client: | ||
print_red(" No client!") | ||
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360) | ||
|
||
version = component.version or "" | ||
try: | ||
releases = self.client.get_releases_by_name(component.name) | ||
if not releases: | ||
return None | ||
|
||
for r in releases: | ||
if r.get("version", "") == component.version: | ||
if r.get("version", "") == version: | ||
return self.client.get_release_by_url(r["_links"]["self"]["href"]) | ||
|
||
return None | ||
except sw360.sw360_api.SW360Error as swex: | ||
if swex.response.status_code == requests.codes['not_found']: | ||
except SW360Error as swex: | ||
if swex.response is None: | ||
print_red(" Unknown error: " + swex.message) | ||
elif swex.response.status_code == requests.codes['not_found']: | ||
print( | ||
Fore.LIGHTYELLOW_EX + " Not found " + component.name + | ||
", " + component.version + ", " + | ||
", " + version + ", " + | ||
Style.RESET_ALL) | ||
else: | ||
print(Fore.LIGHTRED_EX + " Error retrieving release data: ") | ||
print(" " + str(component.name) + ", " + str(component.version)) | ||
print(" " + str(component.name) + ", " + str(version)) | ||
print(" Status Code: " + str(swex.response.status_code)) | ||
if swex.message: | ||
print(" Message: " + swex.message) | ||
|
@@ -89,6 +102,10 @@ def _find_by_name(self, component: Component) -> Optional[Dict[str, Any]]: | |
return None | ||
|
||
def show_bom_item_status(self, bom: Bom, all: bool = False) -> None: | ||
if not self.client: | ||
print_red(" No client!") | ||
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360) | ||
|
||
for component in bom.components: | ||
release = None | ||
id = CycloneDxSupport.get_property_value(component, CycloneDxSupport.CDX_PROP_SW360ID) | ||
|
@@ -117,13 +134,19 @@ def show_bom_item_status(self, bom: Bom, all: bool = False) -> None: | |
release["_links"]["sw360:component"]["href"] | ||
) | ||
) | ||
if not comp_sw360: | ||
print_red("Error accessing component") | ||
continue | ||
|
||
rel_list = comp_sw360["_embedded"]["sw360:releases"] | ||
print(" " + component.name + ", " + component.version + " => ", end="", flush=True) | ||
print("releases for component found = " + str(len(rel_list))) | ||
for orel in rel_list: | ||
href = orel["_links"]["self"]["href"] | ||
rel = self.client.get_release_by_url(href) | ||
if not rel: | ||
print_red("Error accessing release " + href) | ||
continue | ||
cs = rel.get("clearingState", "(unkown clearing state)") | ||
if cs == "APPROVED": | ||
print(Fore.LIGHTGREEN_EX, end="", flush=True) | ||
|
@@ -141,7 +164,7 @@ def show_bom_item_status(self, bom: Bom, all: bool = False) -> None: | |
" => --- no id ---") | ||
continue | ||
|
||
def run(self, args) -> None: | ||
def run(self, args: Any) -> None: | ||
"""Main method()""" | ||
if args.debug: | ||
global LOG | ||
|
Oops, something went wrong.