From 76594141959dd88976c60c6d9429e28236bcf98f Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Thu, 11 Aug 2022 15:11:47 -0400 Subject: [PATCH] Use index.yaml to generate directory index in list_priorities. (#234) * Use index.yaml to generate directory index in list_priorities. As suggested by Steven!, we should parse the index.yaml to find the list of distributions to parse, rather than having a hard-coded list. Signed-off-by: Chris Lalancette Co-authored-by: Scott K Logan --- list_priorities.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/list_priorities.py b/list_priorities.py index 637322ee..029544b0 100755 --- a/list_priorities.py +++ b/list_priorities.py @@ -7,13 +7,23 @@ import yamlinclude -DIRECTORIES = ['foxy', 'galactic', 'humble', 'rolling'] - def main(): base_path = os.path.dirname(__file__) + + # First parse the index.yaml to find the list of distributions that we + # should parse. + + yamlinclude.YamlIncludeConstructor.add_to_loader_class(loader_class=yaml.FullLoader, base_dir=base_path) + with open(os.path.join(base_path, 'index.yaml')) as infp: + index_data = yaml.load(infp, Loader=yaml.FullLoader) + + directories = list(index_data['distributions'].keys()) + + del yaml.FullLoader.yaml_constructors[yamlinclude.YamlIncludeConstructor.DEFAULT_TAG_NAME] + priorities = {} - for directory in DIRECTORIES: + for directory in directories: current_path = os.path.join(base_path, directory) yamlinclude.YamlIncludeConstructor.add_to_loader_class(loader_class=yaml.FullLoader, base_dir=current_path)