2022-05-25 16:15:27 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2022-12-23 17:35:35 +00:00
|
|
|
locodedb "github.com/TrueCloudLab/frostfs-node/pkg/util/locode/db"
|
|
|
|
airportsdb "github.com/TrueCloudLab/frostfs-node/pkg/util/locode/db/airports"
|
|
|
|
locodebolt "github.com/TrueCloudLab/frostfs-node/pkg/util/locode/db/boltdb"
|
|
|
|
continentsdb "github.com/TrueCloudLab/frostfs-node/pkg/util/locode/db/continents/geojson"
|
|
|
|
csvlocode "github.com/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)
|
|
|
|
}
|