sync: Better perform exception in exercices

This commit is contained in:
nemunaire 2023-07-09 19:05:58 +02:00
parent edbb867f62
commit dc83efa868
8 changed files with 45 additions and 34 deletions

View File

@ -142,7 +142,8 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadThemeException(sync.GlobalImporter, theme)
c.JSON(http.StatusOK, flatifySyncErrors(sync.SyncExercices(sync.GlobalImporter, theme, exceptions)))
_, errs := sync.SyncExercices(sync.GlobalImporter, theme, exceptions)
c.JSON(http.StatusOK, flatifySyncErrors(errs))
})
apiSyncExercicesRoutes := router.Group("/exercices/:eid")
apiSyncExercicesRoutes.Use(ExerciceHandler)
@ -152,7 +153,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
exceptions := sync.LoadExerciceException(sync.GlobalImporter, theme, exercice, nil)
_, _, errs := sync.SyncExercice(sync.GlobalImporter, theme, exercice.Path, nil, exceptions)
_, _, _, errs := sync.SyncExercice(sync.GlobalImporter, theme, exercice.Path, nil, exceptions)
c.JSON(http.StatusOK, flatifySyncErrors(errs))
})
apiSyncExercicesRoutes.POST("/files", func(c *gin.Context) {

View File

@ -87,12 +87,21 @@ func (c *CheckExceptions) HasException(ref string) bool {
return false
}
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
}
func LoadThemeException(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)[strings.TrimSpace(line)] = fmt.Sprintf("repochecker-ack.txt:%d", n+1)
}
return ParseExceptionString(fexcept, nil)
}
return
@ -106,9 +115,7 @@ func LoadExerciceException(i Importer, th *fic.Theme, e *fic.Exercice, th_except
exceptions = th_exceptions.GetExerciceExceptions(e)
if fexcept, err := GetFileContent(i, filepath.Join(e.Path, "repochecker-ack.txt")); err == nil {
for n, line := range strings.Split(fexcept, "\n") {
(*exceptions)[strings.TrimSpace(line)] = fmt.Sprintf("repochecker-ack.txt:%d", n+1)
}
return ParseExceptionString(fexcept, exceptions)
}
return

View File

@ -265,7 +265,7 @@ func SyncExerciceFiles(i Importer, exercice *fic.Exercice, exceptions *CheckExce
func ApiGetRemoteExerciceFiles(c *gin.Context) {
theme, exceptions, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
exercice, _, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
if exercice != nil {
files, digests, errs := BuildFilesListInto(GlobalImporter, exercice, "files")
if files != nil {

View File

@ -164,9 +164,9 @@ func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int
func ApiGetRemoteExerciceHints(c *gin.Context) {
theme, exceptions, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
exercice, _, _, eexceptions, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
if exercice != nil {
hints, errs := CheckExerciceHints(GlobalImporter, exercice, exceptions)
hints, errs := CheckExerciceHints(GlobalImporter, exercice, eexceptions)
if hints != nil {
c.JSON(http.StatusOK, hints)
return

View File

@ -649,9 +649,9 @@ func SyncExerciceFlags(i Importer, exercice *fic.Exercice, exceptions *CheckExce
func ApiGetRemoteExerciceFlags(c *gin.Context) {
theme, exceptions, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
exercice, _, _, eexceptions, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
if exercice != nil {
flags, errs := CheckExerciceFlags(GlobalImporter, exercice, []string{}, exceptions)
flags, errs := CheckExerciceFlags(GlobalImporter, exercice, []string{}, eexceptions)
if flags != nil {
c.JSON(http.StatusOK, flags)
return

View File

@ -93,7 +93,7 @@ func parseExerciceDirname(edir string) (eid int, ename string, err error) {
}
// BuildExercice creates an Exercice from a given importer.
func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions *CheckExceptions) (e *fic.Exercice, p ExerciceParams, eid int, edir string, errs []error) {
func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions_in *CheckExceptions) (e *fic.Exercice, p ExerciceParams, eid int, exceptions *CheckExceptions, edir string, errs []error) {
e = &fic.Exercice{}
e.Path = epath
@ -105,12 +105,12 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
// Ignore eid if we are certain this is an exercice directory, eid will be 0
if !i.Exists(path.Join(epath, "title.txt")) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("unable to parse exercice directory: %w", err), theme))
return nil, p, eid, edir, errs
return nil, p, eid, exceptions_in, edir, errs
}
}
// Get exceptions
exceptions = LoadExerciceException(i, theme, e, exceptions)
exceptions = LoadExerciceException(i, theme, e, exceptions_in)
//log.Printf("Kept repochecker exceptions for this exercice: %v", exceptions)
e.Language = theme.Language
@ -350,12 +350,12 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
// SyncExercice imports new or updates existing given exercice.
func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions *CheckExceptions) (e *fic.Exercice, eid int, errs []error) {
func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions_in *CheckExceptions) (e *fic.Exercice, eid int, exceptions *CheckExceptions, errs []error) {
var err error
var p ExerciceParams
var berrors []error
e, p, eid, _, berrors = BuildExercice(i, theme, epath, dmap, exceptions)
e, p, eid, exceptions, _, berrors = BuildExercice(i, theme, epath, dmap, exceptions_in)
for _, e := range berrors {
errs = append(errs, e)
}
@ -403,7 +403,7 @@ func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*f
}
// SyncExercices imports new or updates existing exercices, in a given theme.
func SyncExercices(i Importer, theme *fic.Theme, exceptions *CheckExceptions) (errs []error) {
func SyncExercices(i Importer, theme *fic.Theme, exceptions *CheckExceptions) (exceptions_out map[int]*CheckExceptions, errs []error) {
if exercices, err := GetExercices(i, theme); err != nil {
errs = append(errs, err)
} else {
@ -412,10 +412,11 @@ func SyncExercices(i Importer, theme *fic.Theme, exceptions *CheckExceptions) (e
dmap, _ := buildDependancyMap(i, theme)
for _, edir := range exercices {
e, eid, cur_errs := SyncExercice(i, theme, path.Join(theme.Path, edir), &dmap, exceptions)
e, eid, ex_exceptions, cur_errs := SyncExercice(i, theme, path.Join(theme.Path, edir), &dmap, exceptions)
if e != nil {
emap[e.Title] = eid
dmap[int64(eid)] = e
exceptions_out[eid] = ex_exceptions
errs = append(errs, cur_errs...)
}
}
@ -453,7 +454,7 @@ func ApiListRemoteExercices(c *gin.Context) {
func ApiGetRemoteExercice(c *gin.Context) {
theme, exceptions, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
exercice, _, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
if exercice != nil {
c.JSON(http.StatusOK, exercice)
return

View File

@ -58,7 +58,7 @@ func SpeedySyncDeep(i Importer) (errs SyncReport) {
for tid, theme := range themes {
DeepSyncProgress = 3 + uint8(tid)*themeStep
seerrs := SyncExercices(i, theme, exceptions[theme.Path])
ex_exceptions, seerrs := SyncExercices(i, theme, exceptions[theme.Path])
for _, seerr := range seerrs {
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], seerr.Error())
}
@ -72,13 +72,13 @@ func SpeedySyncDeep(i Importer) (errs SyncReport) {
log.Printf("Speedy synchronization in progress: %d/255 - doing Theme %q, Exercice %q: %q\n", DeepSyncProgress, theme.Name, exercice.Title, exercice.Path)
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
flagsBindings, ferrs := SyncExerciceFlags(i, exercice, exceptions[theme.Path])
flagsBindings, ferrs := SyncExerciceFlags(i, exercice, ex_exceptions[eid])
for _, ferr := range ferrs {
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], ferr.Error())
}
DeepSyncProgress += exerciceStep / 2
_, herrs := SyncExerciceHints(i, exercice, flagsBindings, exceptions[theme.Path])
_, herrs := SyncExerciceHints(i, exercice, flagsBindings, ex_exceptions[eid])
for _, herr := range herrs {
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], herr.Error())
}
@ -193,11 +193,13 @@ func EditDeepReport(errs *SyncReport, erase bool) {
// SyncThemeDeep performs a recursive synchronisation: from challenges to challenge items.
func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8, exceptions *CheckExceptions) (errs []error) {
var ex_exceptions map[int]*CheckExceptions
oneThemeDeepSync.Lock()
defer oneThemeDeepSync.Unlock()
DeepSyncProgress = 3 + uint8(tid)*themeStep
errs = SyncExercices(i, theme, exceptions)
ex_exceptions, errs = SyncExercices(i, theme, exceptions)
if exercices, err := theme.GetExercices(); err == nil && len(exercices) > 0 {
var exerciceStep uint8 = themeStep / uint8(len(exercices))
@ -205,14 +207,14 @@ func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8, excep
log.Printf("Deep synchronization in progress: %d/255 - doing Theme %q, Exercice %q: %q\n", DeepSyncProgress, theme.Name, exercice.Title, exercice.Path)
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
errs = append(errs, SyncExerciceFiles(i, exercice, exceptions)...)
errs = append(errs, SyncExerciceFiles(i, exercice, ex_exceptions[eid])...)
DeepSyncProgress += exerciceStep / 3
flagsBindings, ferrs := SyncExerciceFlags(i, exercice, exceptions)
flagsBindings, ferrs := SyncExerciceFlags(i, exercice, ex_exceptions[eid])
errs = append(errs, ferrs...)
DeepSyncProgress += exerciceStep / 3
_, herrs := SyncExerciceHints(i, exercice, flagsBindings, exceptions)
_, herrs := SyncExerciceHints(i, exercice, flagsBindings, ex_exceptions[eid])
errs = append(errs, herrs...)
}
}

View File

@ -109,12 +109,10 @@ func searchBinaryInGit(edir string) (ret []string) {
}
func checkExercice(theme *fic.Theme, edir string, dmap *map[int64]*fic.Exercice, exceptions *sync.CheckExceptions) (errs []error) {
e, _, eid, _, berrs := sync.BuildExercice(sync.GlobalImporter, theme, path.Join(theme.Path, edir), dmap, exceptions)
e, _, eid, exceptions, _, berrs := sync.BuildExercice(sync.GlobalImporter, theme, path.Join(theme.Path, edir), dmap, nil)
errs = append(errs, berrs...)
if e != nil {
exceptions = exceptions.GetExerciceExceptions(e)
// Files
var files []string
var cerrs []error
@ -263,7 +261,9 @@ func main() {
dmap := map[int64]*fic.Exercice{}
for _, edir := range exercices {
for _, err := range checkExercice(theme, edir, &dmap, exceptions) {
ex_exceptions := exceptions.GetFileExceptions(edir)
for _, err := range checkExercice(theme, edir, &dmap, ex_exceptions) {
log.Println(err.Error())
if logMissingResolution {
@ -293,7 +293,7 @@ func main() {
} else {
log.Printf("This is not a theme directory, run checks for exercice.\n\n")
for _, err := range checkExercice(&fic.Theme{}, p, &map[int64]*fic.Exercice{}, exceptions) {
for _, err := range checkExercice(&fic.Theme{}, p, &map[int64]*fic.Exercice{}, nil) {
nberr += 1
log.Println(err)
}