Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automated-problem-generation-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
MUNI-KYPO-CRP
backend-python
automated-problem-generation-lib
Merge requests
!10
Resolve "Create parser for variables from the json object"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Create parser for variables from the json object"
3-create-parser-for-variables-from-the-json-object
into
develop
Overview
0
Commits
2
Pipelines
3
Changes
2
Merged
Juraj Paluba
requested to merge
3-create-parser-for-variables-from-the-json-object
into
develop
3 years ago
Overview
0
Commits
2
Pipelines
3
Changes
2
Expand
Closes
#3 (closed)
Edited
3 years ago
by
Juraj Paluba
0
0
Merge request reports
Compare
develop
version 1
234c8c9d
3 years ago
develop (base)
and
latest version
latest version
37ef5a01
2 commits,
3 years ago
version 1
234c8c9d
1 commit,
3 years ago
2 files
+
23
−
17
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
generator/var_parser.py
+
22
−
16
Options
from
typing
import
List
import
yaml
import
yaml
from
generator.var_object
import
Variable
from
generator.var_object
import
Variable
def
get_variables
(
variables_raw
:
dict
)
->
List
[
Variable
]:
var_objects
=
[]
for
variable_name
,
variable_options
in
variables_raw
.
items
():
v_type
=
variable_options
[
"
type
"
]
v_min
=
variable_options
.
get
(
"
min
"
)
v_max
=
variable_options
.
get
(
"
max
"
)
v_length
=
variable_options
.
get
(
"
length
"
)
v_prohibited
=
variable_options
.
get
(
"
prohibited
"
)
if
v_prohibited
is
None
:
v_prohibited
=
[]
var_objects
.
append
(
Variable
(
variable_name
,
v_type
,
v_min
,
v_max
,
v_prohibited
,
v_length
))
return
var_objects
def
parser_var_file
(
var_file
):
def
parser_var_file
(
var_file
):
"""
"""
Main function to parsen source data stored in file.
Main function to parsen source data stored in file.
@@ -19,20 +36,9 @@ def parser_var_file(var_file):
@@ -19,20 +36,9 @@ def parser_var_file(var_file):
"""
"""
try
:
try
:
var_list
=
yaml
.
load
(
var_file
,
Loader
=
yaml
.
FullLoader
)
variables_raw
=
yaml
.
load
(
var_file
,
Loader
=
yaml
.
FullLoader
)
var_objects
=
[]
return
get_variables
(
variables_raw
)
for
var
in
var_list
.
keys
():
except
Exception
as
exc
:
v_name
=
var
# TODO: Remove this horrendous exception handling!
v_type
=
var_list
[
var
][
"
type
"
]
print
(
f
"
Something went wrong:
{
exc
}
"
)
v_min
=
var_list
[
var
].
get
(
"
min
"
)
v_max
=
var_list
[
var
].
get
(
"
max
"
)
v_length
=
var_list
[
var
].
get
(
"
length
"
)
v_prohibited
=
var_list
[
var
].
get
(
"
prohibited
"
)
if
v_prohibited
is
None
:
v_prohibited
=
[]
var_objects
.
append
(
Variable
(
v_name
,
v_type
,
v_min
,
v_max
,
v_prohibited
,
v_length
))
except
Exception
as
e
:
print
(
"
Error occure
"
)
return
None
return
None
return
var_objects
Loading