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
commit d303ecfa38
4 changed files with 14 additions and 33 deletions

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 {