func main() { flag.Parse() if *servingTable == "" { flagutil.UsageError("missing --serving_table") } else if *outPath == "" { flagutil.UsageError("missing --out") } ctx := context.Background() db, err := leveldb.Open(*servingTable, nil) if err != nil { log.Fatalf("Error opening db at %q: %v", *servingTable, err) } defer db.Close() tbl := &table.KVProto{db} esr := &esrchsrv.Table{&table.KVInverted{db}} ix := index.Create(*outPath) for _, ticket := range filesInTable(ctx, esr) { var fd srvpb.FileDecorations if err := tbl.Lookup(ctx, xsrv.DecorationsKey(ticket), &fd); err != nil { log.Fatalf("Error looking up decoration for %q: %v", ticket, err) } ix.Add(ticket, bytes.NewReader(fd.SourceText)) } ix.Flush() }
func writeDecor(ctx context.Context, t table.BufferedProto, decor *srvpb.FileDecorations, targets map[string]*srvpb.Node) error { for _, n := range targets { decor.Target = append(decor.Target, n) } sort.Sort(assemble.ByOffset(decor.Decoration)) sort.Sort(assemble.ByTicket(decor.Target)) sort.Sort(assemble.ByAnchorTicket(decor.TargetDefinitions)) return t.Put(ctx, xsrv.DecorationsKey(decor.File.Ticket), decor) }
func writeDecorations(ctx context.Context, t table.Proto, es xrefs.NodesEdgesService, files []string) error { log.Println("Writing Decorations") edges := make(chan *xpb.EdgesReply) var eErr error go func() { eErr = readEdges(ctx, es, files, edges, decorationFilters, []string{revChildOfEdgeKind}) close(edges) }() for e := range edges { decor := &srvpb.FileDecorations{} if len(e.EdgeSet) == 0 { if len(e.Node) != 1 { log.Println("ERROR: missing node for non-decoration file") continue } decor.FileTicket = e.Node[0].Ticket } else if len(e.EdgeSet) != 1 { log.Println("ERROR: invalid number of decoration EdgeSets:", len(e.EdgeSet)) continue } else { decor.FileTicket = e.EdgeSet[0].SourceTicket } for _, n := range e.Node { if n.Ticket == decor.FileTicket { for _, f := range n.Fact { switch f.Name { case schema.TextFact: decor.SourceText = f.Value case schema.TextEncodingFact: decor.Encoding = string(f.Value) } } } else { ds, err := getDecorations(ctx, es, n) if err != nil { return err } decor.Decoration = append(decor.Decoration, ds...) } } sort.Sort(byOffset(decor.Decoration)) if err := t.Put(xsrv.DecorationsKey(decor.FileTicket), decor); err != nil { return err } } return eErr }
func writeDecor(ctx context.Context, t table.BufferedProto, decor *srvpb.FileDecorations) error { sort.Sort(assemble.ByOffset(decor.Decoration)) return t.Put(ctx, xsrv.DecorationsKey(decor.File.Ticket), decor) }