sync: Introduce repochecker-ack.txt to support check exceptions

This commit is contained in:
nemunaire 2022-10-29 17:03:57 +02:00
parent edde9f885d
commit fb368d79d1
17 changed files with 283 additions and 106 deletions

62
admin/sync/exceptions.go Normal file
View file

@ -0,0 +1,62 @@
package sync
import (
"fmt"
"path/filepath"
"strings"
"srs.epita.fr/fic-server/libfic"
)
type CheckExceptions map[string]string
func (c *CheckExceptions) GetExerciceExceptions(e *fic.Exercice) *CheckExceptions {
return c.GetFileExceptions(filepath.Base(e.Path))
}
func (c *CheckExceptions) GetFileExceptions(path string) *CheckExceptions {
if c == nil {
return nil
}
ret := CheckExceptions{}
for k, v := range *c {
if strings.HasPrefix(k, "*:") || strings.HasPrefix(k, path) {
k = strings.TrimPrefix(k, path)
if strings.HasPrefix(k, "/") {
k = strings.TrimPrefix(k, "/")
}
ret[k] = v
}
}
return &ret
}
func (c *CheckExceptions) HasException(ref string) bool {
if c == nil {
return false
}
for k, _ := range *c {
if strings.HasSuffix(k, ref) {
return true
}
}
return false
}
func LoadException(i Importer, th *fic.Theme) (exceptions *CheckExceptions) {
if fexcept, err := GetFileContent(i, filepath.Join(th.Path, "repochecker-ack.txt")); err == nil {
exceptions = &CheckExceptions{}
for n, line := range strings.Split(fexcept, "\n") {
(*exceptions)[line] = fmt.Sprintf("repochecker-ack.txt:%d", n+1)
}
}
return
}