示例#1
0
文件: tx.set.go 项目: js-arias/jdh
func txSetRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	var tax *jdh.Taxon
	if len(idFlag) > 0 {
		tax = taxon(c, localDB, idFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if (len(args) > 0) && (strings.Index(args[0], "=") < 0) {
		name := args[0]
		pName := ""
		args = args[1:]
		if (len(args) > 0) && (strings.Index(args[0], "=") < 0) {
			pName = args[0]
			args = args[1:]

		}
		tax = pickTaxName(c, localDB, name, pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong taxon name or id"))
		c.Usage()
	}
	vals := valsFromArgs(tax.Id, args)
	localDB.Exec(jdh.Set, jdh.Taxonomy, vals)
	localDB.Exec(jdh.Commit, "", nil)
}
示例#2
0
文件: ra.ls.go 项目: js-arias/jdh
func raLsRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	var tax *jdh.Taxon
	if len(taxonFlag) > 0 {
		tax = taxon(c, localDB, taxonFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, localDB, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong taxon name or id"))
		c.Usage()
	}
	vals := new(jdh.Values)
	if childFlag {
		vals.Add(jdh.RDisTaxonParent, tax.Id)
	} else {
		vals.Add(jdh.RDisTaxon, tax.Id)
	}
	l := rasList(c, localDB, vals)
	defer l.Close()
	ct := tax
	for {
		ras := &jdh.Raster{}
		if err := l.Scan(ras); err != nil {
			if err == io.EOF {
				break
			}
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
			os.Exit(1)
		}
		if machineFlag {
			fmt.Fprintf(os.Stdout, "%s\n", ras.Id)
			continue
		}
		if ras.Taxon != ct.Id {
			ct = taxon(c, localDB, ras.Taxon)
		}
		if verboseFlag {
			fmt.Fprintf(os.Stdout, "%s %s %s\t%s\t%dx%d\n", ct.Id, ct.Name, ct.Authority, ras.Id, ras.Cols, ras.Cols/2)
			continue
		}
		fmt.Fprintf(os.Stdout, "%s\t%s\t%dx%d\n", ct.Name, ras.Id, ras.Cols, ras.Cols/2)
	}
}
示例#3
0
文件: ds.set.go 项目: js-arias/jdh
func dsSetRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong dataset id"))
		c.Usage()
	}
	openLocal(c)
	set := dataset(c, localDB, idFlag)
	if len(set.Id) == 0 {
		return
	}
	vals := valsFromArgs(set.Id, args)
	localDB.Exec(jdh.Set, jdh.Datasets, vals)
	localDB.Exec(jdh.Commit, "", nil)
}
示例#4
0
文件: ra.set.go 项目: js-arias/jdh
func raSetRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong specimen id"))
		c.Usage()
	}
	openLocal(c)
	ras := raster(c, localDB, idFlag)
	if len(ras.Id) == 0 {
		return
	}
	vals := valsFromArgs(ras.Id, args)
	localDB.Exec(jdh.Set, jdh.RasDistros, vals)
	localDB.Exec(jdh.Commit, "", nil)
}
示例#5
0
文件: ds.del.go 项目: js-arias/jdh
func dsDelRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong dataset id"))
		c.Usage()
	}
	openLocal(c)
	vals := new(jdh.Values)
	vals.Add(jdh.KeyId, idFlag)
	if _, err := localDB.Exec(jdh.Delete, jdh.Datasets, vals); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
		os.Exit(1)
	}
	localDB.Exec(jdh.Commit, "", nil)
}
示例#6
0
文件: tr.set.go 项目: js-arias/jdh
func trSetRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	if len(nodeFlag) > 0 {
		trSetNode(c, args)
		return
	}
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong tree or node id"))
		c.Usage()
	}
	phy := phylogeny(c, localDB, idFlag)
	if len(phy.Id) == 0 {
		return
	}
	vals := valsFromArgs(phy.Id, args)
	localDB.Exec(jdh.Set, jdh.Trees, vals)
	localDB.Exec(jdh.Commit, "", nil)
}
示例#7
0
文件: tr.del.go 项目: js-arias/jdh
func trDelRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	if len(nodeFlag) > 0 {
		trDelNode(c)
		return
	}
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong tree or node id"))
		c.Usage()
	}
	vals := new(jdh.Values)
	vals.Add(jdh.KeyId, idFlag)
	if _, err := localDB.Exec(jdh.Delete, jdh.Trees, vals); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
		os.Exit(1)
	}
	localDB.Exec(jdh.Commit, "", nil)
}
示例#8
0
文件: sp.del.go 项目: js-arias/jdh
func spDelRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	vals := new(jdh.Values)
	if len(idFlag) > 0 {
		vals.Add(jdh.KeyId, idFlag)
		if _, err := localDB.Exec(jdh.Delete, jdh.Specimens, vals); err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
			os.Exit(1)
		}
		localDB.Exec(jdh.Commit, "", nil)
		return
	}
	var tax *jdh.Taxon
	if len(taxonFlag) > 0 {
		tax = taxon(c, localDB, taxonFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, localDB, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong specimen id or taxon name or id"))
		c.Usage()
	}
	vals.Add(jdh.SpeTaxon, tax.Id)
	if _, err := localDB.Exec(jdh.Delete, jdh.Specimens, vals); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
		os.Exit(1)
	}
	localDB.Exec(jdh.Commit, "", nil)
}
示例#9
0
文件: sp.pop.go 项目: js-arias/jdh
func spPopRun(c *cmdapp.Command, args []string) {
	if len(extDBFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong '--extdb' option"))
		c.Usage()
	}
	openLocal(c)
	openExt(c, extDBFlag, "")
	var tax *jdh.Taxon
	if len(taxonFlag) > 0 {
		tax = taxon(c, localDB, taxonFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, localDB, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		tax = &jdh.Taxon{}
	}
	rank := jdh.Kingdom
	if len(rankFlag) > 0 {
		rank = jdh.GetRank(rankFlag)
		if rank == jdh.Unranked {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("invalid rank"))
			os.Exit(1)
		}
	}
	spPopFetch(c, tax, jdh.Kingdom, rank)
	localDB.Exec(jdh.Commit, "", nil)
}
示例#10
0
文件: ra.info.go 项目: js-arias/jdh
func raInfoRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong raster id"))
		c.Usage()
	}
	openLocal(c)
	ras := raster(c, localDB, idFlag)
	if len(ras.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisTaxon, ras.Taxon)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisSource, ras.Source)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, ras.Reference)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisCols, ras.Cols)
			for _, e := range ras.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, ras.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.RDisTaxon:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisTaxon, ras.Taxon)
		case jdh.RDisSource:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisSource, ras.Source)
		case jdh.RDisCols:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisCols, ras.Cols)
		case jdh.KeyExtern:
			for _, e := range ras.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, ras.Comment)
		case jdh.KeyReference:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, ras.Reference)
		}
		return
	}
	if len(keyFlag) == 0 {
		tax := taxon(c, localDB, ras.Taxon)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", ras.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Taxon:", tax.Name, tax.Authority, ras.Taxon)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Source:", ras.Source)
		fmt.Fprintf(os.Stdout, "%-16s %dx%d\n", "Dimensions:", ras.Cols, ras.Cols/2)
		if len(ras.Reference) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Reference:", ras.Reference)
		}
		if len(ras.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range ras.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(ras.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", ras.Comment)
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.RDisTaxon:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Taxon)
	case jdh.RDisSource:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Source)
	case jdh.RDisCols:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Cols)
	case jdh.KeyExtern:
		for _, e := range ras.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Comment)
	case jdh.KeyReference:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Reference)
	}
}
示例#11
0
文件: tx.info.go 项目: js-arias/jdh
func txInfoRun(c *cmdapp.Command, args []string) {
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	var tax *jdh.Taxon
	if len(idFlag) > 0 {
		tax = taxon(c, db, idFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, db, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong taxon name or id"))
		c.Usage()
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxName, tax.Name)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxAuthority, tax.Authority)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxRank, tax.Rank)
			if tax.IsValid {
				fmt.Fprintf(os.Stdout, "%s=true\n", jdh.TaxValid)
			} else {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxSynonym, tax.Parent)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxParent, tax.Parent)
			for _, e := range tax.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, tax.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.TaxName:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxName, tax.Name)
		case jdh.TaxAuthority:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxAuthority, tax.Authority)
		case jdh.TaxRank:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxRank, tax.Rank)
		case jdh.TaxValid, jdh.TaxSynonym:
			if tax.IsValid {
				fmt.Fprintf(os.Stdout, "%s=true\n", jdh.TaxValid)
			} else {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxSynonym, tax.Parent)
			}
		case jdh.TaxParent:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxParent, tax.Parent)
		case jdh.KeyExtern:
			for _, e := range tax.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, tax.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", tax.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Name:", tax.Name)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Authority:", tax.Authority)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Rank:", tax.Rank)
		if tax.IsValid {
			fmt.Fprintf(os.Stdout, "%-16s true\n", "Valid:")
		} else {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Synonym of:", tax.Parent)
		}
		if len(tax.Parent) > 0 {
			p := taxon(c, db, tax.Parent)
			fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Parent:", p.Name, p.Authority, p.Id)
		}
		if len(tax.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range tax.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(tax.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", tax.Comment)
		}
		txInfoList(c, db, tax.Id, true)
		txInfoList(c, db, tax.Id, false)
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.TaxName:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Name)
	case jdh.TaxAuthority:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Authority)
	case jdh.TaxRank:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Rank)
	case jdh.TaxValid, jdh.TaxSynonym:
		if tax.IsValid {
			fmt.Fprintf(os.Stdout, "true\n")
		} else {
			fmt.Fprintf(os.Stdout, "synonym of %s\n", tax.Parent)
		}
	case jdh.TaxParent:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Parent)
	case jdh.KeyExtern:
		for _, e := range tax.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Comment)
	}
}
示例#12
0
文件: sp.ls.go 项目: js-arias/jdh
func spLsRun(c *cmdapp.Command, args []string) {
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	var tax *jdh.Taxon
	if len(taxonFlag) > 0 {
		tax = taxon(c, db, taxonFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, db, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong taxon name or id"))
		c.Usage()
	}
	vals := new(jdh.Values)
	if childFlag {
		vals.Add(jdh.SpeTaxonParent, tax.Id)
	} else {
		vals.Add(jdh.SpeTaxon, tax.Id)
	}
	if len(countryFlag) > 0 {
		vals.Add(jdh.GeoCountry, countryFlag)
	}
	if geoRefFlag {
		vals.Add(jdh.SpeGeoref, "true")
	} else if noRefFlag {
		vals.Add(jdh.SpeGeoref, "false")
	}
	l := speList(c, db, vals)
	defer l.Close()
	ct := tax
	for {
		spe := &jdh.Specimen{}
		if err := l.Scan(spe); err != nil {
			if err == io.EOF {
				break
			}
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
			os.Exit(1)
		}
		if machineFlag {
			fmt.Fprintf(os.Stdout, "%s\n", spe.Id)
			continue
		}
		if spe.Taxon != ct.Id {
			ct = taxon(c, db, spe.Taxon)
		}
		if verboseFlag {
			fmt.Fprintf(os.Stdout, "%s %s %s\t%s %s", ct.Id, ct.Name, ct.Authority, spe.Id, spe.Catalog)
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "\t%.5f %.5f %d", spe.Georef.Point.Lon, spe.Georef.Point.Lat, spe.Georef.Uncertainty)
			}
			fmt.Fprintf(os.Stdout, "\n")
			continue
		}
		fmt.Fprintf(os.Stdout, "%s\t%s", ct.Name, spe.Catalog)
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "\t%.5f %.5f", spe.Georef.Point.Lon, spe.Georef.Point.Lat)
		}
		fmt.Fprintf(os.Stdout, "\n")
	}
}
示例#13
0
文件: tr.info.go 项目: js-arias/jdh
func trInfoRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	if len(nodeFlag) > 0 {
		trInfoNode(c)
		return
	}
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong tree or node id"))
		c.Usage()
	}
	phy := phylogeny(c, localDB, idFlag)
	if len(phy.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TreName, phy.Name)
			for _, e := range phy.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, phy.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.TreName:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TreName, phy.Name)
		case jdh.KeyExtern:
			for _, e := range phy.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, phy.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", phy.Id)
		if len(phy.Name) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Name:", phy.Name)
		}
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Root:", phy.Root)
		if len(phy.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range phy.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(phy.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", phy.Comment)
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.TreName:
		fmt.Fprintf(os.Stdout, "%s\n", phy.Name)
	case jdh.KeyExtern:
		for _, e := range phy.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", phy.Comment)
	}
}
示例#14
0
文件: tx.sync.go 项目: js-arias/jdh
func txSyncRun(c *cmdapp.Command, args []string) {
	if len(extDBFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong '--extdb' option"))
		c.Usage()
	}
	openLocal(c)
	openExt(c, extDBFlag, "")
	var tax *jdh.Taxon
	if len(idFlag) > 0 {
		tax = taxon(c, localDB, idFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, localDB, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		tax = &jdh.Taxon{}
	}
	noFlag := true
	if matchFlag {
		txSyncMatch(c, tax)
		localDB.Exec(jdh.Commit, "", nil)
		noFlag = false
	}
	if updateFlag || validFlag {
		txSyncUpdate(c, tax)
		localDB.Exec(jdh.Commit, "", nil)
		noFlag = false
	}
	if len(rankFlag) > 0 {
		rank := jdh.GetRank(rankFlag)
		if rank == jdh.Unranked {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("invalid rank"))
			os.Exit(1)
		}
		txSyncRank(c, tax, rank)
		localDB.Exec(jdh.Commit, "", nil)
		noFlag = false
	}
	if len(popFlag) > 0 {
		rank := jdh.GetRank(popFlag)
		if rank == jdh.Unranked {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("invalid rank"))
			os.Exit(1)
		}
		prev := tax.Rank
		if prev == jdh.Unranked {
			prev = jdh.Kingdom
		}
		txSyncPop(c, tax, prev, rank)
		localDB.Exec(jdh.Commit, "", nil)
		noFlag = false
	}
	if noFlag {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("undefined action"))
		c.Usage()
	}
}
示例#15
0
文件: sp.info.go 项目: js-arias/jdh
func spInfoRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong specimen id"))
		c.Usage()
	}
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	spe := specimen(c, db, idFlag)
	if len(spe.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeTaxon, spe.Taxon)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeBasis, spe.Basis)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, spe.Reference)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDataset, spe.Dataset)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCatalog, spe.Catalog)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDeterminer, spe.Determiner)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCollector, spe.Collector)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDate, spe.Date.Format(jdh.Iso8601))
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCountry, spe.Geography.Country)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoState, spe.Geography.State)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCounty, spe.Geography.County)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeLocality, spe.Locality)
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%.8f,%.8f\n", jdh.GeoLonLat, spe.Georef.Point.Lon, spe.Georef.Point.Lat)
				fmt.Fprintf(os.Stdout, "%s=%d\n", jdh.GeoUncertainty, spe.Georef.Uncertainty)
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoSource, spe.Georef.Source)
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoValidation, spe.Georef.Validation)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoLonLat)
				fmt.Fprintf(os.Stdout, "%s=0\n", jdh.GeoUncertainty)
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoSource)
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoValidation)
			}
			for _, e := range spe.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, spe.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.SpeTaxon:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeTaxon, spe.Taxon)
		case jdh.SpeBasis:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeBasis, spe.Basis)
		case jdh.SpeDataset:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDataset, spe.Dataset)
		case jdh.SpeCatalog:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCatalog, spe.Catalog)
		case jdh.SpeDeterminer:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDeterminer, spe.Determiner)
		case jdh.SpeCollector:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCollector, spe.Collector)
		case jdh.SpeDate:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDate, spe.Date.Format(jdh.Iso8601))
		case jdh.GeoCountry:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCountry, spe.Geography.Country)
		case jdh.GeoState:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoState, spe.Geography.State)
		case jdh.GeoCounty:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCounty, spe.Geography.County)
		case jdh.SpeLocality:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeLocality, spe.Locality)
		case jdh.GeoLonLat:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%.8f,%.8f\n", jdh.GeoLonLat, spe.Georef.Point.Lon, spe.Georef.Point.Lat)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoLonLat)
			}
		case jdh.GeoUncertainty:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%d\n", jdh.GeoUncertainty, spe.Georef.Uncertainty)
			} else {
				fmt.Fprintf(os.Stdout, "%s=0\n", jdh.GeoUncertainty)
			}
		case jdh.GeoSource:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoSource, spe.Georef.Source)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoSource)
			}
		case jdh.GeoValidation:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoValidation, spe.Georef.Validation)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoValidation)
			}
		case jdh.KeyExtern:
			for _, e := range spe.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, spe.Comment)
		case jdh.KeyReference:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, spe.Reference)
		}
		return
	}
	if len(keyFlag) == 0 {
		tax := taxon(c, db, spe.Taxon)
		var set *jdh.Dataset
		if len(spe.Dataset) > 0 {
			set = dataset(c, db, spe.Dataset)
		}
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", spe.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Taxon:", tax.Name, tax.Authority, spe.Taxon)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Basis:", spe.Basis)
		if len(spe.Reference) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Reference:", spe.Reference)
		}
		if set != nil {
			fmt.Fprintf(os.Stdout, "%-16s [id: %s]\n%s\n", "Dataset:", set.Id, set.Title)
		}
		if len(spe.Catalog) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Catalog:", spe.Catalog)
		}
		if len(spe.Determiner) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Determiner:", spe.Determiner)
		}
		if len(spe.Collector) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Collector:", spe.Collector)
		}
		if !spe.Date.IsZero() {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Date:", spe.Date.Format(jdh.Iso8601))
		}
		if len(spe.Geography.Country) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Country:", spe.Geography.Country.Name())
		}
		if len(spe.Geography.State) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "State:", spe.Geography.State)
		}
		if len(spe.Geography.County) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "County:", spe.Geography.County)
		}
		if len(spe.Locality) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Locality:", spe.Locality)
		}
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%-16s %.8f, %.8f\n", "LonLat:", spe.Georef.Point.Lon, spe.Georef.Point.Lat)
			if spe.Georef.Uncertainty != 0 {
				fmt.Fprintf(os.Stdout, "%-16s %d\n", "Uncertainty:", spe.Georef.Uncertainty)
			}
			if len(spe.Georef.Source) > 0 {
				fmt.Fprintf(os.Stdout, "%-16s %s\n", "Source:", spe.Georef.Source)
			}
			if len(spe.Georef.Validation) > 0 {
				fmt.Fprintf(os.Stdout, "%-16s %s\n", "Validation:", spe.Georef.Validation)
			}
		}
		if len(spe.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range spe.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(spe.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", spe.Comment)
		}
		if set != nil {
			if len(set.Citation) > 0 {
				fmt.Fprintf(os.Stdout, "Citation:\n%s\n", set.Citation)
			}
			if len(set.License) > 0 {
				fmt.Fprintf(os.Stdout, "License:\n%s\n", set.License)
			}
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.SpeTaxon:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Taxon)
	case jdh.SpeBasis:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Basis)
	case jdh.SpeDataset:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Dataset)
	case jdh.SpeCatalog:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Catalog)
	case jdh.SpeDeterminer:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Determiner)
	case jdh.SpeCollector:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Collector)
	case jdh.SpeDate:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Date.Format(jdh.Iso8601))
	case jdh.GeoCountry:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Geography.Country)
	case jdh.GeoState:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Geography.State)
	case jdh.GeoCounty:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Geography.County)
	case jdh.SpeLocality:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Locality)
	case jdh.GeoLonLat:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%.8f\t%.8f\n", spe.Georef.Point.Lon, spe.Georef.Point.Lat)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.GeoUncertainty:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%d\n", spe.Georef.Uncertainty)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.GeoSource:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%s\n", spe.Georef.Source)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.GeoValidation:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%s\n", spe.Georef.Validation)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.KeyExtern:
		for _, e := range spe.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Comment)
	case jdh.KeyReference:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Reference)
	}
}
示例#16
0
文件: ds.info.go 项目: js-arias/jdh
func dsInfoRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong dataset id"))
		c.Usage()
	}
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	set := dataset(c, db, idFlag)
	if len(set.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataTitle, set.Title)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataCitation, set.Citation)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataLicense, set.License)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataUrl, set.Url)
			for _, e := range set.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, set.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.DataTitle:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataTitle, set.Title)
		case jdh.DataCitation:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataCitation, set.Citation)
		case jdh.DataLicense:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataLicense, set.License)
		case jdh.DataUrl:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataUrl, set.Url)
		case jdh.KeyExtern:
			for _, e := range set.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, set.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", set.Id)
		fmt.Fprintf(os.Stdout, "Title:\n%s\n", set.Title)
		if len(set.Url) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Url:", set.Url)
		}
		if len(set.Citation) > 0 {
			fmt.Fprintf(os.Stdout, "Citation:\n%s\n", set.Citation)
		}
		if len(set.License) > 0 {
			fmt.Fprintf(os.Stdout, "License:\n%s\n", set.License)
		}
		if len(set.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range set.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(set.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", set.Comment)
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.DataTitle:
		fmt.Fprintf(os.Stdout, "%s\n", set.Title)
	case jdh.DataCitation:
		fmt.Fprintf(os.Stdout, "%s\n", set.Citation)
	case jdh.DataLicense:
		fmt.Fprintf(os.Stdout, "%s\n", set.License)
	case jdh.DataUrl:
		fmt.Fprintf(os.Stdout, "%s\n", set.Url)
	case jdh.KeyExtern:
		for _, e := range set.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", set.Comment)
	}
}
示例#17
0
文件: tx.del.go 项目: js-arias/jdh
func txDelRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	var tax *jdh.Taxon
	if len(idFlag) > 0 {
		tax = taxon(c, localDB, idFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, localDB, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong taxon name or id"))
		c.Usage()
	}
	vals := new(jdh.Values)
	if colpFlag {
		if len(tax.Parent) > 0 {
			vals.Add(jdh.KeyId, tax.Id)
			vals.Add(jdh.TaxSynonym, "")
			if _, err := localDB.Exec(jdh.Set, jdh.Taxonomy, vals); err != nil {
				fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
				os.Exit(1)
			}
		} else {
			l := getTaxDesc(c, localDB, tax.Id, true)
			for {
				desc := &jdh.Taxon{}
				if err := l.Scan(desc); err != nil {
					if err == io.EOF {
						break
					}
					fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
					os.Exit(1)
				}
				vals.Reset()
				vals.Add(jdh.KeyId, desc.Id)
				vals.Add(jdh.TaxParent, "")
				if _, err := localDB.Exec(jdh.Set, jdh.Taxonomy, vals); err != nil {
					fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
					os.Exit(1)
				}
			}
		}
	}
	vals.Reset()
	vals.Add(jdh.KeyId, tax.Id)
	if _, err := localDB.Exec(jdh.Delete, jdh.Taxonomy, vals); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
		os.Exit(1)
	}
	localDB.Exec(jdh.Commit, "", nil)
}