From 4971516c5df9908ff12934a34d5c81ae156f3974 Mon Sep 17 00:00:00 2001 From: Steven Groeger Date: Mon, 4 May 2020 14:08:20 +0100 Subject: [PATCH] Add support for deprecated stack to codewind index generation Signed-off-by: Steven Groeger --- ci/create_codewind_index.py | 41 +++++++++++++++++++++++++------------ ci/package.sh | 2 +- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/ci/create_codewind_index.py b/ci/create_codewind_index.py index a36ce03fa..1c2ed251c 100755 --- a/ci/create_codewind_index.py +++ b/ci/create_codewind_index.py @@ -4,21 +4,23 @@ import json import os import fnmatch -import sys from collections import OrderedDict +import argparse +from argparse import ArgumentDefaultsHelpFormatter -base_dir = os.path.abspath(os.path.dirname(sys.argv[0])) +parser = argparse.ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) -displayNamePrefix = "Appsody" -if len(sys.argv) > 1: - displayNamePrefix = sys.argv[1] +parser.add_argument("-n", "--namePrefix", help="Display name prefix.", default="Appsody") +parser.add_argument("-f", "--file", help="Absolute or relative path, to a yaml file or directory of yaml files.", default=os.getcwd()) -# directory to store assets for test or release -assets_dir = base_dir + "/assets/" +args = parser.parse_args() -for file in os.listdir(assets_dir): - if fnmatch.fnmatch(file, '*index.yaml'): - with open(assets_dir + file, 'r') as yamlFile, open(assets_dir + os.path.splitext(file)[0] + ".json", 'wb') as jsonFile: +displayNamePrefix = args.namePrefix + +yaml_dir = os.path.normpath(args.file) + +def generate_json(): + with open(inputFile, 'r') as yamlFile, open(inputFile.rsplit('.', 1)[0] + ".json", 'wb') as jsonFile: try: doc = yaml.safe_load(yamlFile) list = [] @@ -32,7 +34,7 @@ template = "" else: template = " " + item['templates'][n]['id'] - + # populate stack details res = (OrderedDict([ ("displayName", displayNamePrefix + " " + item['name'] + template + " template"), @@ -46,10 +48,23 @@ item['id'] + "/devfile.yaml") ])) ])) + + if ('deprecated' in item): + res.update([("displayName", "[Deprecated] " + displayNamePrefix + " " + item['name'] + template + " template"), + ("deprecated", item['deprecated'])]) + list.append(res) jsonFile.write(json.dumps(list, indent=4, ensure_ascii=False).encode('utf8')) - print("Generated: " + os.path.splitext(file)[0] + ".json") - + print("Generated: " + inputFile.rsplit('.', 1)[0] + ".json") except yaml.YAMLError as exc: print(exc) + +if os.path.isdir(yaml_dir): + for file in os.listdir(yaml_dir): + if fnmatch.fnmatch(file, '*.yaml'): + inputFile = yaml_dir + "/" + file + generate_json() +else: + inputFile = yaml_dir + generate_json() \ No newline at end of file diff --git a/ci/package.sh b/ci/package.sh index 5a27c9454..0d70f6edd 100755 --- a/ci/package.sh +++ b/ci/package.sh @@ -202,7 +202,7 @@ done exec_hooks $script_dir/ext/post_package.d if [ "$CODEWIND_INDEX" == "true" ]; then - python3 $script_dir/create_codewind_index.py $DISPLAY_NAME_PREFIX + python3 $script_dir/create_codewind_index.py -n $DISPLAY_NAME_PREFIX -f $assets_dir # iterate over each repo for codewind_file in $assets_dir/*.json