1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
18 "git.arvados.org/arvados.git/sdk/go/arvados"
19 log "github.com/sirupsen/logrus"
24 func (cmd *dumpGob) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
28 fmt.Fprintf(stderr, "%s\n", err)
31 flags := flag.NewFlagSet("", flag.ContinueOnError)
32 flags.SetOutput(stderr)
33 pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
34 runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
35 projectUUID := flags.String("project", "", "project `UUID` for output data")
36 priority := flags.Int("priority", 500, "container request priority")
37 inputFilename := flags.String("i", "-", "input `file` (library)")
38 outputFilename := flags.String("o", "-", "output `file`")
39 err = flags.Parse(args)
40 if err == flag.ErrHelp {
43 } else if err != nil {
45 } else if flags.NArg() > 0 {
46 err = fmt.Errorf("errant command line arguments after parsed flags: %v", flags.Args())
52 log.Println(http.ListenAndServe(*pprof, nil))
57 if *outputFilename != "-" {
58 err = errors.New("cannot specify output file in container mode: not implemented")
61 runner := arvadosContainerRunner{
62 Name: "lightning dumpgob",
63 Client: arvados.NewClientFromEnv(),
64 ProjectUUID: *projectUUID,
69 err = runner.TranslatePaths(inputFilename)
73 runner.Args = []string{"dumpgob", "-local=true", fmt.Sprintf("-pprof=%v", *pprof), "-i", *inputFilename, "-o", "/mnt/output/dumpgob.txt"}
75 output, err = runner.Run()
79 fmt.Fprintln(stdout, output+"/dumpgob.txt")
83 input, err := open(*inputFilename)
88 output, err := os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0644)
93 bufw := bufio.NewWriterSize(output, 8*1024*1024)
95 var n, nCG, nCS, nTV int
96 err = DecodeLibrary(input, strings.HasSuffix(*inputFilename, ".gz"), func(ent *LibraryEntry) error {
98 fmt.Fprintf(stderr, "ent %d\n", n)
101 if len(ent.TagSet) > 0 {
102 fmt.Fprintf(bufw, "ent %d: TagSet, len %d, taglen %d\n", n, len(ent.TagSet), len(ent.TagSet[0]))
104 for _, cg := range ent.CompactGenomes {
106 fmt.Fprintf(bufw, "ent %d: CompactGenome, name %q, len(Variants) %d\n", n, cg.Name, len(cg.Variants))
108 for _, cs := range ent.CompactSequences {
110 fmt.Fprintf(bufw, "ent %d: CompactSequence, name %q, len(TileSequences) %d\n", n, cs.Name, len(cs.TileSequences))
112 for _, tv := range ent.TileVariants {
114 fmt.Fprintf(bufw, "ent %d: TileVariant, tag %d, variant %d, hash %x, len(seq) %d\n", n, tv.Tag, tv.Variant, tv.Blake2b, len(tv.Sequence))
121 fmt.Fprintf(bufw, "total: ents %d, CompactGenomes %d, CompactSequences %d, TileVariants %d\n", n, nCG, nCS, nTV)