//Init initialize contest. func Init(dir string) { logger := Logger.WithField("state", "init_contest") logger.WithFields(logrus.Fields{ "type": "info", "info": "initialize contest start", }).Info("Initialize contest start") out := libra.CreateFile(filepath.Join(dir, "contest.toml"), logger) defer out.Close() logger.WithFields(logrus.Fields{ "type": "info", "info": "initialize contest end", }).Info("Initialize contest end") }
/* Save problem set to the directory. */ func Save(dir string, contest Contest) { logger := Logger.WithField("state", "save_contest") out := libra.CreateFile(filepath.Join(dir, "contest.toml"), logger) defer out.Close() encoder := toml.NewEncoder(out) err := encoder.Encode(contest) if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error()}).Panicf("Encode contest.toml Failed") } logger.WithFields(logrus.Fields{ "type": "info", "info": "save problem set end"}).Infof("Saved problems: %d", len(contest.Problems)) }
func tryGen(dir, path string, logger *logrus.Entry) (*os.File, error) { logger.WithFields(logrus.Fields{ "type": "info", "info": "try generate file"}).Infof("generation try: %s", path) _, err := os.Stat(filepath.Join(dir, path)) if err == nil { logger.WithFields(logrus.Fields{ "type": "info", "info": "try generate file"}).Warnf("%s found. generation passed.", path) return nil, err } libra.CreateDir(filepath.Dir(filepath.Join(dir, path)), logger) ret := libra.CreateFile(filepath.Join(dir, path), logger) logger.WithFields(logrus.Fields{ "type": "info", "info": "try generation end"}).Infof("generation end: %s", path) return ret, nil }
//Init initialize problem func Init(dir, name string) { if name == "" { name = filepath.Base(dir) } logger := Logger.WithField("state", "init_problem") logger.WithFields(logrus.Fields{ "type": "info", "info": "initialize problem start", }).Infof("initialize problem(%s) start", name) _, err := os.Stat(filepath.Join(dir, "problem.toml")) if err == nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error(), }).Fatal("\"problem.toml\" already exists") } //TODO generation with template problem := libra.Problem{ Answer: []libra.Answer{}, Checker: "", Generator: []libra.Generator{}, Name: name, Solution: "", Validator: "", TimeLimit: 2.0, } out := libra.CreateFile(filepath.Join(dir, "problem.toml"), logger) defer out.Close() encoder := toml.NewEncoder(out) err = encoder.Encode(problem) if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error()}).Panicf("Encode problem.toml Failed") } logger.WithFields(logrus.Fields{ "type": "info", "info": "initialize problem end"}).Infof("initialize problem(%s) end", name) }