2022-05-25 16:15:27 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
|
|
locodedb "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/db"
|
|
|
|
airportsdb "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/db/airports"
|
|
|
|
locodebolt "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/db/boltdb"
|
|
|
|
continentsdb "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/db/continents/geojson"
|
|
|
|
csvlocode "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/table/csv"
|
2022-05-25 16:15:27 +00:00
|
|
|
"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",
|
2023-01-27 10:44:39 +00:00
|
|
|
Short: "Generate UN/LOCODE database for FrostFS",
|
2022-05-25 16:15:27 +00:00
|
|
|
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()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
|
|
|
|
defer targetDB.Close()
|
|
|
|
|
|
|
|
names := &namesDB{
|
|
|
|
DB: airportDB,
|
|
|
|
Table: locodeDB,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = locodedb.FillDatabase(locodeDB, airportDB, continentsDB, names, targetDB)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|