func TestLOC(t *testing.T) { var dump, dumpmagic bool // set to true to print out LOC sigs config.SetHome(filepath.Join("..", "..", "cmd", "roy", "data")) config.SetLOC("")() l, err := newLOC(config.LOC()) if l != nil { if dump { fdd := l.(fdds) for _, v := range fdd.f { fmt.Println(v) fmt.Println("****************") } } else if dumpmagic { fdd := l.(fdds) for _, v := range fdd.f { if len(v.Magics) > 0 { fmt.Println("{") for _, m := range v.Magics { fmt.Println("`" + m + "`,") } fmt.Println("},") } } } if _, _, err = l.Signatures(); err != nil { t.Fatal(err) } } else { t.Fatalf("Expecting a LOC, got nothing! Error: %v", err) } }
func inspectFmt(f string) error { var id core.Identifier var err error fs := expandSets(f) if len(fs) == 0 { return fmt.Errorf("no valid fmt to inspect in %s", f) } opts := append(getOptions(), config.SetDoubleUp()) // speed up by allowing sig double ups if *inspectMI != "" { id, err = mimeinfo.New(opts...) } else if strings.HasPrefix(fs[0], "fdd") || *inspectLOC || (*inspectFDD != "") { if *inspectFDD == "" && !*inspectLOC { opts = append(opts, config.SetLOC("")) } id, err = loc.New(opts...) } else { if !*inspectReports { opts = append(opts, config.SetNoReports()) // speed up by building from droid xml } id, err = pronom.New(opts...) } if err != nil { return err } fmt.Println(id.Inspect(fs...)) return nil }
func TestMakePronomTika(t *testing.T) { s := siegfried.New() config.SetHome(*testhome) p, err := pronom.New() if err != nil { t.Fatal(err) } err = s.Add(p) if err != nil { t.Fatal(err) } m, err := mimeinfo.New(config.SetName("tika"), config.SetMIMEInfo("tika")) if err != nil { t.Fatal(err) } err = s.Add(m) if err != nil { t.Fatal(err) } l, err := loc.New(config.SetName("loc"), config.SetLOC("")) if err != nil { t.Fatal(err) } err = s.Add(l) if err != nil { t.Fatal(err) } sigs := filepath.Join("data", "pronom-tika-loc.sig") err = s.Save(sigs) if err != nil { t.Fatal(err) } }
func getOptions() []config.Option { if *home != config.Home() { config.SetHome(*home) } if *inspectHome != config.Home() { config.SetHome(*inspectHome) } opts := []config.Option{} // build options if *droid != config.Droid() { opts = append(opts, config.SetDroid(*droid)) } if *container != config.Container() { opts = append(opts, config.SetContainer(*container)) } if *mi != "" { opts = append(opts, config.SetMIMEInfo(*mi)) } if *fdd != "" { opts = append(opts, config.SetLOC(*fdd)) } if *locfdd { opts = append(opts, config.SetLOC("")) } if *nopronom { opts = append(opts, config.SetNoPRONOM()) } if *name != "" { opts = append(opts, config.SetName(*name)) } if *details != config.Details() { opts = append(opts, config.SetDetails(*details)) } if *extend != "" { opts = append(opts, config.SetExtend(expandSets(*extend))) } if *extendc != "" { if *extend == "" { fmt.Println( `roy: warning! Unless the container extension only extends formats defined in the DROID signature file you should also include a regular signature extension (-extend) that includes a FileFormatCollection element describing the new formats.`) } opts = append(opts, config.SetExtendC(expandSets(*extendc))) } if *include != "" { opts = append(opts, config.SetLimit(expandSets(*include))) } if *exclude != "" { opts = append(opts, config.SetExclude(expandSets(*exclude))) } if *bof != 0 { opts = append(opts, config.SetBOF(*bof)) } if *eof != 0 { opts = append(opts, config.SetEOF(*eof)) } if *noeof { opts = append(opts, config.SetNoEOF()) } if *multi != "" { opts = append(opts, config.SetMulti(strings.ToLower(*multi))) } if *nocontainer { opts = append(opts, config.SetNoContainer()) } if *notext { opts = append(opts, config.SetNoText()) } if *noname { opts = append(opts, config.SetNoName()) } if *nomime { opts = append(opts, config.SetNoMIME()) } if *noxml { opts = append(opts, config.SetNoXML()) } if *noriff { opts = append(opts, config.SetNoRIFF()) } if *noreports { opts = append(opts, config.SetNoReports()) } if *doubleup { opts = append(opts, config.SetDoubleUp()) } if *rng != config.Range() { opts = append(opts, config.SetRange(*rng)) } if *distance != config.Distance() { opts = append(opts, config.SetDistance(*distance)) } if *choices != config.Choices() { opts = append(opts, config.SetChoices(*choices)) } // inspect options if *inspectMI != "" { opts = append(opts, config.SetMIMEInfo(*inspectMI)) } if *inspectFDD != "" { opts = append(opts, config.SetLOC(*fdd)) } if *inspectLOC { opts = append(opts, config.SetLOC("")) } if *inspectInclude != "" { opts = append(opts, config.SetLimit(expandSets(*inspectInclude))) } if *inspectExclude != "" { opts = append(opts, config.SetExclude(expandSets(*inspectExclude))) } if *inspectExtend != "" { opts = append(opts, config.SetExtend(expandSets(*inspectExtend))) } if *inspectExtendc != "" { if *inspectExtend == "" { fmt.Println( `roy: warning! Unless the container extension only extends formats defined in the DROID signature file you should also include a regular signature extension (-extend) that includes a FileFormatCollection element describing the new formats.`) } opts = append(opts, config.SetExtendC(expandSets(*inspectExtendc))) } return opts }