From 651d4282238a8446d24be5c6ec290d1e4e729a8c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 16 May 2024 11:10:30 +0200 Subject: [PATCH] sync: Prefer challenge.toml over challenge.txt --- admin/get-remote-files/main.go | 4 ++-- admin/sync/errors.go | 8 ++++---- admin/sync/exceptions_test.go | 8 ++++---- admin/sync/exercice_hints.go | 4 ++-- admin/sync/exercice_keys.go | 4 ++-- admin/sync/exercices.go | 2 +- repochecker/main.go | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/admin/get-remote-files/main.go b/admin/get-remote-files/main.go index 1260f40c..85315c3f 100644 --- a/admin/get-remote-files/main.go +++ b/admin/get-remote-files/main.go @@ -73,7 +73,7 @@ func main() { func treatDir(p string) { var expath string - for _, f := range []string{"challenge.txt", "challenge.toml"} { + for _, f := range []string{"challenge.toml", "challenge.txt"} { if sync.GlobalImporter.Exists(path.Join(p, f)) { expath = p break @@ -108,7 +108,7 @@ func treatExercice(expath string) { paramsFiles, err := sync.GetExerciceFilesParams(sync.GlobalImporter, exercice) if err != nil { - log.Printf("Unable to read challenge.txt %q: %s", expath, err.Error()) + log.Printf("Unable to read challenge.toml %q: %s", expath, err.Error()) return } diff --git a/admin/sync/errors.go b/admin/sync/errors.go index 3da4ceb9..a422ffe1 100644 --- a/admin/sync/errors.go +++ b/admin/sync/errors.go @@ -106,9 +106,9 @@ func NewChallengeTxtError(exercice *fic.Exercice, line uint, err error, theme .. func (e *ChallengeTxtError) Error() string { if e.ChallengeTxtLine != 0 { - return fmt.Sprintf("%s:%d: %s", path.Join(e.ExercicePath, "challenge.txt"), e.ChallengeTxtLine, e.ThemeError.error.Error()) + return fmt.Sprintf("%s:%d: %s", path.Join(e.ExercicePath, "challenge.toml"), e.ChallengeTxtLine, e.ThemeError.error.Error()) } else { - return fmt.Sprintf("%s: %s", path.Join(e.ExercicePath, "challenge.txt"), e.ThemeError.error.Error()) + return fmt.Sprintf("%s: %s", path.Join(e.ExercicePath, "challenge.toml"), e.ThemeError.error.Error()) } } @@ -127,7 +127,7 @@ func NewHintError(exercice *fic.Exercice, hint *fic.EHint, line int, err error, } func (e *HintError) Error() string { - return fmt.Sprintf("%s: hint#%d (%s): %s", path.Join(e.ExercicePath, "challenge.txt"), e.HintId, e.HintTitle, e.ThemeError.error.Error()) + return fmt.Sprintf("%s: hint#%d (%s): %s", path.Join(e.ExercicePath, "challenge.toml"), e.HintId, e.HintTitle, e.ThemeError.error.Error()) } type FlagError struct { @@ -144,5 +144,5 @@ func NewFlagError(exercice *fic.Exercice, flag *ExerciceFlag, line int, err erro } func (e *FlagError) Error() string { - return fmt.Sprintf("%s: flag#%d: %s", path.Join(e.ExercicePath, "challenge.txt"), e.FlagId, e.ThemeError.error.Error()) + return fmt.Sprintf("%s: flag#%d: %s", path.Join(e.ExercicePath, "challenge.toml"), e.FlagId, e.ThemeError.error.Error()) } diff --git a/admin/sync/exceptions_test.go b/admin/sync/exceptions_test.go index cced1cc6..5d0c0a37 100644 --- a/admin/sync/exceptions_test.go +++ b/admin/sync/exceptions_test.go @@ -26,10 +26,10 @@ const sampleFile = `0-exercice-1/overview.md:spelling:Sterik 0-exercice-1/resolution.md:11:typo_guillemets_typographiques_doubles_fermants 0-exercice-1/resolution.md:spelling:cronjob 0-exercice-1/resolution.md:spelling:Level -challenge.txt:spelling:time -challenge.txt:spelling:ago +challenge.toml:spelling:time +challenge.toml:spelling:ago 0-exercice-1/resolution.md:spelling:SCL -challenge.txt:spelling:SCL` +challenge.toml:spelling:SCL` func TestLoadExceptions(t *testing.T) { exceptions := ParseExceptionString(sampleFile, nil) @@ -47,7 +47,7 @@ func TestFilterExceptions(t *testing.T) { t.Fatalf("Expected 1 exceptions, got %d", len(*filteredExceptions)) } - filteredExceptions = exceptions.GetFileExceptions("challenge.txt") + filteredExceptions = exceptions.GetFileExceptions("challenge.toml") if len(*filteredExceptions) != 3 { t.Fatalf("Expected 3 exceptions, got %d", len(*filteredExceptions)) } diff --git a/admin/sync/exercice_hints.go b/admin/sync/exercice_hints.go index 75b23c76..ccb8fc9d 100644 --- a/admin/sync/exercice_hints.go +++ b/admin/sync/exercice_hints.go @@ -121,7 +121,7 @@ func buildExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExc // CheckExerciceHints checks if all hints are corrects.. func CheckExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) ([]importHint, error) { - exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml") + exceptions = exceptions.GetFileExceptions("challenge.toml", "challenge.txt") hints, errs := buildExerciceHints(i, exercice, exceptions) @@ -139,7 +139,7 @@ func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int if _, err := exercice.WipeHints(); err != nil { errs = multierr.Append(errs, err) } else { - exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml") + exceptions = exceptions.GetFileExceptions("challenge.toml", "challenge.txt") hints, berrs := buildExerciceHints(i, exercice, exceptions) errs = multierr.Append(errs, berrs) diff --git a/admin/sync/exercice_keys.go b/admin/sync/exercice_keys.go index ceaa6ec7..889fba43 100644 --- a/admin/sync/exercice_keys.go +++ b/admin/sync/exercice_keys.go @@ -541,7 +541,7 @@ func buildExerciceFlags(i Importer, exercice *fic.Exercice, exceptions *CheckExc // CheckExerciceFlags checks if all flags for the given challenge are correct. func CheckExerciceFlags(i Importer, exercice *fic.Exercice, files []string, exceptions *CheckExceptions) (rf []fic.Flag, errs error) { - exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml") + exceptions = exceptions.GetFileExceptions("challenge.toml", "challenge.txt") flags, flagsids, berrs := buildExerciceFlags(i, exercice, exceptions) errs = multierr.Append(errs, berrs) @@ -634,7 +634,7 @@ func SyncExerciceFlags(i Importer, exercice *fic.Exercice, exceptions *CheckExce } else if _, err := exercice.WipeMCQs(); err != nil { errs = multierr.Append(errs, err) } else { - exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml") + exceptions = exceptions.GetFileExceptions("challenge.toml", "challenge.txt") flags, flagids, berrs := buildExerciceFlags(i, exercice, exceptions) errs = multierr.Append(errs, berrs) diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index a5d055b4..158e96ba 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -280,7 +280,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]* e.WIP = p.WIP if p.WIP && !AllowWIPExercice { - errs = multierr.Append(errs, NewExerciceError(e, fmt.Errorf("exercice declared Work In Progress in challenge.txt"), theme)) + errs = multierr.Append(errs, NewExerciceError(e, fmt.Errorf("exercice declared Work In Progress in challenge.toml"), theme)) } if p.Gain == 0 { diff --git a/repochecker/main.go b/repochecker/main.go index 499e185f..ff49aacb 100644 --- a/repochecker/main.go +++ b/repochecker/main.go @@ -248,7 +248,7 @@ func main() { nberr := 0 theme, exceptions, errs := sync.BuildTheme(sync.GlobalImporter, p) - if theme != nil && !sync.GlobalImporter.Exists(path.Join(p, "challenge.txt")) && !sync.GlobalImporter.Exists(path.Join(p, "challenge.toml")) { + if theme != nil && !sync.GlobalImporter.Exists(path.Join(p, "challenge.toml")) && !sync.GlobalImporter.Exists(path.Join(p, "challenge.txt")) { thiserrors := multierr.Errors(errs) nberr += len(thiserrors) for _, err := range thiserrors {