Exemplo n.º 1
0
// Pronom creates a pronom object
func newPronom() (*pronom, error) {
	p := &pronom{}
	// apply no container rule
	if !config.NoContainer() && !config.Inspect() {
		if err := p.setContainers(); err != nil {
			return nil, fmt.Errorf("Pronom: error loading containers; got %s\nUnless you have set `-nocontainer` you need to download a container signature file", err)
		}
	}
	if err := p.setParseables(); err != nil {
		return nil, err
	}
	if config.Inspect() {
		return p, nil
	}
	// apply noPriority rule
	if !config.NoPriority() {
		p.pm = p.j.Priorities()
		p.pm.Complete()
	}
	return p, nil
}
Exemplo n.º 2
0
// set parseables joins signatures in the DROID signature file with any extra reports and adds that to the pronom object
func (p *pronom) setParseables() error {
	d, err := newDroid(config.Droid())
	if err != nil {
		return fmt.Errorf("Pronom: error loading Droid file; got %s\nYou must have a Droid file to build a signature", err)
	}
	// if we are just inspecting a single report file
	if config.Inspect() {
		r, err := newReports(config.Limit(d.IDs()), nil)
		if err != nil {
			return fmt.Errorf("Pronom: error loading reports; got %s\nYou must download PRONOM reports to build a signature (unless you use the -noreports flag). You can use `roy harvest` to download reports", err)
		}
		is := infos(r.Infos())
		sigs, puids, err := r.Signatures()
		if err != nil {
			return fmt.Errorf("Pronom: parsing signatures; got %s", err)
		}
		var puid string
		for i, sig := range sigs {
			if puids[i] != puid {
				puid = puids[i]
				fmt.Printf("%s: \n", is[puid].name)
			}
			fmt.Println(sig)
		}
		p.j = r
		return nil
	}
	// apply limit or exclude filters (only one can be applied)
	puids := d.IDs()
	if config.HasLimit() {
		puids = config.Limit(puids)
	} else if config.HasExclude() {
		puids = config.Exclude(puids)
	}
	// if noreports set
	if config.Reports() == "" {
		p.j = d
		// apply filter
		if config.HasLimit() || config.HasExclude() {
			p.j = parseable.Filter(puids, p.j)
		}
	} else { // otherwise build from reports
		r, err := newReports(puids, d.idsPuids())
		if err != nil {
			return fmt.Errorf("Pronom: error loading reports; got %s\nYou must download PRONOM reports to build a signature (unless you use the -noreports flag). You can use `roy harvest` to download reports", err)
		}
		p.j = r
	}
	// exclude byte signatures where also have container signatures, unless doubleup set
	if !config.DoubleUp() {
		p.j = &doublesFilter{
			config.ExcludeDoubles(puids, p.c.Puids()),
			p.j,
		}
	}
	// add extensions
	for _, v := range config.Extend() {
		e, err := newDroid(v)
		if err != nil {
			return fmt.Errorf("Pronom: error loading extension file; got %s", err)
		}
		p.j = parseable.Join(p.j, e)
	}
	// mirror PREV wild segments into EOF if maxBof and maxEOF set
	if config.MaxBOF() > 0 && config.MaxEOF() > 0 {
		p.j = &parseable.Mirror{p.j}
	}
	return nil
}