Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jakub Jalowiec
fill-template
Commits
45a17bc7
Commit
45a17bc7
authored
Mar 03, 2021
by
Jakub Jalowiec
Browse files
Fixing global dictionary processing
parent
2cabf6fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
fill-template.py
View file @
45a17bc7
...
...
@@ -46,10 +46,8 @@ logging.info("File with default values: " + default_json)
with
open
(
default_json
,
"r"
)
as
read_file
:
default
=
json
.
load
(
read_file
)
global_values
=
default
.
get
(
"global"
,
dict
())
for
key
in
default
:
if
not
key
==
"global"
:
for
global_default_key
in
global_values
:
default
[
key
][
global_default_key
]
=
default
[
key
].
get
(
global_default_key
,
global_values
[
global_default_key
])
print
(
"global_values: "
)
print
(
global_values
)
with
open
(
config_json
,
"r"
)
as
write_file
:
config
=
json
.
load
(
write_file
)
...
...
@@ -67,7 +65,9 @@ for directory, content in config.items():
for
template_name
,
files
in
content
.
items
():
# if the key does not exist return an empty dictionary
dictionary
=
default
.
get
(
template_name
,
dict
())
default_values
=
default
.
get
(
template_name
,
dict
())
logging
.
info
(
"Default values: "
)
logging
.
info
(
str
(
default_values
))
for
target
,
custom_values
in
files
.
items
():
if
(
len
(
custom_values
)
>
0
):
logging
.
info
(
"Filling up "
+
template_name
+
" with values from "
+
target
+
" dictionary and saving as "
+
directory
+
"/"
+
target
+
"."
)
...
...
@@ -80,9 +80,13 @@ for directory, content in config.items():
else
:
template_path
=
templates_dir
+
template_name
t
=
templateEnv
.
get_template
(
template_path
)
for
key
,
value
in
custom_values
.
items
():
dictionary
[
key
]
=
value
dictionary
[
'directory'
]
=
directory
logging
.
info
(
"Custom values: "
)
logging
.
info
(
str
(
custom_values
))
dictionary
=
global_values
.
copy
()
dictionary
.
update
(
default_values
)
dictionary
.
update
(
custom_values
)
logging
.
info
(
"Resulting gictionary: "
)
logging
.
info
(
str
(
dictionary
))
output
=
t
.
render
(
dictionary
)
with
open
(
path
+
"/"
+
target
,
'w'
)
as
filetowrite
:
filetowrite
.
write
(
output
)
...
...
tests/test.sh
View file @
45a17bc7
...
...
@@ -4,7 +4,7 @@ for test in */
do
cd
"
$test
"
echo
"Starting
$test
"
python ../../fill-template.py
-c
./config.json
-d
./default.json
-t
./
-l
ERROR
python ../../fill-template.py
-c
./config.json
-d
./default.json
-t
./
# check return code of prepare-md.py
if
[
"
$?
"
!=
"0"
]
;
then
# prepare-md.py failed...
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment