|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | - |
15 | | -from __future__ import (absolute_import, division, print_function) |
| 14 | +from __future__ import absolute_import, division, print_function |
| 15 | +from typing import Optional |
16 | 16 | import re |
17 | 17 |
|
18 | 18 | __metaclass__ = type |
@@ -74,15 +74,24 @@ def _flatten_dict_list(i, l, parents): |
74 | 74 |
|
75 | 75 | return state |
76 | 76 |
|
77 | | - def extract_products_from_manifests(self, manifests): |
| 77 | + def extract_products_from_manifests(self, manifests, os_distribution: Optional[str] = None): |
78 | 78 | products = dict() |
79 | 79 | for manifest in manifests: |
80 | | - for parcel in manifest['parcels']: |
| 80 | + for parcel in manifest["parcels"]: |
| 81 | + # fetch the full parcel name from the manifest |
| 82 | + full_parcel_name = str(parcel["parcelName"]) |
| 83 | + # the parcel OS distribution is between the last "-" and the ".parcel" extension |
| 84 | + parcel_os_distribution = full_parcel_name[ |
| 85 | + full_parcel_name.rindex("-") |
| 86 | + + 1: full_parcel_name.rindex(".parcel") |
| 87 | + ] |
81 | 88 | # take first parcel, strip off OS name and file extension |
82 | | - parcel_name = re.sub(r"-[a-z0-9]+\.parcel$", "", str(parcel['parcelName'])) |
| 89 | + parcel_name = re.sub(r"-[a-z0-9]+\.parcel$", "", full_parcel_name) |
83 | 90 | # the product name is before the first dash |
84 | | - product = parcel_name[:parcel_name.index("-")] |
85 | | - if product not in products: |
| 91 | + product = parcel_name[: parcel_name.index("-")] |
| 92 | + if product not in products and ( |
| 93 | + os_distribution == parcel_os_distribution or os_distribution is None |
| 94 | + ): |
86 | 95 | # the version string is everything after the first dash |
87 | 96 | version = parcel_name[parcel_name.index("-") + 1:] |
88 | 97 | products[product] = version |
|
0 commit comments