forked from platformsh/templates-external
-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.py
62 lines (58 loc) · 2.31 KB
/
list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import glob
import yaml
outputFile = "{0}/list.yaml".format(os.getcwd())
templates = glob.glob("{0}/templates/*.yaml".format(os.getcwd()))
dopPrefix = "https://console.platform.sh/projects/create-project?template=https://raw.githubusercontent.com/platformsh/templates-external/master"
# Hardcode runtimes for now.
runtimes = {
"Symfony 6.0/PHP 8.1/demo": "php",
"Symfony 5.4/PHP 8.1/webapp": "php",
"Symfony 6.0/PHP 8.0/base": "php",
"Symfony 5.4/PHP 8.0/webapp": "php",
"Restyaboard": "php",
"Symfony 5.4/PHP 8.0/base": "php",
"redirection.io": "golang",
"eZ Platform v2": "php",
"Pizzly": "nodejs",
"OpenideaL": "php",
"eZ Platform v3": "php",
"Varbase (Drupal 9)": "php",
"Symfony 5.4/PHP 8.1/base": "php",
"Symfony 6.0/PHP 8.1/webapp": "php",
"Symfony 6.0/PHP 8.1/base": "php",
"Symfony 6.0/PHP 8.0/webapp": "php",
"Symfony 6.0/PHP 8.0/demo": "php",
}
uniqueRuntimes = list(set(list(runtimes.values())))
data = dict([(key, []) for key in uniqueRuntimes])
for templateDef in templates:
with open(templateDef) as file:
try:
# Get the data.
templateData = yaml.safe_load(file)
# Define the repository.
repoParts = templateData['initialize']['repository'].split(".git@")
if len(repoParts) == 1:
repo = repoParts[0].split(".git")[0]
else:
repo = "{0}/tree/{1}".format(repoParts[0], repoParts[1])
# Define object pulling from template.yamls.
entry = {
"shortname": templateData['info']['id'],
"name": templateData['info']['name'],
"repo": repo,
"description": templateData['info']['description'],
"image": templateData['info']['image'],
"deploy": "{0}/{1}".format(dopPrefix, templateDef.split("/templates-external/")[1]),
"content": templateData['info']['notes'][0]['content'],
"tags": templateData['info']['tags']
}
# Append to the runtime key.
currentRuntime = runtimes[templateData['info']['name']]
data[currentRuntime].append(entry)
except yaml.YAMLError as exc:
print(exc)
# Output.
with open(outputFile, 'w') as file:
yaml.dump(data, file)