Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
panacota
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amandine PERRIN
panacota
Commits
5ab9ef44
Commit
5ab9ef44
authored
3 years ago
by
Amandine PERRIN
Browse files
Options
Downloads
Patches
Plain Diff
remove quote marks surrounding strings in configfile
parent
d3ec33c7
No related branches found
No related tags found
No related merge requests found
Pipeline
#62509
passed
3 years ago
Stage: test
Stage: coverage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PanACoTA/utils_argparse.py
+27
-0
27 additions, 0 deletions
PanACoTA/utils_argparse.py
with
27 additions
and
0 deletions
PanACoTA/utils_argparse.py
+
27
−
0
View file @
5ab9ef44
...
...
@@ -193,28 +193,55 @@ def perc_id(param):
class
Conf_all_parser
(
configparser
.
ConfigParser
):
"""
Read configfile and return arguments found, according to required type
Parameters
----------
conffile : str
path to configuration file
readsec : list
list of sections of the config file to read
Attributes
----------
conffile : str
Path to configfile
sec_dicts : dict
{section1: {param: value}, {section2: {param:value}}}
"""
def
__init__
(
self
,
conffile
,
readsec
=
[]):
super
().
__init__
()
# If there is a config file specified, but it does not exist -> exit with error message
if
conffile
!=
""
and
not
os
.
path
.
isfile
(
conffile
):
print
(
f
"
Error: config file
{
conffile
}
not found.
"
)
sys
.
exit
(
1
)
self
.
conffile
=
conffile
# Read the config file
try
:
self
.
read
(
conffile
)
except
configparser
.
DuplicateOptionError
as
err
:
print
(
err
)
sys
.
exit
(
1
)
self
.
sec_dicts
=
{}
# Convert configfile sections to dicts
for
sec
in
readsec
:
# If section in configfile, put its arguments and values to a dict
# If not, create empty section, and associate with empty dict
if
sec
in
dict
(
self
):
self
.
sec_dicts
[
sec
]
=
dict
(
self
[
sec
])
self
.
clean_strings
(
sec
)
else
:
self
.
sec_dicts
[
sec
]
=
{}
self
.
add_section
(
sec
)
def
clean_strings
(
self
,
section
):
"""
Remove quote marks surrounding strings
"""
for
param
in
self
.
sec_dicts
[
section
]:
initial
=
self
.
sec_dicts
[
section
][
param
]
self
.
sec_dicts
[
section
][
param
]
=
initial
.
strip
(
'"'
)
def
get_section_dict
(
self
,
section
):
"""
get dictionary of values for
'
section
'
section
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment