admin: synchronization of exercices, files, hints and keys

This commit is contained in:
nemunaire 2017-12-09 01:21:58 +01:00 committed by nemunaire
parent e5777e604b
commit 3253707824
5 changed files with 227 additions and 1 deletions

View file

@ -0,0 +1,29 @@
package sync
import (
"fmt"
"path"
"srs.epita.fr/fic-server/libfic"
)
func SyncExerciceHints(i Importer, exercice fic.Exercice) []string {
var errs []string
if _, err := exercice.WipeHints(); err != nil {
errs = append(errs, err.Error())
} else if hints, err := i.listDir(path.Join(exercice.Path, "hints")); err != nil {
errs = append(errs, err.Error())
} else {
for _, hfile := range hints {
if hint_cnt, err := getFileContent(i, path.Join(exercice.Path, "hints", hfile)); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to read hint file %q: %s", path.Base(exercice.Path), hfile, err))
continue
} else if _, err := exercice.AddHint(hfile, hint_cnt, 1); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to add hint %q: %s", path.Base(exercice.Path), hfile, err))
continue
}
}
}
return errs
}