Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90946457
replace_in_config.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 6, 07:27
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Nov 8, 07:27 (2 d)
Engine
blob
Format
Raw Data
Handle
22163734
Attached To
R2915 eSCT pipeline interoperability
replace_in_config.py
View Options
import
logging
import
yaml
import
re
def
replace_in_config
(
paths
):
"""
Replaces the YAML configuration file and return a dictionary with all the configuration parameters.
@author: Balazs Laurenczy
@date: 2017-2018
"""
# do the "root" parts replacing in the paths
logging
.
debug
(
"Replacing '__XXXX_ROOT__' tags ..."
)
is_match
=
True
# repeat until no more roots have been replaced
while
is_match
:
is_match
=
False
# loop through each key/value pair in the "path" dictionary
for
key
,
value
in
paths
.
items
():
# replace the "__XXX_ROOT__" tags in the path with their corresponding path entry
# for example: "__DATA_ROOT__" should be replaced with paths['data_root']
if
re
.
match
(
'__\w+_ROOT__'
,
value
):
# a match was found, make sure to loop again
is_match
=
True
# extract the different parts of the path
re_match
=
re
.
match
(
'(.*)__(\w+)_ROOT__(.*)'
,
value
)
# get the root's name, like "DATA" or "REF"
root_name
=
re_match
.
groups
()[
1
]
# get the lower case version ("data" or "ref")
root_name_lower
=
root_name
.
lower
()
# replace the path: for example "__DATA_ROOT__" with paths['data_root']
paths
[
key
]
=
value
.
replace
(
"__"
+
root_name
+
"_ROOT__"
,
paths
[
root_name_lower
+
'_root'
])
# remove the beginning './' from all the paths
logging
.
debug
(
"Replacing './' ..."
)
is_match
=
True
# repeat until no more replacements have been done
while
is_match
:
is_match
=
False
# loop through each key/value pair in the "path" dictionary
for
key
,
value
in
paths
.
items
():
if
re
.
match
(
'^\./'
,
value
):
# a match was found, make sure to loop again
is_match
=
True
# remove the beginning of the path (the './')
paths
[
key
]
=
value
[
2
:]
return
paths
Event Timeline
Log In to Comment