Example #1
0
// runAirfieldPut invokes the configured plugins to put airfield data from source to dest.
func runAirfieldPut(cmd *commander.Command, args []string) {
	var err error
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, "failed to put airfield data :: no destination given\n")
		return
	}
	cfg, _ := config.Get()
	pluginID := args[0]
	destPlugin, err := plugin.GetAirfielder(pluginID, cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get plugin '%v' :: %v\n", pluginID, err)
		return
	}
	afield, _ := plugin.GetAirfielder("", cfg)
	airfields, err := afield.(airfield.Airfielder).GetAirfield(strings.Split(*region, ","), time.Time{})
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get airfield :: %v\n", err)
		return
	}
	glog.V(5).Infof("putting %v airfields", len(airfields))
	glog.V(20).Infof("%v", airfields)
	if len(airfields) > 0 {
		err = destPlugin.(airfield.Airfielder).PutAirfield(airfields)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to put airfields :: %v\n", err)
			return
		}
	}
	fmt.Printf("pushed %v airfields into %v\n", len(airfields), pluginID)
}
Example #2
0
// runAirfieldGet invokes the configured plugin and outputs airfield data.
func runAirfieldGet(cmd *commander.Command, args []string) {
	var err error
	cfg, _ := config.Get()
	afield, err := plugin.GetAirfielder("", cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get airfield plugin :: %v\n", err)
		return
	}
	tafter := time.Time{}
	if *after != "" {
		tafter, err = time.Parse("2006-01-02", *after)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to get airfield :: %v\n", err)
			return
		}
	}
	airfields, err := afield.(airfield.Airfielder).GetAirfield(strings.Split(*region, ","), tafter)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get airfield :: %v\n", err)
		return
		// FIXME: must return -1, but no way now to check this in test
	}
	glog.V(5).Infof("airfield get with args '%v' got %d results", args, len(airfields))
	glog.V(20).Infof("%+v", airfields)
	fmt.Printf("%v", util.Struct2CSV(airfields))
}
Example #3
0
// runWaypointPut invokes the configured plugins to put waypoint data from source to dest.
func runWaypointPut(cmd *commander.Command, args []string) {
	var err error
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, "failed to put waypoint data :: no destination given\n")
		return
	}
	cfg, _ := config.Get()
	pluginID := args[0]
	destPlugin, err := plugin.GetWaypointer(pluginID, cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get plugin '%v' :: %v\n", pluginID, err)
		return
	}
	wpoint, _ := plugin.GetWaypointer("", cfg)
	waypoints, err := wpoint.(waypoint.Waypointer).GetWaypoint(strings.Split(*region, ","), time.Time{})
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get waypoint :: %v\n", err)
		return
	}
	glog.V(5).Infof("putting %v waypoints", len(waypoints))
	glog.V(20).Infof("%v", waypoints)
	if len(waypoints) > 0 {
		err = destPlugin.(waypoint.Waypointer).PutWaypoint(waypoints)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to put waypoints :: %v\n", err)
			return
		}
	}
	fmt.Printf("pushed %v waypoints into %v\n", len(waypoints), pluginID)
}
Example #4
0
// runFlightGet invokes the configured plugin and outputs flight data.
func runFlightGet(cmd *commander.Command, args []string) {
	cfg, _ := config.Get()
	f, _ := plugin.GetFlighter("", cfg)
	glog.V(20).Infof("flight plugin instance ::  %v", f)

	var flights []flight.Flight
	if *startID != "" {
		vmax := -1
		// query for flights with ID higher than startID
		sid, err := strconv.Atoi(*startID)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to get flight :: %v\n", err)
			return
		}
		if *max != "" {
			vmax, err = strconv.Atoi(*max)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to get flight :: %v\n", err)
				return
			}
		}
		glog.V(10).Infof("querying from start id %v, max %v", sid, vmax)
		flights, err = f.(flight.Flighter).GetFlightFromID(sid, vmax)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to get flight :: %v\n", err)
			return
		}
	} else if *id != "" {
		// query for flights with specific ID
		sid, err := strconv.Atoi(*id)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to get flight :: %v\n", err)
			return
		}
		glog.V(10).Infof("querying id %v", sid)
		flight, err := f.(flight.Flighter).GetFlightByID(sid)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to get flight :: %v\n", err)
			return
			// FIXME: must return -1, but no way now to check this in test
		}
		flights = append(flights, flight)
	}
	glog.V(5).Infof("flight get with args '%v' got %d results", args, len(flights))
	glog.V(20).Infof("%+v", flights)
	for _, f := range flights {
		fmt.Printf("%v,%v,%v,%v\n", f.Header.Date.Format("02/01/2006"),
			f.Header.Pilot, f.Header.GliderType, f.Header.GliderID)
		for sourceID, source := range f.Sources {
			fmt.Printf("\t%v,%v,%v,%v,%v,%v,%v,%v\n", sourceID, source.Name,
				source.Category, source.Club, source.Country, source.Region,
				source.Distance, source.Points)
		}
	}
}
Example #5
0
// runAirspaceGet invokes the configured plugin and outputs airspace data.
func runAirspaceGet(cmd *commander.Command, args []string) {
	var err error
	cfg, _ := config.Get()
	aspace, err := plugin.GetAirspacer("", cfg)
	if err != nil {
		glog.Errorf("failed to get airspacer plugin :: %v\n", err)
		return
	}
	airspaces, err := aspace.GetAirspace(strings.Split(*region, ","), time.Time{})
	if err != nil {
		glog.Errorf("failed to get airspace :: %v", err)
		// FIXME: must return -1, but no way now to check this in test
	}
	glog.V(5).Infof("airspace get with args '%v' got %d results", args, len(airspaces))
	glog.V(20).Infof("%+v", airspaces)
	for i := range airspaces {
		fmt.Printf("%+v\n", airspaces[i])
	}
}
Example #6
0
// runWaypointGet invokes the configured plugin and outputs waypoint data.
func runWaypointGet(cmd *commander.Command, args []string) {
	var err error
	cfg, _ := config.Get()
	wpoint, _ := plugin.GetWaypointer("", cfg)

	tafter := time.Time{}
	if *after != "" {
		tafter, err = time.Parse("2006-01-02", *after)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to get waypoint :: %v\n", err)
			return
		}
	}
	waypoints, err := wpoint.(waypoint.Waypointer).GetWaypoint(strings.Split(*region, ","), tafter)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get waypoint :: %v", err)
		// FIXME: must return -1, but no way now to check this in test
	}
	glog.V(5).Infof("waypoint get with args '%v' got %d results", args, len(waypoints))
	glog.V(20).Infof("%+v", waypoints)
	fmt.Printf("%v", util.Struct2CSV(waypoints))
}