admin/sync: theme's name is now part of the theme's dirname
This commit is contained in:
parent
cb02fa98dd
commit
9ab5738cff
5 changed files with 37 additions and 24 deletions
|
|
@ -13,11 +13,13 @@ import (
|
|||
func getExercices(i Importer, theme fic.Theme) ([]string, error) {
|
||||
var exercices []string
|
||||
|
||||
if dirs, err := i.listDir(theme.Name); err != nil {
|
||||
if len(theme.Path) == 0 {
|
||||
return []string{}, nil
|
||||
} else if dirs, err := i.listDir(theme.Path); err != nil {
|
||||
return []string{}, err
|
||||
} else {
|
||||
for _, dir := range dirs {
|
||||
if _, err := i.listDir(path.Join(theme.Name, dir)); err == nil {
|
||||
if _, err := i.listDir(path.Join(theme.Path, dir)); err == nil {
|
||||
exercices = append(exercices, dir)
|
||||
}
|
||||
}
|
||||
|
|
@ -52,12 +54,12 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
emap[ename] = eid
|
||||
|
||||
// Overview and scenario
|
||||
overview, err := getFileContent(i, path.Join(theme.Name, edir, "overview.txt"))
|
||||
overview, err := getFileContent(i, path.Join(theme.Path, edir, "overview.txt"))
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: overview.txt: %s", edir, err))
|
||||
}
|
||||
|
||||
statement, err := getFileContent(i, path.Join(theme.Name, edir, "statement.txt"))
|
||||
statement, err := getFileContent(i, path.Join(theme.Path, edir, "statement.txt"))
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: statement.txt: %s", edir, err))
|
||||
continue
|
||||
|
|
@ -65,7 +67,7 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
|
||||
// Handle score gain
|
||||
var gain int64
|
||||
if p, err := parseExerciceParams(i, path.Join(theme.Name, edir)); err != nil {
|
||||
if p, err := parseExerciceParams(i, path.Join(theme.Path, edir)); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", edir, err))
|
||||
continue
|
||||
} else if p.Gain == 0 {
|
||||
|
|
@ -75,14 +77,14 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||
}
|
||||
|
||||
// Handle video
|
||||
videoURI := path.Join(theme.Name, edir, "resolution.mp4")
|
||||
videoURI := path.Join(theme.Path, 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 {
|
||||
if ex, err := theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Name, edir), statement, overview, nil, gain, videoURI); err != nil {
|
||||
if ex, err := theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Path, edir), statement, overview, nil, gain, videoURI); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error on exercice add: %s", edir, err))
|
||||
continue
|
||||
} else {
|
||||
|
|
|
|||
Reference in a new issue