-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vydra polygon package upload (#34)
* feat: add vydra polygon package upload * chore: minor * chore: resources * chore: executables * chore: statement sections * ci: linter * chore: time-limit-exceeded-or-accepted * chore: errors channel; non fatal * feat: support tags; validator; checker * feat: update problem info * feat: upload tests; natstream internal * feat: validator tests upload * feat: checker tests * docs: vydra logo + directory flag * fix: stdin/stdout; empty tags * fix: skip dumb generated tests * feat: points & groups; decompose Upload * chore: deps better logging * docs: minor * fix: no empty script * chore: remove random mac build * fix: multitest generator (gen > {3-100}) * docs: known issues block * docs: minor * fix: multitest generator * docs: minor
- Loading branch information
Showing
12 changed files
with
1,021 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/Gornak40/algolymp/config" | ||
"github.com/Gornak40/algolymp/polygon" | ||
"github.com/Gornak40/algolymp/polygon/vydra" | ||
"github.com/akamensky/argparse" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
parser := argparse.NewParser("vydra", "Upload package to Polygon.") | ||
pID := parser.Int("i", "pid", &argparse.Options{ | ||
Required: true, | ||
Help: "Polygon problem ID", | ||
}) | ||
pDir := parser.String("p", "prob-dir", &argparse.Options{ | ||
Required: false, | ||
Default: ".", | ||
Help: "Problem directory (with problem.xml)", | ||
}) | ||
|
||
if err := parser.Parse(os.Args); err != nil { | ||
logrus.WithError(err).Fatal("bad arguments") | ||
} | ||
if err := os.Chdir(*pDir); err != nil { | ||
logrus.WithError(err).Fatal("bad problem directory") | ||
} | ||
|
||
cfg := config.NewConfig() | ||
pClient := polygon.NewPolygon(&cfg.Polygon) | ||
|
||
vyd := vydra.NewVydra(pClient, *pID) | ||
errs := make(chan error) | ||
go func() { | ||
for err := range errs { | ||
if err != nil { | ||
logrus.WithError(err).Error("vydra error") | ||
} | ||
} | ||
}() | ||
if err := vyd.Upload(errs); err != nil { | ||
logrus.WithError(err).Fatal("upload failed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package natstream | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/facette/natsort" | ||
) | ||
|
||
var ( | ||
ErrEndStream = errors.New("no more files in natstream") | ||
) | ||
|
||
type NatStream struct { | ||
files []string | ||
idx int | ||
} | ||
|
||
func (ns *NatStream) Init(glob string) error { | ||
files, err := filepath.Glob(glob) | ||
if err != nil { | ||
return err | ||
} | ||
ns.files = files | ||
natsort.Sort(ns.files) | ||
ns.idx = 0 | ||
|
||
return nil | ||
} | ||
|
||
func (ns *NatStream) Next() (string, error) { | ||
if ns.idx == len(ns.files) { | ||
return "", ErrEndStream | ||
} | ||
data, err := os.ReadFile(ns.files[ns.idx]) | ||
if err != nil { | ||
return "", err | ||
} | ||
ns.idx++ | ||
|
||
return string(data), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.