sync: Handle repochecker-ack.txt in exercice directory

This commit is contained in:
nemunaire 2023-06-14 17:24:15 +02:00
parent c06d667088
commit f366d6b8c1
4 changed files with 28 additions and 13 deletions

View File

@ -59,7 +59,7 @@ func declareSyncRoutes(router *gin.RouterGroup) {
apiSyncDeepRoutes.POST("", func(c *gin.Context) { apiSyncDeepRoutes.POST("", func(c *gin.Context) {
theme := c.MustGet("theme").(*fic.Theme) theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadException(sync.GlobalImporter, theme) exceptions := sync.LoadThemeException(sync.GlobalImporter, theme)
var st []string var st []string
for _, se := range sync.SyncThemeDeep(sync.GlobalImporter, theme, 0, 250, exceptions) { for _, se := range sync.SyncThemeDeep(sync.GlobalImporter, theme, 0, 250, exceptions) {
@ -140,7 +140,7 @@ func declareSyncRoutes(router *gin.RouterGroup) {
func declareSyncExercicesRoutes(router *gin.RouterGroup) { func declareSyncExercicesRoutes(router *gin.RouterGroup) {
router.POST("/exercices", func(c *gin.Context) { router.POST("/exercices", func(c *gin.Context) {
theme := c.MustGet("theme").(*fic.Theme) theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadException(sync.GlobalImporter, theme) exceptions := sync.LoadThemeException(sync.GlobalImporter, theme)
c.JSON(http.StatusOK, flatifySyncErrors(sync.SyncExercices(sync.GlobalImporter, theme, exceptions))) c.JSON(http.StatusOK, flatifySyncErrors(sync.SyncExercices(sync.GlobalImporter, theme, exceptions)))
}) })
@ -148,11 +148,10 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
apiSyncExercicesRoutes.Use(ExerciceHandler) apiSyncExercicesRoutes.Use(ExerciceHandler)
apiSyncExercicesRoutes.POST("", func(c *gin.Context) { apiSyncExercicesRoutes.POST("", func(c *gin.Context) {
theme := c.MustGet("theme").(*fic.Theme) theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadException(sync.GlobalImporter, theme)
exercice := c.MustGet("exercice").(*fic.Exercice) exercice := c.MustGet("exercice").(*fic.Exercice)
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)) c.JSON(http.StatusOK, flatifySyncErrors(errs))
}) })
@ -160,7 +159,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
exercice := c.MustGet("exercice").(*fic.Exercice) exercice := c.MustGet("exercice").(*fic.Exercice)
theme := c.MustGet("theme").(*fic.Theme) theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadException(sync.GlobalImporter, theme) exceptions := sync.LoadExerciceException(sync.GlobalImporter, theme, exercice, nil)
c.JSON(http.StatusOK, sync.SyncExerciceFiles(sync.GlobalImporter, exercice, exceptions)) c.JSON(http.StatusOK, sync.SyncExerciceFiles(sync.GlobalImporter, exercice, exceptions))
}) })
@ -183,7 +182,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
exercice := c.MustGet("exercice").(*fic.Exercice) exercice := c.MustGet("exercice").(*fic.Exercice)
theme := c.MustGet("theme").(*fic.Theme) theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadException(sync.GlobalImporter, theme) exceptions := sync.LoadExerciceException(sync.GlobalImporter, theme, exercice, nil)
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions) _, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions)
c.JSON(http.StatusOK, flatifySyncErrors(errs)) c.JSON(http.StatusOK, flatifySyncErrors(errs))
@ -192,7 +191,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
exercice := c.MustGet("exercice").(*fic.Exercice) exercice := c.MustGet("exercice").(*fic.Exercice)
theme := c.MustGet("theme").(*fic.Theme) theme := c.MustGet("theme").(*fic.Theme)
exceptions := sync.LoadException(sync.GlobalImporter, theme) exceptions := sync.LoadExerciceException(sync.GlobalImporter, theme, exercice, nil)
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice, exceptions) _, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice, exceptions)
_, herrs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions) _, herrs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions)
c.JSON(http.StatusOK, flatifySyncErrors(append(errs, herrs...))) c.JSON(http.StatusOK, flatifySyncErrors(append(errs, herrs...)))
@ -283,7 +282,7 @@ func autoSync(c *gin.Context) {
} }
} }
exceptions := sync.LoadException(sync.GlobalImporter, theTheme) exceptions := sync.LoadThemeException(sync.GlobalImporter, theTheme)
var st []string var st []string
for _, se := range sync.SyncThemeDeep(sync.GlobalImporter, theTheme, 0, 250, exceptions) { for _, se := range sync.SyncThemeDeep(sync.GlobalImporter, theTheme, 0, 250, exceptions) {

View File

@ -87,7 +87,7 @@ func (c *CheckExceptions) HasException(ref string) bool {
return false return false
} }
func LoadException(i Importer, th *fic.Theme) (exceptions *CheckExceptions) { func LoadThemeException(i Importer, th *fic.Theme) (exceptions *CheckExceptions) {
if fexcept, err := GetFileContent(i, filepath.Join(th.Path, "repochecker-ack.txt")); err == nil { if fexcept, err := GetFileContent(i, filepath.Join(th.Path, "repochecker-ack.txt")); err == nil {
exceptions = &CheckExceptions{} exceptions = &CheckExceptions{}
for n, line := range strings.Split(fexcept, "\n") { for n, line := range strings.Split(fexcept, "\n") {
@ -97,3 +97,19 @@ func LoadException(i Importer, th *fic.Theme) (exceptions *CheckExceptions) {
return return
} }
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 {
for n, line := range strings.Split(fexcept, "\n") {
(*exceptions)[strings.TrimSpace(line)] = fmt.Sprintf("repochecker-ack.txt:%d", n+1)
}
}
return
}

View File

@ -105,8 +105,8 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
return nil, p, eid, edir, errs return nil, p, eid, edir, errs
} }
// Limit exceptions to this exercice // Get exceptions
exceptions = exceptions.GetExerciceExceptions(e) exceptions = LoadExerciceException(i, theme, e, exceptions)
//log.Printf("Kept repochecker exceptions for this exercice: %v", exceptions) //log.Printf("Kept repochecker exceptions for this exercice: %v", exceptions)
e.Language = theme.Language e.Language = theme.Language

View File

@ -110,7 +110,7 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExcept
th.Path = tdir th.Path = tdir
// Get exceptions // Get exceptions
exceptions = LoadException(i, th) exceptions = LoadThemeException(i, th)
// Overwrite language // Overwrite language
if language, err := GetFileContent(i, path.Join(tdir, "language.txt")); err == nil { if language, err := GetFileContent(i, path.Join(tdir, "language.txt")); err == nil {