// InsertBefore inserts at the end, when NextSibling is null. // compare http://stackoverflow.com/questions/4793604/how-to-do-insert-after-in-javascript-without-using-a-library func InsertAfter(insPnt, toInsert *html.Node) { if insPnt.Parent != nil { insPnt.Parent.InsertBefore(toInsert, insPnt.NextSibling) } else { log.Printf("\nInsertAfter - insPnt has no Parent\n") runtimepb.StackTrace(4) } }
func RemoveNode(n *html.Node) { par := n.Parent if par != nil { par.RemoveChild(n) } else { log.Printf("\nNode to remove has no Parent\n") runtimepb.StackTrace(4) } }
// // // Path is the directory, BName contains the base name. func (fs *dsFileSys) saveFileByPath(f *DsFile, name string) error { dir, bname := fs.SplitX(name) f.Dir = dir // bname was only submitted in the fileobject // correct previous if f.BName != "" && f.BName != bname { dir = dir + bname // re-append if !strings.HasSuffix(dir, sep) { dir += sep } bname = f.BName f.Dir = dir } f.BName = common.Filify(bname) // f.MModTime = time.Now() f.fSys = fs // // -------------now the datastore part------------------------- foDir, err := fs.dirByPath(dir) if err == datastore.ErrNoSuchEntity { return err } else if err != nil { aelog.Errorf(fs.Ctx(), "Error reading dir for file %v => %v", dir+bname, err) return err } suggKey := datastore.NewKey(fs.Ctx(), tfil, f.BName, 0, foDir.Key) f.Key = suggKey effKey, err := datastore.Put(fs.Ctx(), suggKey, f) if err != nil { aelog.Errorf(fs.Ctx(), "Error saving file %v => %v", dir+bname, err) return err } if !suggKey.Equal(effKey) { aelog.Errorf(fs.Ctx(), "file keys unequal %v - %v; %v %s", suggKey, effKey, f.Dir+f.BName, f.Data) runtimepb.StackTrace(6) } // f.MemCacheSet() return nil }
func Nd(ntype string, content ...string) *html.Node { nd0 := new(html.Node) if ntype == "text" { nd0.Type = html.TextNode if len(content) > 0 { nd0.Data = content[0] } } else { nd0.Type = html.ElementNode nd0.Data = ntype if len(content) > 0 { runtimepb.StackTrace(4) log.Printf("Element nodes can't have content") } } return nd0 }
// Some websites have url paths like // .../news/some--title/32168.html // .../news/other-title/82316.html // // We want to condense these to // .../news/some--title-32168.html // .../news/other-title-82316.html func condenseTrailingDir(uri string, n int) (ret string) { switch n { case 0: return uri case 1: return uri case 2: base1 := path.Base(uri) rdir1 := path.Dir(uri) // rightest Dir base2 := path.Base(rdir1) rdir2 := path.Dir(rdir1) ret = path.Join(rdir2, base2+"-"+base1) default: runtimepb.StackTrace(4) log.Fatalf("not implemented n > 2 (%v)", n) } return }
"github.com/pbberlin/tools/runtimepb" ) var spf func(format string, a ...interface{}) string = fmt.Sprintf // plain and unchanged var epf func(format string, a ...interface{}) error = fmt.Errorf var pfOld func(format string, a ...interface{}) (int, error) = fmt.Printf // no more, old style var pf = func(format string, a ...interface{}) (int, error) { // new - a wrapper s := spf(format, a...) if len(appStageLogs) == 0 || len(appStageLogs) < currStage-1 { fmt.Printf("Premature pf() or appStageLogs too small (%v,%v) %s\n", len(appStageLogs), currStage, s) runtimepb.StackTrace(3) ExitWithLogDump() } buf := appStageLogs[currStage] if strings.HasSuffix(buf, "\n\n") { buf = buf[0 : len(buf)-1] } if strings.HasPrefix(s, "sameline") && strings.HasSuffix(buf, "\n") { buf = buf[0 : len(buf)-1] s = s[len("sameline"):] } buf += s