| |
@@ -41,6 +41,7 @@
|
| |
"""
|
| |
|
| |
import yaml
|
| |
+ import ast
|
| |
|
| |
from modulemd.components import ModuleComponents
|
| |
from modulemd.content import ModuleContent
|
| |
@@ -170,9 +171,49 @@
|
| |
if "multilib" in e:
|
| |
extras["multilib"] = e["multilib"]
|
| |
self.components.rpms.add_package(p, **extras)
|
| |
+
|
| |
+ #Iterate through the filtered packages (if they exist)
|
| |
if "filter" in yml["data"]["components"]["rpms"]:
|
| |
- self.components.rpms.filter = \
|
| |
- set(yml["data"]["components"]["rpms"]["filter"])
|
| |
+
|
| |
+ #Grab list of RPMs, filters, and packages, and create a dict
|
| |
+ #to store all the filtered packages' arches
|
| |
+ filtered_packages = {}
|
| |
+ rpms_yaml = yml["data"]["components"]["rpms"]
|
| |
+ filter_yaml = rpms_yaml["filter"]
|
| |
+ packages_yaml = rpms_yaml["packages"]
|
| |
+
|
| |
+ #Iterate through all the filters
|
| |
+ for filtkey, filt in filter_yaml:
|
| |
+ for p in packages_yaml:
|
| |
+
|
| |
+ #Exclude this package
|
| |
+ if ((p == filt) or
|
| |
+ (filtkey in filtered_packages) or
|
| |
+ (filt in packages_yaml)):
|
| |
+ continue
|
| |
+
|
| |
+ arches = filt.get("arches")
|
| |
+
|
| |
+ #This case is for excluding secondary architectures
|
| |
+ if arches:
|
| |
+ if arches[0] == ".+":
|
| |
+ arches = ["*"]
|
| |
+ filt = filt + ".+"
|
| |
+ else: #Otherwise, exclude all package architectures
|
| |
+ arches = ["*"]
|
| |
+ filtered_packages[filt] = arches
|
| |
+
|
| |
+ #Combine like-architectures by switching dict keys with dict values
|
| |
+ filtered = {}
|
| |
+ for pkey, pvalue in filtered_packages:
|
| |
+ for a in pvalue:
|
| |
+ if a not in filtered:
|
| |
+ filtered[a] = [pkey]
|
| |
+ else:
|
| |
+ filtered[a].append(pkey)
|
| |
+
|
| |
+ #This is for json formatting. (Python is picky about ' vs ")
|
| |
+ self.components.rpms.filter = set([str(filtered).replace("'",'"')])
|
| |
|
| |
def dump(self, f):
|
| |
"""Dumps the metadata into the supplied file.
|
| |
@@ -261,8 +302,30 @@
|
| |
data["data"]["components"]["rpms"]["packages"][p] = \
|
| |
extra
|
| |
if self.components.rpms.filter:
|
| |
+ filter_list = list(self.components.rpms.filter)[0]
|
| |
+ filter_str = ast.literal_eval(filter_list)
|
| |
+ if isinstance(filter_str, str):
|
| |
+ filter_dict = ast.literal_eval(filter_str[0])
|
| |
+ else:
|
| |
+ filter_dict = filter_str
|
| |
+ filter_dict_reversed = dict()
|
| |
+ for a in filter_dict:
|
| |
+ for p in filter_dict[a]:
|
| |
+ arches = dict()
|
| |
+ if p not in filter_dict_reversed:
|
| |
+ if ".+" in p:
|
| |
+ (name, empty) = p.split(".+")
|
| |
+ arches["arches"] = [".+"]
|
| |
+ filter_dict_reversed[name] = arches
|
| |
+ else:
|
| |
+ arches["arches"] = [a]
|
| |
+ filter_dict_reversed[p] = arches
|
| |
+ else:
|
| |
+ filter_dict_reversed[p]["arches"].append(a)
|
| |
data["data"]["components"]["rpms"]["filter"] = \
|
| |
- list(self.components.rpms.filter)
|
| |
+ filter_dict_reversed
|
| |
+
|
| |
+
|
| |
return yaml.safe_dump(data)
|
| |
|
| |
def validate(self):
|
| |
Hi, I've updated the filtering feature to accommodate binary filtering, which we plan to later use in Rida (fm-orchestrator). The only file affected is
__init__.py
along with its related tests.