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) native_names = [] aur_names = [] for p in flat_packages: assert isinstance(p, dict) if p['name'].startswith('aur/'): aur_names.append(p['name'].split('/')[1]) continue native_names.append(p['name']) print(json.dumps({ "native": native_names, "aur": aur_names })) # print(' '.join(names))