コード例 #1
0
ファイル: importer.go プロジェクト: contester/runlib
func mkdirAndCopy(backend storage.ProblemStore, dir, name, gridname string) error {
	if err := os.MkdirAll(dir, os.ModePerm); err != nil {
		return err
	}
	if _, err := backend.Copy(filepath.Join(dir, name),
		gridname, false, "", "", *authToken); err != nil {
		return err
	}
	return nil
}
コード例 #2
0
ファイル: importer.go プロジェクト: contester/runlib
func exportProblem(backend storage.ProblemStore, manifest storage.ProblemManifest, dest string) error {
	if err := os.MkdirAll(dest, os.ModePerm); err != nil {
		return err
	}
	gridprefix := manifest.GetGridPrefix()
	if manifest.TesterName != "" {
		if err := os.MkdirAll(filepath.Join(dest, "Tester"), os.ModePerm); err != nil {
			return err
		}
		if _, err := backend.Copy(filepath.Join(dest, "Tester", manifest.TesterName), gridprefix+"checker", false, "", "", *authToken); err != nil {
			return err
		}
	}
	if err := ioutil.WriteFile(filepath.Join(dest, "memlimit"), []byte(fmt.Sprintf("%d", manifest.MemoryLimit)), os.ModePerm); err != nil {
		return err
	}
	if err := ioutil.WriteFile(filepath.Join(dest, "timex"), []byte(fmt.Sprintf("%f", float64(manifest.TimeLimitMicros)/1000000)), os.ModePerm); err != nil {
		return err
	}

	answers := make(map[int]struct{})
	for _, v := range manifest.Answers {
		answers[v] = struct{}{}
	}

	for i := 1; i <= manifest.TestCount; i++ {
		if i > 1 {
			fmt.Printf(" ")
		}
		fmt.Printf("%d", i)
		os.Stdout.Sync()
		test := filepath.Join(dest, fmt.Sprintf("Test.%d", i))
		if err := mkdirAndCopy(backend, filepath.Join(test, "Input"),
			"input.txt", gridprefix+fmt.Sprintf("tests/%d/input.txt", i)); err != nil {
			return err
		}
		if _, ok := answers[i]; !ok {
			continue
		}
		if err := mkdirAndCopy(backend, filepath.Join(test, "Add-ons"),
			"answer.txt", gridprefix+fmt.Sprintf("tests/%d/answer.txt", i)); err != nil {
			return err
		}
	}
	return nil
}