Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
43af1188
Commit
43af1188
authored
Aug 03, 2018
by
Robert Czechowski
Browse files
Yaml-Configreader
parent
cb2d9344
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/configreader_yaml.rs
0 → 100644
View file @
43af1188
extern
crate
linked_hash_map
;
use
self
::
linked_hash_map
::
LinkedHashMap
;
use
db_objects
::{
Contest
,
Taskgroup
,
Task
};
#[derive(Debug,
Deserialize)]
struct
ContestYaml
{
name
:
Option
<
String
>
,
participation_start
:
Option
<
String
>
,
participation_end
:
Option
<
String
>
,
duration_minutes
:
Option
<
u32
>
,
public_listing
:
Option
<
bool
>
,
tasks
:
Option
<
serde_yaml
::
Mapping
>
,
}
pub
fn
parse_yaml
(
content
:
&
str
,
filename
:
&
str
,
directory
:
&
str
)
->
Option
<
Contest
>
{
let
config
:
ContestYaml
=
serde_yaml
::
from_str
(
&
content
)
.unwrap
();
println!
(
"hi"
);
let
mut
contest
=
Contest
::
new
(
directory
.to_string
(),
filename
.to_string
(),
config
.name
?
,
config
.duration_minutes
?
,
config
.public_listing
.unwrap_or
(
false
),
None
,
None
);
println!
(
"hi"
);
for
(
name
,
info
)
in
config
.tasks
?
{
println!
(
"hi"
);
if
let
serde_yaml
::
Value
::
String
(
name
)
=
name
{
let
mut
taskgroup
=
Taskgroup
::
new
(
name
);
match
info
{
serde_yaml
::
Value
::
String
(
taskdir
)
=>
{
let
mut
task
=
Task
::
new
(
taskdir
,
3
);
taskgroup
.tasks
.push
(
task
);
},
serde_yaml
::
Value
::
Sequence
(
taskdirs
)
=>
{
let
mut
stars
=
2
;
for
taskdir
in
taskdirs
{
if
let
serde_yaml
::
Value
::
String
(
taskdir
)
=
taskdir
{
let
mut
task
=
Task
::
new
(
taskdir
,
stars
);
taskgroup
.tasks
.push
(
task
);
}
else
{
panic!
(
"Invalid contest YAML: {}{} (a)"
,
directory
,
filename
)
}
stars
+=
1
;
}
}
serde_yaml
::
Value
::
Mapping
(
taskdirs
)
=>
{
let
mut
stars
=
2
;
for
(
taskdir
,
taskinfo
)
in
taskdirs
{
if
let
(
serde_yaml
::
Value
::
String
(
taskdir
),
serde_yaml
::
Value
::
Mapping
(
taskinfo
))
=
(
taskdir
,
taskinfo
)
{
if
let
Some
(
serde_yaml
::
Value
::
Number
(
cstars
))
=
taskinfo
.get
(
&
serde_yaml
::
Value
::
String
(
"stars"
.to_string
()))
{
stars
=
cstars
.as_u64
()
.unwrap
()
as
u8
;
}
let
mut
task
=
Task
::
new
(
taskdir
,
stars
);
taskgroup
.tasks
.push
(
task
);
stars
+=
1
;
}
else
{
panic!
(
"Invalid contest YAML: {}{} (b)"
,
directory
,
filename
)
}
}
}
_
=>
panic!
(
"Invalid contest YAML: {}{} (c)"
,
directory
,
filename
)
}
contest
.taskgroups
.push
(
taskgroup
);
}
else
{
panic!
(
"Invalid contest YAML: {}{} (d)"
,
directory
,
filename
)
}
}
Some
(
contest
)
}
Robert Czechowski
@zgtm
mentioned in issue
#1 (closed)
·
Aug 10, 2018
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment