-
Notifications
You must be signed in to change notification settings - Fork 101
/
configure
executable file
·101 lines (83 loc) · 3.48 KB
/
configure
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
#Import necessary functions from Jinja2 module
from jinja2 import Environment, FileSystemLoader
import pathlib
import sys
#Import YAML module
import yaml
#Load lang parameters
config_data = yaml.load(open('./parameters.yml'), Loader=yaml.FullLoader)
print("Config file loaded successfully")
avaiable_products = config_data["products"].keys()
if len(sys.argv) != 2:
print("ERROR: ./configure requires one parameter [product]")
print("Based on parameters.yaml, valid value for product are: ")
for key in avaiable_products :
print("- " + key)
sys.exit(1)
param_product = sys.argv[1]
if param_product not in avaiable_products:
print(f"ERROR: {param_product} is not defined in parameters.yaml. site.yml and entities.adoc cannot be created.")
sys.exit(1)
products = config_data["products"]
product = products[param_product]
# enrich product with common param
common_dict= {}
common_dict["languages"] = config_data["languages"]
product.update(common_dict)
#Load Jinja2 template
env = Environment(loader = FileSystemLoader('./'), trim_blocks=True, lstrip_blocks=True)
template_lang = env.get_template('Makefile.j2')
print("Creating Makefile for each language..")
#Create makefile for each language from template
for i in config_data["languages"]:
with open('Makefile.' + i["langcode"], 'w') as f:
print(template_lang.render(i), file=f)
f.close()
print("Makefiles successfully created")
print("Including new Makefiles in Makefile.lang")
#include the new makefile in the main one
with open('Makefile.lang', 'a') as f:
f.truncate(0)
for i in config_data["languages"]:
f.write('-include ' + 'Makefile.' + i["langcode"] + '\n')
f.close()
#Create books target
print("Creating new target using books target..")
template_target = env.get_template('Makefile.section.functions.j2')
with open('Makefile.section.functions', 'w') as f:
print(template_target.render(product), file=f)
f.close()
#Create common target
template_target = env.get_template('Makefile.lang.target.j2')
print("Creating new target using language target..")
with open('Makefile.lang.target', 'w') as f:
print(template_target.render(config_data), file=f)
f.close()
#Create site.yml and entities.adoc
print("Creating entities.adoc")
print("Creating parameters specific for " + param_product + " for entities file..")
pathlib.Path("branding/locale/").mkdir(parents=True, exist_ok=True)
with open('branding/locale/entities.specific.adoc', 'w') as f:
template_target = env.get_template('entities.specific.adoc.j2')
print(template_target.render(product), file=f)
f.close()
pathlib.Path("branding/pdf/").mkdir(parents=True, exist_ok=True)
with open('branding/pdf/entities.adoc', 'w') as f:
template_target = env.get_template('entities.adoc.j2')
print(template_target.render(config_data), file=f)
f.close()
with open('site.yml', 'w') as f:
print("Creating site.yml.")
template_target = env.get_template('site.yml.common.j2')
print(template_target.render(config_data), file=f)
print("Creating parameters specific for " + param_product + " in site.yml")
template_target = env.get_template('site.yml.j2')
print(template_target.render(product), file=f)
f.close()
with open('antora.yml', 'w') as f:
print("Creating parameters specific for " + param_product + " in antora.yml")
template_target = env.get_template('antora.yml.j2')
print(template_target.render(product), file=f)
f.close()
print("Configuration Completed!")