Esempio n. 1
0
//Add add problem to problem set.
func Add(dir, name string) {
	contest := Load(dir)
	logger := Logger.WithField("state", "add_problem")
	if name == "" {
		logger.WithFields(logrus.Fields{
			"type":  "error",
			"error": libra.IE.String(),
			"info":  "problem name must be no-empty string",
		}).Fatal("Empty string is not allowed")
	}
	logger.WithFields(logrus.Fields{
		"type": "info",
		"info": "add problem start",
	}).Infof("add problem(%s) start", name)
	for _, v := range contest.Problems {
		if v.Name == name {
			logger.WithFields(logrus.Fields{
				"type":  "error",
				"error": libra.IE.String(),
				"info":  "problem already exists",
			}).Fatalf("Problem '%s' already exists", name)
		}
	}
	_, err := os.Stat(filepath.Join(dir, name, "problem.toml"))
	if err != nil {
		libra.CreateDir(filepath.Join(dir, name), logger)
		initialize(filepath.Join(dir, name), name)
	}
	contest.Problems = append(contest.Problems, Problem{Name: name})
	Save(dir, contest)
	logger.WithFields(logrus.Fields{
		"type": "info",
		"info": "add problem end",
	}).Infof("add problem(%s) end", name)
}
Esempio n. 2
0
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
}