def parse_blocks(blocks_elt): blocks = [] for b_e in blocks_elt.findall("block"): name = get_attrib(b_e, "name") no = get_attrib(b_e, "no") block = Block(name, int(no), b_e) blocks.append(block) return blocks
def parse_exceptions(exs_elt): if exs_elt is None: return [] excs = [] for ex_e in exs_elt.findall("exception"): cond = get_attrib(ex_e, "cond") deroute = get_attrib(ex_e, "deroute") exc = Exc(cond, deroute) excs.append(exc) return excs
def parse(fp_xml): fp = FlightPlan() fp_tree = etree.parse(fp_xml) fp_element = fp_tree.find("flight_plan") fp.name = get_attrib(fp_element, "name") fp.lat0 = get_attrib(fp_element, "lat0") fp.lon0 = get_attrib(fp_element, "lon0") fp.max_dist_from_home = get_attrib(fp_element, "max_dist_from_home") fp.ground_alt = get_attrib(fp_element, "ground_alt") fp.security_height = get_attrib(fp_element, "security_height") fp.alt = get_attrib(fp_element, "alt") if fp_element.find("header") is not None: fp.header = fp_element.find("header").text ways_elt = fp_element.find("waypoints") fp.waypoints = FlightPlan.parse_waypoints(ways_elt) blocks_elt = fp_element.find("blocks") fp.blocks = FlightPlan.parse_blocks(blocks_elt) excs_elt = fp_element.find("exceptions") fp.exceptions = FlightPlan.parse_exceptions(excs_elt) return fp
def parse_waypoints(ways_elt: etree.Element): waypoints = [] w_no = 1 # first waypoint number is 1. for way_e in ways_elt.findall("waypoint"): name = get_attrib(way_e, "name") x = get_attrib_default(way_e, "x", None, float) y = get_attrib_default(way_e, "y", None, float) lat = get_attrib_default(way_e, "lat", None) lon = get_attrib_default(way_e, "lon", None) alt = get_attrib_default(way_e, "alt", None, float) height = get_attrib_default(way_e, "height", None, float) waypoint = Waypoint(name, x, y, lat, lon, alt, height, w_no) waypoints.append(waypoint) w_no += 1 return waypoints
def parse_dl_setting(self, element): var = get_attrib(element, "var") min_v = get_attrib(element, "min", typ=float) max_v = get_attrib(element, "max", typ=float) shortname = get_attrib_default(element, "shortname", var) step = get_attrib_default(element, "step", 1, typ=float) values = get_attrib_default(element, "values", None) if values is None: values = [] else: values = values.split("|") count = int((max_v - min_v + step) / step) if len(values) != count: print( "Warning: possibly wrong number of values ({}) for {} (expected {})" .format(len(values), shortname, count)) setting = PprzSetting(var, self.setting_nb, shortname, min_v, max_v, step, values, element) for e_button in element.findall("strip_button"): name = get_attrib(e_button, "name") value = get_attrib(e_button, "value") icon = get_attrib_default(e_button, "icon", None) group = get_attrib_default(e_button, "group", None) button = StripButton(value, name, icon, group) setting.buttons.append(button) for e_key in element.findall("key_press"): key = get_attrib(e_key, "key") value = get_attrib(e_key, "value") key_press = KeyPress(key, value) setting.key_press.append(key_press) self.setting_nb += 1 return setting