1package paged23import (4 "context"56 "src.rest/cat/012/internal/fileio"7 "src.rest/cat/012/internal/sheet"8)910// Links are the workbook's linked sources as the host reads them: each11// one's file through abs (which resolves it from the workbook's folder),12// what they build kept in tempDir ("" for the system's).13func Links(w *sheet.Workbook, abs func(string) string, tempDir string) []Linked {14 var out []Linked15 for _, info := range w.Sources() {16 src := info.Source17 out = append(out, Linked{Name: info.Name, Spec: fileio.SourceSpec{18 Path: abs(src.Path), Format: src.Format, Table: src.Table, Query: src.Query, TempDir: tempDir,19 }})20 }21 return out22}2324// Apply tells the workbook what storing a job found: a source opened,25// or questions answered.26func Apply(w *sheet.Workbook, d Done) {27 if d.Opened != "" {28 w.SetSourceShape(d.Opened, d.Shape, d.Err)29 }30 if len(d.Keys) > 0 {31 w.RecalcSourced(d.Keys)32 }33}3435// Settle links the sources links names (Links), unless links is nil,36// and runs every job the host queues, one after another, applying each,37// until none is left: for what has no screen to keep live while they38// run (012 get, tests).39func (h *Host) Settle(ctx context.Context, w *sheet.Workbook, links []Linked) {40 if links != nil {41 h.Link(links)42 }43 w.SetSources(h)44 for jobs := h.Jobs(); len(jobs) > 0; jobs = h.Jobs() {45 for _, j := range jobs {46 j.Run(ctx)47 Apply(w, h.Store(j))48 }49 if ctx.Err() != nil {50 return51 }52 }53}