Settings are now given through TEAMS/settings.json instead of been given through command line arguments
This commit is contained in:
parent
37310e41f5
commit
10fe40e4a8
9 changed files with 209 additions and 69 deletions
|
@ -11,8 +11,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"gopkg.in/fsnotify.v1"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
"srs.epita.fr/fic-server/settings"
|
||||
|
||||
"gopkg.in/fsnotify.v1"
|
||||
)
|
||||
|
||||
var TeamsDir string
|
||||
|
@ -41,19 +43,31 @@ func watchsubdir(watcher *fsnotify.Watcher, pathname string) error {
|
|||
}
|
||||
}
|
||||
|
||||
func reloadSettings(config settings.FICSettings) {
|
||||
fic.PartialValidation = config.PartialValidation
|
||||
fic.UnlockedChallenges = !config.EnableExerciceDepend
|
||||
|
||||
fic.FirstBlood = config.FirstBlood
|
||||
fic.SubmissionCostBase = config.SubmissionCostBase
|
||||
|
||||
log.Println("Generating files...")
|
||||
go func() {
|
||||
genAll()
|
||||
log.Println("Full generation done")
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
var dsn = flag.String("dsn", "fic:fic@/fic", "DSN to connect to the MySQL server")
|
||||
flag.StringVar(&SubmissionDir, "submission", "./submissions", "Base directory where save submissions")
|
||||
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
|
||||
flag.StringVar(&TeamsDir, "teams", "./TEAMS", "Base directory where save teams JSON files")
|
||||
flag.StringVar(&fic.FilesDir, "files", "/files", "Request path prefix to reach files")
|
||||
var skipFullGeneration = flag.Bool("skipFullGeneration", false, "Skip initial full generation (safe to skip after start)")
|
||||
flag.BoolVar(&fic.PartialValidation, "partialValidation", false, "Validates flags which are corrects, don't be binary")
|
||||
flag.BoolVar(&fic.UnlockedChallenges, "unlockedChallenges", false, "Make all challenges accessible without having to validate previous level")
|
||||
flag.Parse()
|
||||
|
||||
log.SetPrefix("[backend] ")
|
||||
|
||||
SubmissionDir = path.Clean(SubmissionDir)
|
||||
TeamsDir = path.Clean(TeamsDir)
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
|
@ -70,6 +84,9 @@ func main() {
|
|||
}
|
||||
defer fic.DBClose()
|
||||
|
||||
// Load configuration
|
||||
settings.LoadAndWatchSettings(path.Join(TeamsDir, settings.SettingsFile), reloadSettings)
|
||||
|
||||
log.Println("Registering directory events...")
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
|
@ -81,14 +98,6 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !*skipFullGeneration {
|
||||
log.Println("Generating files...")
|
||||
go func() {
|
||||
genAll()
|
||||
log.Println("Full generation done")
|
||||
}()
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case ev := <-watcher.Events:
|
||||
|
|
Reference in a new issue