admin/sync: new error on flags import
This commit is contained in:
parent
a0a2313924
commit
eee1558dd9
@ -4,10 +4,20 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/libfic"
|
"srs.epita.fr/fic-server/libfic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isFullGraphic(s string) bool {
|
||||||
|
for _, c := range s {
|
||||||
|
if !unicode.IsGraphic(c) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string {
|
func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string {
|
||||||
var errs []string
|
var errs []string
|
||||||
|
|
||||||
@ -23,16 +33,21 @@ func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var label, rawkey string
|
|
||||||
if len(flag_splt) == 1 {
|
if len(flag_splt) == 1 {
|
||||||
rawkey = flag_splt[0]
|
errs = append(errs, fmt.Sprintf("%q: error in flags file at line %d: no separator found", path.Base(exercice.Path), nline + 1))
|
||||||
} else {
|
continue
|
||||||
label = flag_splt[0]
|
|
||||||
rawkey = flag_splt[1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(label) == 0 {
|
var label, rawkey string
|
||||||
|
if len(flag_splt[0]) == 0 {
|
||||||
label = "Flag"
|
label = "Flag"
|
||||||
|
} else {
|
||||||
|
label = flag_splt[0]
|
||||||
|
}
|
||||||
|
rawkey = flag_splt[1]
|
||||||
|
|
||||||
|
if !isFullGraphic(rawkey) {
|
||||||
|
errs = append(errs, fmt.Sprintf("%q: WARNING in flags file at line %d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := exercice.AddRawKey(label, rawkey); err != nil {
|
if _, err := exercice.AddRawKey(label, rawkey); err != nil {
|
||||||
@ -104,6 +119,11 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(quest) < 2 {
|
||||||
|
errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d: missing label", path.Base(exercice.Path), nline + 1))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := flag.AddEntry(choice[1:], choice[0] == 49); err != nil {
|
if _, err := flag.AddEntry(choice[1:], choice[0] == 49); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d,%d: %s", path.Base(exercice.Path), nline + 1, cid, err))
|
errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d,%d: %s", path.Base(exercice.Path), nline + 1, cid, err))
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user