MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / BuildProblemPackage

Function BuildProblemPackage

client/packmgr/package.go:18–75  ·  view source on GitHub ↗

BuildProblemPackage 创建题目数据包

(c *cli.Context)

Source from the content-addressed store, hash-verified

16
17// BuildProblemPackage 创建题目数据包
18func 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}

Callers

nothing calls this directly

Calls 7

GetArmorPublicKeyFunction · 0.92
NewSessionFunction · 0.92
CheckRequireFilesExistsFunction · 0.92
PackProblemsAsZipFunction · 0.92
PackProblemsFunction · 0.92
ErrorfMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected