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
722b59fb
Commit
722b59fb
authored
4 years ago
by
Amandine PERRIN
Browse files
Options
Downloads
Patches
Plain Diff
Add class for config parser
parent
eac94f8c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PanACoTA/utils_argparse.py
+74
-0
74 additions, 0 deletions
PanACoTA/utils_argparse.py
with
74 additions
and
0 deletions
PanACoTA/utils_argparse.py
+
74
−
0
View file @
722b59fb
...
@@ -42,6 +42,8 @@ April 2017
...
@@ -42,6 +42,8 @@ April 2017
"""
"""
from
PanACoTA
import
utils
from
PanACoTA
import
utils
import
argparse
import
argparse
import
configparser
import
sys
def
gen_name
(
param
):
def
gen_name
(
param
):
...
@@ -149,3 +151,75 @@ def perc_id(param):
...
@@ -149,3 +151,75 @@ def perc_id(param):
msg
=
(
"
The minimum %% of identity must be in [0, 1]. Invalid value: {}
"
.
format
(
param
))
msg
=
(
"
The minimum %% of identity must be in [0, 1]. Invalid value: {}
"
.
format
(
param
))
raise
argparse
.
ArgumentTypeError
(
msg
)
raise
argparse
.
ArgumentTypeError
(
msg
)
return
param
return
param
class
Conf_all_parser
(
configparser
.
ConfigParser
):
"""
Read configfile and return arguments found, according to required type
"""
def
__init__
(
self
,
conffile
,
sections
):
super
().
__init__
()
self
.
read
(
conffile
)
self
.
sec_dicts
=
{}
for
sec
in
sections
:
self
.
sec_dicts
[
sec
]
=
dict
(
self
[
sec
])
def
get_section_dict
(
self
,
section
):
"""
get dictionary of values for
'
section
'
section
"""
return
self
.
sec_dicts
[
section
]
def
add_default
(
self
,
defargs
,
section
):
"""
Add all default arguments (defargs) in section dict.
"""
for
key
,
val
in
defargs
.
items
():
if
key
not
in
self
.
sec_dicts
[
section
]:
self
[
section
][
key
]
=
str
(
val
)
self
.
sec_dicts
[
section
][
key
]
=
val
def
update
(
self
,
args
,
section
):
"""
Add all arguments from args. If key already exists in self, overwrite it.
Otherwise, create it.
"""
self
.
sec_dicts
[
section
].
update
(
args
)
for
key
,
val
in
self
.
sec_dicts
[
section
].
items
():
self
[
section
][
key
]
=
str
(
val
)
def
set_boolean
(
self
,
section
,
param
):
"""
Change param of section to boolean
"""
try
:
bool_param
=
self
.
getboolean
(
section
,
param
)
self
.
sec_dicts
[
section
][
param
]
=
bool_param
except
ValueError
as
err
:
val
=
self
[
section
][
param
]
print
(
f
"
ERROR:
{
param
}
must be a boolean. Wrong value:
{
val
}
.
"
)
sys
.
exit
(
1
)
def
set_int
(
self
,
section
,
param
):
"""
Change param of section to boolean
"""
try
:
int_param
=
self
.
getint
(
section
,
param
)
self
.
sec_dicts
[
section
][
param
]
=
int_param
except
ValueError
as
err
:
val
=
self
[
section
][
param
]
print
(
f
"
ERROR:
{
param
}
must be an int. Wrong value:
{
val
}
.
"
)
sys
.
exit
(
1
)
def
set_float
(
self
,
section
,
param
):
"""
Change param of section to boolean
"""
try
:
float_param
=
self
.
getfloat
(
section
,
param
)
self
.
sec_dicts
[
section
][
param
]
=
float_param
except
ValueError
as
err
:
val
=
self
[
section
][
param
]
print
(
f
"
ERROR:
{
param
}
must be a float. Wrong value:
{
val
}
.
"
)
sys
.
exit
(
1
)
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