Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #340 from groeges/release-0.9-codewind
Browse files Browse the repository at this point in the history
Add support for deprecated stack to codewind index generation
  • Loading branch information
groeges authored May 14, 2020
2 parents b82d65d + 4971516 commit 104bb14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
41 changes: 28 additions & 13 deletions ci/create_codewind_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -32,7 +34,7 @@
template = ""
else:
template = " " + item['templates'][n]['id']

# populate stack details
res = (OrderedDict([
("displayName", displayNamePrefix + " " + item['name'] + template + " template"),
Expand All @@ -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()
2 changes: 1 addition & 1 deletion ci/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 104bb14

Please sign in to comment.