server/admin/sync/exercice_defines.go

73 lines
2.2 KiB
Go
Raw Normal View History

package sync
import (
"path"
"github.com/BurntSushi/toml"
)
2018-03-09 18:07:08 +00:00
// ExerciceHintParams holds EHint definition infomation.
type ExerciceHintParams struct {
Filename string
Content string
Cost int64
Title string
}
// ExerciceDependency holds dependency definitions information.
type ExerciceDependency struct {
Id int64
Theme string `toml:",omitempty"`
}
// ExerciceUnlockFile holds parameters related to a locked file.
type ExerciceUnlockFile struct {
Filename string `toml:",omitempty"`
}
2019-01-18 03:24:28 +00:00
// ExerciceFlagChoice holds informations about a choice (for MCQ and UCQ).
type ExerciceFlagChoice struct {
Label string `toml:",omitempty"`
Value interface{} `toml:",omitempty"`
Justification *ExerciceFlag `toml:",omitempty""`
}
2019-01-16 04:25:20 +00:00
// ExerciceFlag holds informations about one flag.
type ExerciceFlag struct {
2018-12-02 18:21:07 +00:00
Id int64
2018-11-16 19:46:19 +00:00
Label string `toml:",omitempty"`
2019-01-16 04:25:20 +00:00
Type string `toml:",omitempty"`
2018-12-04 17:34:38 +00:00
Raw interface{}
Separator string `toml:",omitempty"`
2018-12-04 18:09:58 +00:00
Ordered bool `toml:",omitempty"`
2018-11-16 19:46:19 +00:00
IgnoreCase bool `toml:",omitempty"`
ValidatorRe string `toml:"validator_regexp,omitempty"`
Help string `toml:",omitempty"`
2019-01-16 04:25:20 +00:00
ChoicesCost int64 `toml:"choices_cost,omitempty"`
2019-01-18 03:24:28 +00:00
Choice []ExerciceFlagChoice
2018-11-16 19:46:19 +00:00
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
2018-12-02 18:21:07 +00:00
NeedFlag []ExerciceDependency `toml:"need_flag,omitempty"`
2019-01-16 04:25:20 +00:00
NoShuffle bool
}
2018-03-09 18:07:08 +00:00
// ExerciceParams contains values parsed from defines.txt.
type ExerciceParams struct {
Gain int64
Tags []string
Hints []ExerciceHintParams `toml:"hint"`
Dependencies []ExerciceDependency `toml:"depend"`
Flags []ExerciceFlag `toml:"flag"`
2019-01-16 04:25:20 +00:00
FlagsMCQ []ExerciceFlag `toml:"flag_mcq"`
FlagsUCQ []ExerciceFlag `toml:"flag_ucq"`
}
2018-03-09 18:07:08 +00:00
// parseExerciceParams reads challenge definitions from defines.txt and extract usefull data to set up the challenge.
func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, err error) {
var defs string
defs, err = getFileContent(i, path.Join(exPath, "challenge.txt"))
_, err = toml.Decode(defs, &p)
return
}