Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cfel_fmt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
dataAnalysis
cfel_fmt
Commits
da7b8861
Commit
da7b8861
authored
8 years ago
by
Valerio Mariani
Browse files
Options
Downloads
Patches
Plain Diff
Switched to ast module to parse dictionaries and lists
parent
ab6f50c9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cfel_optarg.py
+11
-11
11 additions, 11 deletions
cfel_optarg.py
with
11 additions
and
11 deletions
cfel_optarg.py
+
11
−
11
View file @
da7b8861
...
@@ -28,9 +28,7 @@ configuration files.
...
@@ -28,9 +28,7 @@ configuration files.
"""
"""
import
argparse
import
ast
import
os
import
json
def
parse_parameters
(
config
):
def
parse_parameters
(
config
):
...
@@ -84,18 +82,20 @@ def parse_parameters(config):
...
@@ -84,18 +82,20 @@ def parse_parameters(config):
continue
continue
if
monitor_params
[
sect
][
op
].
startswith
(
"
[
"
)
and
monitor_params
[
sect
][
op
].
endswith
(
"
]
"
):
if
monitor_params
[
sect
][
op
].
startswith
(
"
[
"
)
and
monitor_params
[
sect
][
op
].
endswith
(
"
]
"
):
try
:
try
:
monitor_params
[
sect
][
op
]
=
json
.
loads
(
config
.
get
(
sect
,
op
)
.
replace
(
"'"
,
'"'
)
)
monitor_params
[
sect
][
op
]
=
ast
.
literal_eval
(
config
.
get
(
sect
,
op
))
continue
continue
except
:
except
(
SyntaxError
,
ValueError
):
raise
RuntimeError
(
'
Error parsing parameters. The parameter {0}/{1} parameter
'
raise
RuntimeError
(
'
Error parsing parameter {0} in section {1}. Make sure that the syntax is
'
'
has an invalid type.
'
.
format
(
sect
,
op
))
'
correct: list elements are separated by comma, dict entries contain the colon
'
'
symbol and strings are quoted.
'
.
format
(
op
,
sect
))
if
monitor_params
[
sect
][
op
].
startswith
(
"
{
"
)
and
monitor_params
[
sect
][
op
].
endswith
(
"
}
"
):
if
monitor_params
[
sect
][
op
].
startswith
(
"
{
"
)
and
monitor_params
[
sect
][
op
].
endswith
(
"
}
"
):
try
:
try
:
monitor_params
[
sect
][
op
]
=
json
.
loads
(
config
.
get
(
sect
,
op
)
.
replace
(
"'"
,
'"'
)
)
monitor_params
[
sect
][
op
]
=
ast
.
literal_eval
(
config
.
get
(
sect
,
op
))
continue
continue
except
:
except
(
SyntaxError
,
ValueError
):
raise
RuntimeError
(
'
Error parsing parameters. The parameter {0}/{1} parameter
'
raise
RuntimeError
(
'
Error parsing parameter {0} in section {1}. Make sure that the syntax is
'
'
has an invalid type.
'
.
format
(
sect
,
op
))
'
correct: list elements are separated by comma, dict entries contain the colon
'
'
symbol and strings are quoted.
'
.
format
(
op
,
sect
))
if
monitor_params
[
sect
][
op
]
==
'
None
'
:
if
monitor_params
[
sect
][
op
]
==
'
None
'
:
monitor_params
[
sect
][
op
]
=
None
monitor_params
[
sect
][
op
]
=
None
continue
continue
...
...
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