sync: handle new sync format: filenames and locations

This commit is contained in:
Thibaut 2018-05-12 02:01:49 +02:00 committed by Pierre-Olivier Mercier
parent 12cb4e95f4
commit d303ecfa38
4 changed files with 14 additions and 33 deletions

View file

@ -22,7 +22,7 @@ type ExerciceParams struct {
// parseExerciceParams reads challenge definitions from defines.txt and extract usefull data to set up the challenge.
func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, err error) {
var defs string
defs, err = getFileContent(i, path.Join(exPath, "defines.txt"))
defs, err = getFileContent(i, path.Join(exPath, "challenge.txt"))
_, err = toml.Decode(defs, &p)

View file

@ -19,7 +19,7 @@ import (
func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
params, err := parseExerciceParams(i, exercice.Path)
if err != nil {
errs = append(errs, fmt.Sprintf("%q: defines.txt: %s", path.Base(exercice.Path), err))
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", path.Base(exercice.Path), err))
}
if _, err := exercice.WipeHints(); err != nil {

View file

@ -26,24 +26,6 @@ func getExercices(i Importer, theme fic.Theme) ([]string, error) {
return exercices, nil
}
// findResolutionMovie searchs a resolution movie across a given exercice path.
func findResolutionMovie(i Importer, exPath string) (videoURI string, err error) {
var files []string
if files, err = i.listDir(path.Join(exPath, "resolution")); err != nil {
return
} else {
for _, fname := range files {
switch strings.ToLower(path.Ext(fname)) {
case ".mkv", ".mp4", ".webm", ".ogv", ".avi", ".mov", ".flv":
videoURI = path.Join("/resolution", exPath, "resolution", fname)
}
}
}
return
}
// SyncExercices imports new or updates existing exercices, in a given theme.
func SyncExercices(i Importer, theme fic.Theme) []string {
var errs []string
@ -70,34 +52,33 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
emap[ename] = eid
// Overview and scenario
overview, err := getFileContent(i, path.Join(theme.Name, edir, "introduction.txt"))
overview, err := getFileContent(i, path.Join(theme.Name, edir, "overview.txt"))
if err != nil {
errs = append(errs, fmt.Sprintf("%q: introduction.txt: %s", edir, err))
errs = append(errs, fmt.Sprintf("%q: overview.txt: %s", edir, err))
}
statement, err := getFileContent(i, path.Join(theme.Name, edir, "scenario.txt"))
statement, err := getFileContent(i, path.Join(theme.Name, edir, "statement.txt"))
if err != nil {
errs = append(errs, fmt.Sprintf("%q: scenario.txt: %s", edir, err))
errs = append(errs, fmt.Sprintf("%q: statement.txt: %s", edir, err))
continue
}
// Handle score gain
var gain int64
if p, err := parseExerciceParams(i, path.Join(theme.Name, edir)); err != nil {
errs = append(errs, fmt.Sprintf("%q: defines.txt: %s", edir, err))
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", edir, err))
continue
} else if p.Gain == 0 {
errs = append(errs, fmt.Sprintf("%q: defines.txt: Undefined gain for challenge", edir))
errs = append(errs, fmt.Sprintf("%q: challenge.txt: Undefined gain for challenge", edir))
} else {
gain = p.Gain
}
// Handle video
videoURI, err := findResolutionMovie(i, path.Join(theme.Name, edir))
if err != nil {
errs = append(errs, fmt.Sprintf("%q: resolution: %s", edir, err))
} else if len(videoURI) == 0 {
errs = append(errs, fmt.Sprintf("%q: resolution: no video file found.", edir))
videoURI := path.Join(theme.Name, edir, "resolution.mp4")
if !i.exists(videoURI) {
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: no video file found at %s", edir, videoURI))
videoURI = ""
}
if e, err := theme.GetExerciceByTitle(ename); err != nil {

View file

@ -50,8 +50,8 @@ func SyncThemes(i Importer) []string {
if authors, err = getAuthors(i, tname); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get AUTHORS: %s", tname, err))
continue
} else if intro, err = getFileContent(i, path.Join(tname, "introduction.txt")); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get introduction: %s", tname, err))
} else if intro, err = getFileContent(i, path.Join(tname, "overview.txt")); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get theme's overview: %s", tname, err))
} else if theme, err = fic.GetThemeByName(tname); err != nil {
if _, err := fic.CreateTheme(tname, fic.ToURLid(tname), strings.Join(authors, ", "), intro); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tname, err))