forked from TrueCloudLab/frostfs-locode-db
George Bartolomey
840b20538b
Added frostfs-locode-db CLI utility that can generate and view UN/LOCODE database files. Go package git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode copied to this repository to eliminate interdependency between frostfs-node and frostfs-locode-db projects. The process of building database files reduced to starting make command. Signed-off-by: George Bartolomey <george@bh4.ru>
96 lines
3.1 KiB
Go
96 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
locodedb "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db"
|
|
airportsdb "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db/airports"
|
|
locodebolt "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db/boltdb"
|
|
continentsdb "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db/continents/geojson"
|
|
csvlocode "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/table/csv"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type namesDB struct {
|
|
*airportsdb.DB
|
|
*csvlocode.Table
|
|
}
|
|
|
|
const (
|
|
locodeGenerateInputFlag = "in"
|
|
locodeGenerateSubDivFlag = "subdiv"
|
|
locodeGenerateAirportsFlag = "airports"
|
|
locodeGenerateCountriesFlag = "countries"
|
|
locodeGenerateContinentsFlag = "continents"
|
|
locodeGenerateOutputFlag = "out"
|
|
)
|
|
|
|
var (
|
|
locodeGenerateInPaths []string
|
|
locodeGenerateSubDivPath string
|
|
locodeGenerateAirportsPath string
|
|
locodeGenerateCountriesPath string
|
|
locodeGenerateContinentsPath string
|
|
locodeGenerateOutPath string
|
|
|
|
locodeGenerateCmd = &cobra.Command{
|
|
Use: "generate",
|
|
Short: "Generate UN/LOCODE database for FrostFS",
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
|
|
locodeDB := csvlocode.New(
|
|
csvlocode.Prm{
|
|
Path: locodeGenerateInPaths[0],
|
|
SubDivPath: locodeGenerateSubDivPath,
|
|
},
|
|
csvlocode.WithExtraPaths(locodeGenerateInPaths[1:]...),
|
|
)
|
|
|
|
airportDB := airportsdb.New(airportsdb.Prm{
|
|
AirportsPath: locodeGenerateAirportsPath,
|
|
CountriesPath: locodeGenerateCountriesPath,
|
|
})
|
|
|
|
continentsDB := continentsdb.New(continentsdb.Prm{
|
|
Path: locodeGenerateContinentsPath,
|
|
})
|
|
|
|
targetDB := locodebolt.New(locodebolt.Prm{
|
|
Path: locodeGenerateOutPath,
|
|
})
|
|
|
|
err := targetDB.Open()
|
|
ExitOnErr(cmd, "", err)
|
|
|
|
defer targetDB.Close()
|
|
|
|
names := &namesDB{
|
|
DB: airportDB,
|
|
Table: locodeDB,
|
|
}
|
|
|
|
err = locodedb.FillDatabase(locodeDB, airportDB, continentsDB, names, targetDB)
|
|
ExitOnErr(cmd, "", err)
|
|
},
|
|
}
|
|
)
|
|
|
|
func initUtilLocodeGenerateCmd() {
|
|
flags := locodeGenerateCmd.Flags()
|
|
|
|
flags.StringSliceVar(&locodeGenerateInPaths, locodeGenerateInputFlag, nil, "List of paths to UN/LOCODE tables (csv)")
|
|
_ = locodeGenerateCmd.MarkFlagRequired(locodeGenerateInputFlag)
|
|
|
|
flags.StringVar(&locodeGenerateSubDivPath, locodeGenerateSubDivFlag, "", "Path to UN/LOCODE subdivision database (csv)")
|
|
_ = locodeGenerateCmd.MarkFlagRequired(locodeGenerateSubDivFlag)
|
|
|
|
flags.StringVar(&locodeGenerateAirportsPath, locodeGenerateAirportsFlag, "", "Path to OpenFlights airport database (csv)")
|
|
_ = locodeGenerateCmd.MarkFlagRequired(locodeGenerateAirportsFlag)
|
|
|
|
flags.StringVar(&locodeGenerateCountriesPath, locodeGenerateCountriesFlag, "", "Path to OpenFlights country database (csv)")
|
|
_ = locodeGenerateCmd.MarkFlagRequired(locodeGenerateCountriesFlag)
|
|
|
|
flags.StringVar(&locodeGenerateContinentsPath, locodeGenerateContinentsFlag, "", "Path to continent polygons (GeoJSON)")
|
|
_ = locodeGenerateCmd.MarkFlagRequired(locodeGenerateContinentsFlag)
|
|
|
|
flags.StringVar(&locodeGenerateOutPath, locodeGenerateOutputFlag, "", "Target path for generated database")
|
|
_ = locodeGenerateCmd.MarkFlagRequired(locodeGenerateOutputFlag)
|
|
}
|