admin: synchronization of exercices, files, hints and keys
This commit is contained in:
parent
a033f81f5f
commit
762d3a5222
5 changed files with 227 additions and 1 deletions
46
admin/sync/exercice_keys.go
Normal file
46
admin/sync/exercice_keys.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string {
|
||||
var errs []string
|
||||
|
||||
if _, err := exercice.WipeKeys(); err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
} else if flags, err := getFileContent(i, path.Join(exercice.Path, "flags.txt")); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to read flags: %s", path.Base(exercice.Path), err))
|
||||
} else {
|
||||
for nline, flag := range strings.Split(flags, "\n") {
|
||||
flag_splt := strings.SplitN(string(flag), "\t", 2)
|
||||
if len(flag_splt) > 2 {
|
||||
errs = append(errs, fmt.Sprintf("%q: error in flags file at line %d: invalid format", path.Base(exercice.Path), nline + 1))
|
||||
continue
|
||||
}
|
||||
|
||||
var label, rawkey string
|
||||
if len(flag_splt) == 1 {
|
||||
rawkey = flag_splt[0]
|
||||
} else {
|
||||
label = flag_splt[0]
|
||||
rawkey = flag_splt[1]
|
||||
}
|
||||
|
||||
if len(label) == 0 {
|
||||
label = "Flag"
|
||||
}
|
||||
|
||||
if _, err := exercice.AddRawKey(label, rawkey); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error in flags file at line %d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
Reference in a new issue