BuildProblemPackage 创建题目数据包
(c *cli.Context)
| 16 | |
| 17 | // BuildProblemPackage 创建题目数据包 |
| 18 | func BuildProblemPackage(c *cli.Context) error { |
| 19 | |
| 20 | if c.String("passphrase") != "" { |
| 21 | log.Println("[warn] Using a password on the command line interface can be insecure.") |
| 22 | } |
| 23 | passphrase := []byte(c.String("passphrase")) |
| 24 | configFile := c.Args().Get(0) |
| 25 | outputFile := c.Args().Get(1) |
| 26 | |
| 27 | if c.Bool("zip") && !strings.HasSuffix(configFile, "problem.json") { |
| 28 | return errors.Errorf("config file must named 'problem.json' in zip mode") |
| 29 | } |
| 30 | |
| 31 | var err error |
| 32 | var pem *persistence.DigitalSignPEM |
| 33 | |
| 34 | _, err = os.Stat(configFile) |
| 35 | if err != nil && os.IsNotExist(err) { |
| 36 | return errors.Errorf("problem config file (%s) not found", configFile) |
| 37 | } |
| 38 | |
| 39 | if c.Bool("sign") { |
| 40 | pem, err = persistence.GetArmorPublicKey(c.String("gpg-key"), passphrase) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | } |
| 45 | options := persistence.ProblemPackageOptions{} |
| 46 | options.ConfigFile = configFile |
| 47 | options.DigitalSign = c.Bool("sign") |
| 48 | options.DigitalPEM = pem |
| 49 | options.OutFile = outputFile |
| 50 | |
| 51 | // problem |
| 52 | session, err := executor.NewSession(configFile) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | options.ConfigDir = session.ConfigDir |
| 57 | |
| 58 | err = executor.CheckRequireFilesExists(&session.JudgeConfig, options.ConfigDir) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | if c.Bool("zip") { |
| 64 | err = problems.PackProblemsAsZip(&options) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | } else { |
| 69 | err = problems.PackProblems(&session.JudgeConfig, &options) |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | } |
| 74 | return nil |
| 75 | } |
nothing calls this directly
no test coverage detected