2022-10-29 15:03:57 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2022-10-31 15:38:32 +00:00
|
|
|
func (c *CheckExceptions) GetFileExceptions(paths ...string) *CheckExceptions {
|
2022-10-29 15:03:57 +00:00
|
|
|
ret := CheckExceptions{}
|
|
|
|
|
2022-12-02 14:27:43 +00:00
|
|
|
if c != nil {
|
|
|
|
for k, v := range *c {
|
|
|
|
cols := strings.SplitN(k, ":", 2)
|
|
|
|
if len(cols) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
2022-10-31 16:21:22 +00:00
|
|
|
|
2022-12-02 14:27:43 +00:00
|
|
|
for _, path := range paths {
|
|
|
|
if strings.HasPrefix(cols[0], path) {
|
|
|
|
k = strings.TrimPrefix(k, path)
|
2022-10-29 15:03:57 +00:00
|
|
|
|
2022-12-02 14:27:43 +00:00
|
|
|
if strings.HasPrefix(k, "/") {
|
|
|
|
k = strings.TrimPrefix(k, "/")
|
|
|
|
}
|
2022-10-29 15:03:57 +00:00
|
|
|
|
2022-12-02 14:27:43 +00:00
|
|
|
ret[k] = v
|
|
|
|
break
|
|
|
|
} else if eval, err := filepath.Match(cols[0], path); err == nil && eval {
|
|
|
|
ret[k] = v
|
|
|
|
break
|
|
|
|
}
|
2022-10-31 15:38:32 +00:00
|
|
|
}
|
2022-10-29 15:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:27:43 +00:00
|
|
|
// Ignore redondances in resolution.md
|
|
|
|
if len(paths) > 0 && paths[0] == "resolution.md" {
|
|
|
|
ret["resolution.md:*:redondances_paragraphe"] = "automatic"
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
return &ret
|
|
|
|
}
|
|
|
|
|
2022-11-02 16:42:08 +00:00
|
|
|
func (c *CheckExceptions) Filter2ndCol(str string) *CheckExceptions {
|
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := CheckExceptions{}
|
|
|
|
|
|
|
|
for k, v := range *c {
|
|
|
|
cols := strings.SplitN(k, ":", 3)
|
|
|
|
if len(cols) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-11-03 16:49:06 +00:00
|
|
|
if cols[1] == "spelling" {
|
|
|
|
ret[k] = v
|
|
|
|
} else if eval, err := filepath.Match(cols[1], str); err == nil && eval {
|
2022-11-02 16:42:08 +00:00
|
|
|
ret[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ret
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-07-09 17:05:58 +00:00
|
|
|
func ParseExceptionString(fexcept string, exceptions *CheckExceptions) *CheckExceptions {
|
|
|
|
if exceptions == nil {
|
|
|
|
exceptions = &CheckExceptions{}
|
|
|
|
}
|
|
|
|
|
|
|
|
for n, line := range strings.Split(fexcept, "\n") {
|
|
|
|
(*exceptions)[strings.TrimSpace(line)] = fmt.Sprintf("repochecker-ack.txt:%d", n+1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return exceptions
|
|
|
|
}
|
|
|
|
|
2023-06-14 15:24:15 +00:00
|
|
|
func LoadThemeException(i Importer, th *fic.Theme) (exceptions *CheckExceptions) {
|
2024-03-15 16:46:50 +00:00
|
|
|
if th == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
if fexcept, err := GetFileContent(i, filepath.Join(th.Path, "repochecker-ack.txt")); err == nil {
|
2023-07-09 17:05:58 +00:00
|
|
|
return ParseExceptionString(fexcept, nil)
|
2022-10-29 15:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-06-14 15:24:15 +00:00
|
|
|
|
|
|
|
func LoadExerciceException(i Importer, th *fic.Theme, e *fic.Exercice, th_exceptions *CheckExceptions) (exceptions *CheckExceptions) {
|
|
|
|
if th_exceptions == nil {
|
|
|
|
th_exceptions = LoadThemeException(i, th)
|
|
|
|
}
|
|
|
|
|
|
|
|
exceptions = th_exceptions.GetExerciceExceptions(e)
|
|
|
|
|
|
|
|
if fexcept, err := GetFileContent(i, filepath.Join(e.Path, "repochecker-ack.txt")); err == nil {
|
2023-07-09 17:05:58 +00:00
|
|
|
return ParseExceptionString(fexcept, exceptions)
|
2023-06-14 15:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|