|
19 | 19 | import toml |
20 | 20 | from pathlib import Path |
21 | 21 | from spdx.utils import SPDXNone, UnKnown |
22 | | -from typing import Union, Optional, Iterator, Iterable, Any |
| 22 | +from typing import Union, Optional, Iterator, Any, Tuple |
23 | 23 |
|
24 | 24 | from mbed_tools_ci_scripts.utils.configuration import ConfigurationVariable, configuration |
25 | 25 | from mbed_tools_ci_scripts.utils.definitions import UNKNOWN |
@@ -106,21 +106,39 @@ def ignore_path(p: Path) -> bool: |
106 | 106 | return list_all_files(project_root, ignore_path) |
107 | 107 |
|
108 | 108 |
|
109 | | -def determine_checked_packages_from_string(checked_packages: Any) -> Iterable[Any]: |
110 | | - """Determines the list of packages for which the licence has been checked.""" |
| 109 | +def _convert_list_into_dict(checked_packages: Any) -> dict: |
| 110 | + checked_package_description = dict() |
| 111 | + for item in checked_packages: |
| 112 | + info = item.split("=" if "=" in item else ":") |
| 113 | + checked_package_description[info[0].strip()] = info[-1].strip() if len(info) > 1 else None |
| 114 | + return checked_package_description |
| 115 | + |
| 116 | + |
| 117 | +def determine_checked_packages_from_configuration_entry(checked_packages: Any) -> dict: |
| 118 | + """Determines the list of packages for which the licence has been manually checked.""" |
111 | 119 | if isinstance(checked_packages, str): |
112 | 120 | checked_packages = checked_packages.split(", ") |
113 | | - if isinstance(checked_packages, (list, dict, tuple, set)): |
114 | | - yield from checked_packages |
| 121 | + if isinstance(checked_packages, (list, tuple, set)): |
| 122 | + return _convert_list_into_dict(checked_packages) |
| 123 | + if isinstance(checked_packages, dict): |
| 124 | + return checked_packages |
| 125 | + return dict() |
115 | 126 |
|
116 | 127 |
|
117 | | -def get_packages_with_checked_licence() -> Iterable[str]: |
| 128 | +def get_packages_with_checked_licence() -> dict: |
118 | 129 | """Determines the list of packages for which the licence has been checked from configuration.""" |
119 | | - yield from determine_checked_packages_from_string( |
| 130 | + return determine_checked_packages_from_configuration_entry( |
120 | 131 | configuration.get_value(ConfigurationVariable.PACKAGES_WITH_CHECKED_LICENCE) |
121 | 132 | ) |
122 | 133 |
|
123 | 134 |
|
124 | | -def is_package_licence_checked(package_name: str) -> bool: |
125 | | - """States whether the licence of a package has been checked and hence, that its licence is compliant.""" |
126 | | - return package_name.strip() in get_packages_with_checked_licence() |
| 135 | +def get_package_manual_check(package_name: str) -> Tuple[bool, Optional[str]]: |
| 136 | + """Gets information about package licence manual check.""" |
| 137 | + checked_packages = get_packages_with_checked_licence() |
| 138 | + return bool(package_name.strip() in checked_packages), checked_packages.get(package_name.strip()) |
| 139 | + |
| 140 | + |
| 141 | +def is_package_licence_manually_checked(package_name: str) -> bool: |
| 142 | + """States whether the licence of a package has been manually checked and hence, that its licence is compliant.""" |
| 143 | + checked, _ = get_package_manual_check(package_name) |
| 144 | + return checked |
0 commit comments