monakhos/ansible/parse_arch_packages.py
2024-05-22 17:35:11 +02:00

35 lines
889 B
Python

import json
import yaml
packages_tree = None
with open("arch_packages.yaml", 'r') as config_f:
packages_tree = yaml.safe_load(config_f)
assert packages_tree is not None, "Must have load valid package tree"
def flatten_packages(item):
packages = []
if isinstance(item, str):
return {'name': item}
if isinstance(item, dict) and 'name' in item:
return item
if isinstance(item, list):
return [flatten_packages(p) for p in item]
if isinstance(item, dict):
packages = []
for k, v in item.items():
packages += flatten_packages(v)
return packages
return []
flat_packages = flatten_packages(packages_tree)
names = []
for p in flat_packages:
assert isinstance(p, dict)
if p['name'].startswith('aur/'):
continue
names.append(p['name'])
print(json.dumps(names))
# print(' '.join(names))