mirror of
https://github.com/rocky-linux/peridot-releng.git
synced 2024-11-23 07:41:23 +00:00
Switch to black for formatting
This commit is contained in:
parent
9e91db39a1
commit
147aedf354
@ -28,6 +28,7 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import argparse
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
import xml.etree.ElementTree as ET
|
||||
from xml.dom import minidom
|
||||
@ -36,49 +37,47 @@ from group import Group, PackageReq, Environment, EnvGroup
|
||||
|
||||
|
||||
def write_variant(groups, environments, categories, out):
|
||||
root = ET.Element('comps')
|
||||
root = ET.Element("comps")
|
||||
for group in groups:
|
||||
group_elem = ET.SubElement(root, 'group')
|
||||
ET.SubElement(group_elem, 'id').text = group.id
|
||||
group_elem = ET.SubElement(root, "group")
|
||||
ET.SubElement(group_elem, "id").text = group.id
|
||||
for lang in group.name:
|
||||
name = ET.SubElement(group_elem, 'name')
|
||||
name = ET.SubElement(group_elem, "name")
|
||||
if lang != "":
|
||||
name.set('xml:lang', lang)
|
||||
name.set("xml:lang", lang)
|
||||
name.text = group.name[lang]
|
||||
for lang in group.description:
|
||||
description = ET.SubElement(group_elem, 'description')
|
||||
description = ET.SubElement(group_elem, "description")
|
||||
if lang != "":
|
||||
description.set('xml:lang', lang)
|
||||
description.set("xml:lang", lang)
|
||||
description.text = group.description[lang]
|
||||
ET.SubElement(group_elem, 'default').text = str(group.default).lower()
|
||||
ET.SubElement(group_elem, 'uservisible').text = str(
|
||||
group.user_visible).lower()
|
||||
package_list = ET.SubElement(group_elem, 'packagelist')
|
||||
ET.SubElement(group_elem, "default").text = str(group.default).lower()
|
||||
ET.SubElement(group_elem, "uservisible").text = str(group.user_visible).lower()
|
||||
package_list = ET.SubElement(group_elem, "packagelist")
|
||||
for package in group.packages:
|
||||
package_elem = ET.SubElement(package_list, 'packagereq')
|
||||
package_elem.set('type', package.type)
|
||||
package_elem = ET.SubElement(package_list, "packagereq")
|
||||
package_elem.set("type", package.type)
|
||||
package_elem.text = package.name
|
||||
for environment in environments:
|
||||
env_elem = ET.SubElement(root, 'environment')
|
||||
ET.SubElement(env_elem, 'id').text = environment.id
|
||||
env_elem = ET.SubElement(root, "environment")
|
||||
ET.SubElement(env_elem, "id").text = environment.id
|
||||
for lang in environment.name:
|
||||
name = ET.SubElement(env_elem, 'name')
|
||||
name = ET.SubElement(env_elem, "name")
|
||||
if lang != "":
|
||||
name.set('xml:lang', lang)
|
||||
name.set("xml:lang", lang)
|
||||
name.text = environment.name[lang]
|
||||
for lang in environment.description:
|
||||
description = ET.SubElement(env_elem, 'description')
|
||||
description = ET.SubElement(env_elem, "description")
|
||||
if lang != "":
|
||||
description.set('xml:lang', lang)
|
||||
description.set("xml:lang", lang)
|
||||
description.text = environment.description[lang]
|
||||
ET.SubElement(env_elem, 'display_order').text = str(
|
||||
environment.display_order)
|
||||
group_list = ET.SubElement(env_elem, 'grouplist')
|
||||
ET.SubElement(env_elem, "display_order").text = str(environment.display_order)
|
||||
group_list = ET.SubElement(env_elem, "grouplist")
|
||||
for group in environment.group_list:
|
||||
ET.SubElement(group_list, 'groupid').text = group.name
|
||||
option_list = ET.SubElement(env_elem, 'optionlist')
|
||||
ET.SubElement(group_list, "groupid").text = group.name
|
||||
option_list = ET.SubElement(env_elem, "optionlist")
|
||||
for option in environment.option_list:
|
||||
ET.SubElement(option_list, 'optionid').text = option.name
|
||||
ET.SubElement(option_list, "optionid").text = option.name
|
||||
for category_name in categories.keys():
|
||||
category = categories[category_name]
|
||||
new_group_list = []
|
||||
@ -89,37 +88,41 @@ def write_variant(groups, environments, categories, out):
|
||||
break
|
||||
if len(new_group_list) == 0:
|
||||
continue
|
||||
category_elem = ET.SubElement(root, 'category')
|
||||
ET.SubElement(category_elem, 'id').text = category_name
|
||||
category_elem = ET.SubElement(root, "category")
|
||||
ET.SubElement(category_elem, "id").text = category_name
|
||||
for lang in category.name:
|
||||
name = ET.SubElement(category_elem, 'name')
|
||||
name = ET.SubElement(category_elem, "name")
|
||||
if lang != "":
|
||||
name.set('xml:lang', lang)
|
||||
name.set("xml:lang", lang)
|
||||
name.text = category.name[lang]
|
||||
for lang in category.description:
|
||||
description = ET.SubElement(category_elem, 'description')
|
||||
description = ET.SubElement(category_elem, "description")
|
||||
if lang != "":
|
||||
description.set('xml:lang', lang)
|
||||
description.set("xml:lang", lang)
|
||||
description.text = category.description[lang]
|
||||
ET.SubElement(category_elem, 'display_order').text = str(
|
||||
category.display_order)
|
||||
group_list = ET.SubElement(category_elem, 'grouplist')
|
||||
ET.SubElement(category_elem, "display_order").text = str(category.display_order)
|
||||
group_list = ET.SubElement(category_elem, "grouplist")
|
||||
for group in new_group_list:
|
||||
ET.SubElement(group_list, 'groupid').text = group.name
|
||||
ET.ElementTree(root).write(out, encoding='utf-8', xml_declaration=False)
|
||||
ET.SubElement(group_list, "groupid").text = group.name
|
||||
ET.ElementTree(root).write(out, encoding="utf-8", xml_declaration=False)
|
||||
|
||||
with open(out, 'r') as f:
|
||||
with open(out, "r") as f:
|
||||
data = f.read()
|
||||
with open(out, 'w') as f:
|
||||
f.writelines("""<?xml version="1.0" encoding="UTF-8"?>
|
||||
with open(out, "w") as f:
|
||||
f.writelines(
|
||||
"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE comps
|
||||
PUBLIC '-//Red Hat, Inc.//DTD Comps info//EN'
|
||||
'comps.dtd'>
|
||||
""" + minidom.parseString(data).toprettyxml(indent=" ").replace('<?xml version="1.0" ?>\n', ''))
|
||||
"""
|
||||
+ minidom.parseString(data)
|
||||
.toprettyxml(indent=" ")
|
||||
.replace('<?xml version="1.0" ?>\n', "")
|
||||
)
|
||||
|
||||
|
||||
def main(comps_path: str, variants_path: str, output_path: str):
|
||||
default_arches = ['x86_64', 'aarch64', 'ppc64le', 's390x']
|
||||
default_arches = ["x86_64", "aarch64", "ppc64le", "s390x"]
|
||||
variants = {}
|
||||
environments = {}
|
||||
categories = {}
|
||||
@ -127,53 +130,55 @@ def main(comps_path: str, variants_path: str, output_path: str):
|
||||
tree = ET.parse(comps_path)
|
||||
root = tree.getroot()
|
||||
for gchild in root:
|
||||
if gchild.tag == 'group':
|
||||
if gchild.tag == "group":
|
||||
group_name = {}
|
||||
group_desc = {}
|
||||
group_id = ''
|
||||
group_id = ""
|
||||
is_default = False
|
||||
is_visible = False
|
||||
variant = ''
|
||||
variant = ""
|
||||
package_list_xml = None
|
||||
if 'variant' in gchild.attrib:
|
||||
variant = gchild.attrib['variant']
|
||||
if 'arch' in gchild.attrib:
|
||||
arches = gchild.attrib['arch'].split(',')
|
||||
if "variant" in gchild.attrib:
|
||||
variant = gchild.attrib["variant"]
|
||||
if "arch" in gchild.attrib:
|
||||
arches = gchild.attrib["arch"].split(",")
|
||||
else:
|
||||
arches = default_arches
|
||||
for gattr in gchild:
|
||||
if gattr.tag == 'id':
|
||||
if gattr.tag == "id":
|
||||
group_id = gattr.text
|
||||
elif gattr.tag == 'name':
|
||||
if '{http://www.w3.org/XML/1998/namespace}lang' in gattr.attrib:
|
||||
group_name[gattr.attrib[
|
||||
'{http://www.w3.org/XML/1998/namespace}lang']] = gattr.text
|
||||
elif gattr.tag == "name":
|
||||
if "{http://www.w3.org/XML/1998/namespace}lang" in gattr.attrib:
|
||||
group_name[
|
||||
gattr.attrib["{http://www.w3.org/XML/1998/namespace}lang"]
|
||||
] = gattr.text
|
||||
else:
|
||||
group_name[""] = gattr.text
|
||||
elif gattr.tag == 'description':
|
||||
if '{http://www.w3.org/XML/1998/namespace}lang' in gattr.attrib:
|
||||
group_desc[gattr.attrib[
|
||||
'{http://www.w3.org/XML/1998/namespace}lang']] = gattr.text
|
||||
elif gattr.tag == "description":
|
||||
if "{http://www.w3.org/XML/1998/namespace}lang" in gattr.attrib:
|
||||
group_desc[
|
||||
gattr.attrib["{http://www.w3.org/XML/1998/namespace}lang"]
|
||||
] = gattr.text
|
||||
else:
|
||||
group_desc[""] = gattr.text
|
||||
elif gattr.tag == 'default':
|
||||
is_default = gattr.text == 'true'
|
||||
elif gattr.tag == 'uservisible':
|
||||
is_visible = gattr.text == 'true'
|
||||
elif gattr.tag == 'packagelist':
|
||||
elif gattr.tag == "default":
|
||||
is_default = gattr.text == "true"
|
||||
elif gattr.tag == "uservisible":
|
||||
is_visible = gattr.text == "true"
|
||||
elif gattr.tag == "packagelist":
|
||||
package_list_xml = gattr
|
||||
package_list = {}
|
||||
if variant != '':
|
||||
if variant != "":
|
||||
package_list[variant] = {}
|
||||
for reqxml in package_list_xml:
|
||||
req_variant = variant
|
||||
req_type = 'default'
|
||||
if 'variant' in reqxml.attrib:
|
||||
req_variant = reqxml.attrib['variant']
|
||||
if 'type' in reqxml.attrib:
|
||||
req_type = reqxml.attrib['type']
|
||||
if 'arch' in reqxml.attrib:
|
||||
req_arches = reqxml.attrib['arch'].split(',')
|
||||
req_type = "default"
|
||||
if "variant" in reqxml.attrib:
|
||||
req_variant = reqxml.attrib["variant"]
|
||||
if "type" in reqxml.attrib:
|
||||
req_type = reqxml.attrib["type"]
|
||||
if "arch" in reqxml.attrib:
|
||||
req_arches = reqxml.attrib["arch"].split(",")
|
||||
else:
|
||||
req_arches = arches
|
||||
if req_variant not in package_list:
|
||||
@ -182,7 +187,8 @@ def main(comps_path: str, variants_path: str, output_path: str):
|
||||
if arch not in package_list[req_variant]:
|
||||
package_list[req_variant][arch] = []
|
||||
package_list[req_variant][arch].append(
|
||||
PackageReq(reqxml.text, req_type, req_arches))
|
||||
PackageReq(reqxml.text, req_type, req_arches)
|
||||
)
|
||||
for variant in package_list:
|
||||
if variant not in variants:
|
||||
variants[variant] = {}
|
||||
@ -191,59 +197,62 @@ def main(comps_path: str, variants_path: str, output_path: str):
|
||||
package_list[variant][arch] = []
|
||||
if group_id not in variants[variant]:
|
||||
variants[variant][group_id] = {}
|
||||
variants[variant][group_id][arch] = Group(group_id,
|
||||
group_name,
|
||||
group_desc,
|
||||
is_default,
|
||||
is_visible,
|
||||
package_list[
|
||||
variant][
|
||||
arch])
|
||||
elif gchild.tag == 'environment' or gchild.tag == 'category':
|
||||
variants[variant][group_id][arch] = Group(
|
||||
group_id,
|
||||
group_name,
|
||||
group_desc,
|
||||
is_default,
|
||||
is_visible,
|
||||
package_list[variant][arch],
|
||||
)
|
||||
elif gchild.tag == "environment" or gchild.tag == "category":
|
||||
env_name = {}
|
||||
env_desc = {}
|
||||
env_id = ''
|
||||
env_id = ""
|
||||
display_order = 0
|
||||
group_list = []
|
||||
option_list = []
|
||||
for gattr in gchild:
|
||||
if gattr.tag == 'id':
|
||||
if gattr.tag == "id":
|
||||
env_id = gattr.text
|
||||
elif gattr.tag == 'name':
|
||||
if '{http://www.w3.org/XML/1998/namespace}lang' in gattr.attrib:
|
||||
env_name[gattr.attrib[
|
||||
'{http://www.w3.org/XML/1998/namespace}lang']] = gattr.text
|
||||
elif gattr.tag == "name":
|
||||
if "{http://www.w3.org/XML/1998/namespace}lang" in gattr.attrib:
|
||||
env_name[
|
||||
gattr.attrib["{http://www.w3.org/XML/1998/namespace}lang"]
|
||||
] = gattr.text
|
||||
else:
|
||||
env_name[""] = gattr.text
|
||||
elif gattr.tag == 'description':
|
||||
if '{http://www.w3.org/XML/1998/namespace}lang' in gattr.attrib:
|
||||
env_desc[gattr.attrib[
|
||||
'{http://www.w3.org/XML/1998/namespace}lang']] = gattr.text
|
||||
elif gattr.tag == "description":
|
||||
if "{http://www.w3.org/XML/1998/namespace}lang" in gattr.attrib:
|
||||
env_desc[
|
||||
gattr.attrib["{http://www.w3.org/XML/1998/namespace}lang"]
|
||||
] = gattr.text
|
||||
else:
|
||||
env_desc[""] = gattr.text
|
||||
elif gattr.tag == 'display_order':
|
||||
elif gattr.tag == "display_order":
|
||||
display_order = gattr.text
|
||||
elif gattr.tag == 'grouplist':
|
||||
elif gattr.tag == "grouplist":
|
||||
for group in gattr:
|
||||
if 'arch' in group.attrib:
|
||||
arches = group.attrib['arch'].split(',')
|
||||
if "arch" in group.attrib:
|
||||
arches = group.attrib["arch"].split(",")
|
||||
else:
|
||||
arches = default_arches
|
||||
group_list.append(EnvGroup(group.text, arches))
|
||||
elif gattr.tag == 'optionlist':
|
||||
elif gattr.tag == "optionlist":
|
||||
for group in gattr:
|
||||
if 'arch' in group.attrib:
|
||||
arches = group.attrib['arch'].split(',')
|
||||
if "arch" in group.attrib:
|
||||
arches = group.attrib["arch"].split(",")
|
||||
else:
|
||||
arches = default_arches
|
||||
option_list.append(EnvGroup(group.text, arches))
|
||||
new_env = Environment(env_id, env_name, env_desc, display_order,
|
||||
group_list, option_list)
|
||||
new_env = Environment(
|
||||
env_id, env_name, env_desc, display_order, group_list, option_list
|
||||
)
|
||||
dictmap = categories
|
||||
if gchild.tag == 'environment':
|
||||
if gchild.tag == "environment":
|
||||
dictmap = environments
|
||||
if 'arch' in gchild.attrib:
|
||||
arches = gchild.attrib['arch'].split(',')
|
||||
if "arch" in gchild.attrib:
|
||||
arches = gchild.attrib["arch"].split(",")
|
||||
else:
|
||||
arches = default_arches
|
||||
for arch in arches:
|
||||
@ -262,18 +271,18 @@ def main(comps_path: str, variants_path: str, output_path: str):
|
||||
environment_arch_index = {}
|
||||
pungi_variants_tree = ET.parse(variants_path).getroot()
|
||||
for pungi_variant in pungi_variants_tree:
|
||||
if pungi_variant.tag == 'variant':
|
||||
if pungi_variant.attrib['type'] != 'variant':
|
||||
if pungi_variant.tag == "variant":
|
||||
if pungi_variant.attrib["type"] != "variant":
|
||||
continue
|
||||
arches = []
|
||||
groups = {}
|
||||
n_environments = {}
|
||||
variant_id = pungi_variant.attrib['id']
|
||||
variant_id = pungi_variant.attrib["id"]
|
||||
for child in pungi_variant:
|
||||
if child.tag == 'arches':
|
||||
if child.tag == "arches":
|
||||
for arch in child:
|
||||
arches.append(arch.text)
|
||||
elif child.tag == 'groups':
|
||||
elif child.tag == "groups":
|
||||
for group in child:
|
||||
groupbase = variants[""]
|
||||
if variant_id in variants:
|
||||
@ -284,17 +293,20 @@ def main(comps_path: str, variants_path: str, output_path: str):
|
||||
for arch_group in groupind.keys():
|
||||
if arch_group not in groups:
|
||||
groups[arch_group] = []
|
||||
if 'default' in group.attrib:
|
||||
groupind[arch_group].default = group.attrib['default'] == 'true'
|
||||
if "default" in group.attrib:
|
||||
groupind[arch_group].default = (
|
||||
group.attrib["default"] == "true"
|
||||
)
|
||||
groups[arch_group].append(groupind[arch_group])
|
||||
elif child.tag == 'environments':
|
||||
elif child.tag == "environments":
|
||||
for environment in child:
|
||||
envind = environment_id_index[environment.text]
|
||||
for arch_environment in envind.keys():
|
||||
if arch_environment not in n_environments:
|
||||
n_environments[arch_environment] = []
|
||||
n_environments[arch_environment].append(
|
||||
envind[arch_environment])
|
||||
envind[arch_environment]
|
||||
)
|
||||
for arch in arches:
|
||||
if arch in groups:
|
||||
if arch not in variant_arch_index:
|
||||
@ -308,25 +320,29 @@ def main(comps_path: str, variants_path: str, output_path: str):
|
||||
if variant_id not in environment_arch_index[arch]:
|
||||
environment_arch_index[arch][variant_id] = []
|
||||
environment_arch_index[arch][variant_id].extend(
|
||||
n_environments[arch])
|
||||
n_environments[arch]
|
||||
)
|
||||
|
||||
for arch in variant_arch_index.keys():
|
||||
for variant in variant_arch_index[arch].keys():
|
||||
write_variant(variant_arch_index[arch][variant] if variant in
|
||||
variant_arch_index[
|
||||
arch] else [],
|
||||
environment_arch_index[arch][variant] if variant in
|
||||
environment_arch_index[
|
||||
arch] else [],
|
||||
write_variant(
|
||||
variant_arch_index[arch][variant]
|
||||
if variant in variant_arch_index[arch]
|
||||
else [],
|
||||
environment_arch_index[arch][variant]
|
||||
if variant in environment_arch_index[arch]
|
||||
else [],
|
||||
categories[arch].copy(),
|
||||
f'{output_path}/{variant}-{arch}.xml')
|
||||
f"{output_path}/{variant}-{arch}.xml",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Convert comps to Peridot compatible configuration.')
|
||||
parser.add_argument('--comps-path', type=str, required=True)
|
||||
parser.add_argument('--variants-path', type=str, required=True)
|
||||
parser.add_argument('--output-path', type=str, default=".")
|
||||
description="Convert comps to Peridot compatible configuration."
|
||||
)
|
||||
parser.add_argument("--comps-path", type=str, required=True)
|
||||
parser.add_argument("--variants-path", type=str, required=True)
|
||||
parser.add_argument("--output-path", type=str, default=".")
|
||||
args = parser.parse_args()
|
||||
main(args.comps_path, args.variants_path, args.output_path)
|
||||
|
@ -38,8 +38,12 @@ class PeridotCatalogSyncPackageType(str, Enum):
|
||||
PACKAGE_TYPE_MODULE_FORK = "PACKAGE_TYPE_MODULE_FORK"
|
||||
PACKAGE_TYPE_MODULE_FORK_COMPONENT = "PACKAGE_TYPE_MODULE_FORK_COMPONENT"
|
||||
PACKAGE_TYPE_NORMAL_FORK_MODULE = "PACKAGE_TYPE_NORMAL_FORK_MODULE"
|
||||
PACKAGE_TYPE_NORMAL_FORK_MODULE_COMPONENT = "PACKAGE_TYPE_NORMAL_FORK_MODULE_COMPONENT"
|
||||
PACKAGE_TYPE_MODULE_FORK_MODULE_COMPONENT = "PACKAGE_TYPE_MODULE_FORK_MODULE_COMPONENT"
|
||||
PACKAGE_TYPE_NORMAL_FORK_MODULE_COMPONENT = (
|
||||
"PACKAGE_TYPE_NORMAL_FORK_MODULE_COMPONENT"
|
||||
)
|
||||
PACKAGE_TYPE_MODULE_FORK_MODULE_COMPONENT = (
|
||||
"PACKAGE_TYPE_MODULE_FORK_MODULE_COMPONENT"
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -49,12 +53,12 @@ class PeridotCatalogSyncRepository:
|
||||
multilib: list[str]
|
||||
|
||||
def include_filter_to_prototxt(self):
|
||||
return '\n' + '\n'.join(
|
||||
[f" include_filter: \"{f}\"" for f in self.include_filter])
|
||||
return "\n" + "\n".join(
|
||||
[f' include_filter: "{f}"' for f in self.include_filter]
|
||||
)
|
||||
|
||||
def multilib_to_prototxt(self):
|
||||
return '\n' + '\n'.join(
|
||||
[f" multilib: \"{f}\"" for f in self.multilib])
|
||||
return "\n" + "\n".join([f' multilib: "{f}"' for f in self.multilib])
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -65,19 +69,26 @@ class PeridotCatalogSyncPackage:
|
||||
repositories: list[PeridotCatalogSyncRepository]
|
||||
|
||||
def mc_to_prototxt(self):
|
||||
return '\n' + '\n'.join(
|
||||
[f" module_component: \"{component}\"" for component in
|
||||
self.module_components])
|
||||
return "\n" + "\n".join(
|
||||
[
|
||||
f' module_component: "{component}"'
|
||||
for component in self.module_components
|
||||
]
|
||||
)
|
||||
|
||||
def repos_to_prototxt(self):
|
||||
return '\n'.join(
|
||||
[f""" repository {{
|
||||
return "\n".join(
|
||||
[
|
||||
f""" repository {{
|
||||
name: \"{repo.name}\"{
|
||||
repo.include_filter_to_prototxt() if repo.include_filter else ""
|
||||
}{
|
||||
repo.multilib_to_prototxt() if repo.multilib else ""
|
||||
}
|
||||
}}""" for repo in self.repositories])
|
||||
}}"""
|
||||
for repo in self.repositories
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class PeridotCatalogSync:
|
||||
@ -91,42 +102,53 @@ class PeridotCatalogSync:
|
||||
self.packages.append(package)
|
||||
|
||||
def additional_multilib_to_prototxt(self):
|
||||
return '\n'.join(
|
||||
[f"additional_multilib: \"{f}\"" for f in
|
||||
self.additional_multilib])
|
||||
return "\n".join(
|
||||
[f'additional_multilib: "{f}"' for f in self.additional_multilib]
|
||||
)
|
||||
|
||||
def exclude_multilib_filter_to_prototxt(self):
|
||||
return '\n' + '\n'.join(
|
||||
[f"exclude_multilib_filter: \"{f}\"" for f in
|
||||
self.exclude_multilib_filter])
|
||||
return "\n" + "\n".join(
|
||||
[f'exclude_multilib_filter: "{f}"' for f in self.exclude_multilib_filter]
|
||||
)
|
||||
|
||||
def filter_arch_to_prototxt(self, arch: dict):
|
||||
nl = '\n'
|
||||
nl = "\n"
|
||||
glob_match = {}
|
||||
for k, v in arch.items():
|
||||
glob_match[k] = [f" glob_match: \"{f}\"" for f in v]
|
||||
glob_match[k] = [f' glob_match: "{f}"' for f in v]
|
||||
for k in glob_match.keys():
|
||||
if len(glob_match[k]) > 0:
|
||||
glob_match[k][0] = '\n' + glob_match[k][0]
|
||||
return '\n'.join([f""" arch {{
|
||||
glob_match[k][0] = "\n" + glob_match[k][0]
|
||||
return "\n".join(
|
||||
[
|
||||
f""" arch {{
|
||||
key: \"{f}\"{nl.join(glob_match[f])}
|
||||
}}""" for f in arch.keys()])
|
||||
}}"""
|
||||
for f in arch.keys()
|
||||
]
|
||||
)
|
||||
|
||||
def exclude_filter_to_prototxt(self):
|
||||
return '\n' + '\n'.join(
|
||||
[f"""exclude_filter {{
|
||||
return "\n" + "\n".join(
|
||||
[
|
||||
f"""exclude_filter {{
|
||||
repo_match: \"{f[0]}\"
|
||||
{self.filter_arch_to_prototxt(f[1])}
|
||||
}}""" for f in
|
||||
self.exclude_filter])
|
||||
}}"""
|
||||
for f in self.exclude_filter
|
||||
]
|
||||
)
|
||||
|
||||
def include_filter_to_prototxt(self):
|
||||
return '\n' + '\n'.join(
|
||||
[f"""include_filter {{
|
||||
return "\n" + "\n".join(
|
||||
[
|
||||
f"""include_filter {{
|
||||
repo_match: \"{f[0]}\"
|
||||
{self.filter_arch_to_prototxt(f[1])}
|
||||
}}""" for f in
|
||||
self.include_filter])
|
||||
}}"""
|
||||
for f in self.include_filter
|
||||
]
|
||||
)
|
||||
|
||||
def to_prototxt(self):
|
||||
ret = f"""# kind: resf.peridot.v1.CatalogSync
|
||||
|
@ -32,8 +32,12 @@ import os
|
||||
|
||||
import kobo.conf
|
||||
|
||||
from catalog import PeridotCatalogSync, PeridotCatalogSyncPackage, \
|
||||
PeridotCatalogSyncPackageType, PeridotCatalogSyncRepository
|
||||
from catalog import (
|
||||
PeridotCatalogSync,
|
||||
PeridotCatalogSyncPackage,
|
||||
PeridotCatalogSyncPackageType,
|
||||
PeridotCatalogSyncRepository,
|
||||
)
|
||||
from scm import SCM
|
||||
|
||||
|
||||
@ -51,10 +55,10 @@ def main(pungi_conf_path: str, output_path: str):
|
||||
catalog = PeridotCatalogSync()
|
||||
|
||||
# Set multilib filters
|
||||
catalog.additional_multilib.extend(
|
||||
list(conf.get("multilib_whitelist").values())[0])
|
||||
catalog.additional_multilib.extend(list(conf.get("multilib_whitelist").values())[0])
|
||||
catalog.exclude_multilib_filter.extend(
|
||||
list(conf.get("multilib_blacklist").values())[0])
|
||||
list(conf.get("multilib_blacklist").values())[0]
|
||||
)
|
||||
|
||||
# Set additional packages/filters
|
||||
catalog.exclude_filter.extend(conf.get("filter_packages"))
|
||||
@ -73,31 +77,40 @@ def main(pungi_conf_path: str, output_path: str):
|
||||
if package not in package_index:
|
||||
package_index[package] = {}
|
||||
if repo not in package_index[package]:
|
||||
package_index[package][repo] = {"include_filter": [],
|
||||
"multilib": []}
|
||||
package_index[package][repo] = {
|
||||
"include_filter": [],
|
||||
"multilib": [],
|
||||
}
|
||||
na_list = gpjson[repo][arch][package]
|
||||
for na in na_list:
|
||||
splitted = na.split(".")
|
||||
arch_package = splitted[len(splitted) - 1]
|
||||
if arch != arch_package and arch_package != "noarch":
|
||||
if arch not in package_index[package][repo]["multilib"]:
|
||||
package_index[package][repo]["multilib"].append(
|
||||
arch)
|
||||
package_index[package][repo]["multilib"].append(arch)
|
||||
if na not in package_index[package][repo]["include_filter"]:
|
||||
package_index[package][repo]["include_filter"].append(
|
||||
na)
|
||||
package_index[package][repo]["include_filter"].append(na)
|
||||
|
||||
arch_specific_excludes = {}
|
||||
na_index = {}
|
||||
for pkg in package_index.keys():
|
||||
for repo in package_index[pkg].keys():
|
||||
na_list = list(filter(lambda x: x.endswith('.noarch'), package_index[pkg][repo]["include_filter"]))
|
||||
na_list = list(
|
||||
filter(
|
||||
lambda x: x.endswith(".noarch"),
|
||||
package_index[pkg][repo]["include_filter"],
|
||||
)
|
||||
)
|
||||
if not na_list:
|
||||
continue
|
||||
exclude_arches = {}
|
||||
for na in na_list:
|
||||
for arch in all_arches:
|
||||
if arch not in gpjson[repo] or pkg not in gpjson[repo][arch] or na not in gpjson[repo][arch][pkg]:
|
||||
if (
|
||||
arch not in gpjson[repo]
|
||||
or pkg not in gpjson[repo][arch]
|
||||
or na not in gpjson[repo][arch][pkg]
|
||||
):
|
||||
if na not in exclude_arches:
|
||||
exclude_arches[na] = []
|
||||
exclude_arches[na].append(arch)
|
||||
@ -132,7 +145,7 @@ def main(pungi_conf_path: str, output_path: str):
|
||||
if arch not in filter_tuple:
|
||||
filter_tuple[arch] = []
|
||||
for na in repo_arch_index[repo][arch]:
|
||||
na = na.removesuffix('.noarch')
|
||||
na = na.removesuffix(".noarch")
|
||||
if na not in filter_tuple[arch]:
|
||||
filter_tuple[arch].append(na)
|
||||
catalog.exclude_filter.append((repo_key, filter_tuple))
|
||||
@ -141,12 +154,18 @@ def main(pungi_conf_path: str, output_path: str):
|
||||
catalog.add_package(
|
||||
PeridotCatalogSyncPackage(
|
||||
package,
|
||||
PeridotCatalogSyncPackageType.PACKAGE_TYPE_NORMAL_FORK if not package.startswith("rocky-") else PeridotCatalogSyncPackageType.PACKAGE_TYPE_NORMAL_SRC,
|
||||
PeridotCatalogSyncPackageType.PACKAGE_TYPE_NORMAL_FORK
|
||||
if not package.startswith("rocky-")
|
||||
else PeridotCatalogSyncPackageType.PACKAGE_TYPE_NORMAL_SRC,
|
||||
[],
|
||||
[PeridotCatalogSyncRepository(x, package_index[package][x][
|
||||
"include_filter"], package_index[package][x]["multilib"])
|
||||
for
|
||||
x in package_index[package].keys()]
|
||||
[
|
||||
PeridotCatalogSyncRepository(
|
||||
x,
|
||||
package_index[package][x]["include_filter"],
|
||||
package_index[package][x]["multilib"],
|
||||
)
|
||||
for x in package_index[package].keys()
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
@ -159,9 +178,9 @@ def main(pungi_conf_path: str, output_path: str):
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Convert Pungi configuration to Peridot compatible '
|
||||
'catalogs.')
|
||||
parser.add_argument('--pungi-conf-path', type=str, required=True)
|
||||
parser.add_argument('--output-path', type=str, default="catalog.cfg")
|
||||
description="Convert Pungi configuration to Peridot compatible " "catalogs."
|
||||
)
|
||||
parser.add_argument("--pungi-conf-path", type=str, required=True)
|
||||
parser.add_argument("--output-path", type=str, default="catalog.cfg")
|
||||
args = parser.parse_args()
|
||||
main(args.pungi_conf_path, args.output_path)
|
||||
|
@ -27,16 +27,16 @@
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
BASE_URL = 'https://peridot-api.build.resf.org/v1'
|
||||
PROJECT_ID_PROD = '55b17281-bc54-4929-8aca-a8a11d628738'
|
||||
BASE_URL = "https://peridot-api.build.resf.org/v1"
|
||||
PROJECT_ID_PROD = "55b17281-bc54-4929-8aca-a8a11d628738"
|
||||
|
||||
|
||||
def construct_url(path, project_id=PROJECT_ID_PROD):
|
||||
return f'{BASE_URL}/projects/{project_id}{path}'
|
||||
return f"{BASE_URL}/projects/{project_id}{path}"
|
||||
|
||||
|
||||
def build_batches_url(batch_type, task_id, page, status,
|
||||
project_id=PROJECT_ID_PROD):
|
||||
def build_batches_url(batch_type, task_id, page, status, project_id=PROJECT_ID_PROD):
|
||||
return construct_url(
|
||||
f'/{batch_type}_batches/{task_id}?page={page}&limit=100&filter.status={status}',
|
||||
project_id)
|
||||
f"/{batch_type}_batches/{task_id}?page={page}&limit=100&filter.status={status}",
|
||||
project_id,
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ from common import build_batches_url
|
||||
|
||||
def get_batch(batch_type, task_id, status, page):
|
||||
r = requests.get(build_batches_url(batch_type, task_id, page, status))
|
||||
return r.json()[f'{batch_type}s']
|
||||
return r.json()[f"{batch_type}s"]
|
||||
|
||||
|
||||
def process_batch(batch_type, task_id, status):
|
||||
@ -52,18 +52,16 @@ def process_batch(batch_type, task_id, status):
|
||||
page = page + 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
batch_type = sys.argv[1]
|
||||
task_id = sys.argv[2]
|
||||
|
||||
batch_items = process_batch(batch_type, task_id, 4)
|
||||
|
||||
req = {}
|
||||
key = f'{batch_type}s'
|
||||
key = f"{batch_type}s"
|
||||
req[key] = []
|
||||
for item in batch_items:
|
||||
req[key].append({
|
||||
'package_name': item['name']
|
||||
})
|
||||
req[key].append({"package_name": item["name"]})
|
||||
|
||||
print(json.dumps(req))
|
||||
|
@ -38,13 +38,14 @@ from common import construct_url
|
||||
|
||||
def chunks(lst, n):
|
||||
for i in range(0, len(lst), n):
|
||||
yield lst[i:i + n]
|
||||
yield lst[i : i + n]
|
||||
|
||||
|
||||
def get_packages(page):
|
||||
r = requests.get(
|
||||
construct_url(f'/packages?limit=100&page={page}&filters.no_builds=1'))
|
||||
return r.json()['packages']
|
||||
construct_url(f"/packages?limit=100&page={page}&filters.no_builds=1")
|
||||
)
|
||||
return r.json()["packages"]
|
||||
|
||||
|
||||
def process_packages():
|
||||
@ -58,13 +59,11 @@ def process_packages():
|
||||
page = page + 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
batch_items = process_packages()
|
||||
|
||||
builds = []
|
||||
for item in batch_items:
|
||||
builds.append({
|
||||
'package_name': item['name']
|
||||
})
|
||||
builds.append({"package_name": item["name"]})
|
||||
for chunk in chunks(builds, 400):
|
||||
print(json.dumps({"builds": chunk}))
|
||||
|
@ -30,15 +30,13 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
build_type = sys.argv[1]
|
||||
key = f'{build_type}s'
|
||||
key = f"{build_type}s"
|
||||
|
||||
req = {}
|
||||
req[key] = []
|
||||
for line in sys.stdin:
|
||||
req[key].append({
|
||||
'package_name': line.strip()
|
||||
})
|
||||
req[key].append({"package_name": line.strip()})
|
||||
|
||||
print(json.dumps(req))
|
||||
|
Loading…
Reference in New Issue
Block a user