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 {
|
||||
|
|
|
|||
|
|
@ -42,19 +42,27 @@ func SyncThemes(i Importer) []string {
|
|||
if themes, err := getThemes(i); err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
} else {
|
||||
for _, tname := range themes {
|
||||
for _, tdir := range themes {
|
||||
var authors []string
|
||||
var intro string
|
||||
var theme fic.Theme
|
||||
var tname string
|
||||
|
||||
if authors, err = getAuthors(i, tname); err != nil {
|
||||
// Extract theme's label
|
||||
if f := strings.Index(tdir, "-"); f >= 0 {
|
||||
tname = tdir[f+1:]
|
||||
} else {
|
||||
tname = tdir
|
||||
}
|
||||
|
||||
if authors, err = getAuthors(i, tdir); 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, "overview.txt")); err != nil {
|
||||
} else if intro, err = getFileContent(i, path.Join(tdir, "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))
|
||||
if _, err := fic.CreateTheme(tname, fic.ToURLid(tname), tdir, strings.Join(authors, ", "), intro); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tdir, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -65,8 +73,9 @@ func SyncThemes(i Importer) []string {
|
|||
theme.Name = tname
|
||||
theme.Authors = authors_str
|
||||
theme.Intro = intro
|
||||
theme.Path = tdir
|
||||
if _, err := theme.Update(); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: an error occurs during update: %s", tname, err))
|
||||
errs = append(errs, fmt.Sprintf("%q: an error occurs during update: %s", tdir, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue