def parse_scene_from_xml(_scene_el, _scene_index, _scene_name): new_scene = Scene() # Find meta element. meta_el = _scene_el.find("meta") if meta_el is not None: # Get scene ID, use scene name if not found and there's only one scene, otherwise skip. new_scene.id = meta_el.get("id") if new_scene.id is None: if _scene_name: new_scene.id = _scene_name else: logger.error("Scene {0} has a meta element without an id attribute. Skipping.".format(_scene_index+1)) return else: new_scene.id = new_scene.id.strip() if not scene_id_re.match(new_scene.id): logger.error("Scene {0} has an invalid id '{1}'. Scene ids must consist of letters, underscores, hyphens, spaces, and numbers. Skipping.".format(_scene_index+1, new_scene.id)) return # Get scene tags, if any. tags = meta_el.get("tags", None) if tags: new_scene.tags = string_to_tags(tags) else: if _scene_name: new_scene.id = _scene_name else: logger.error("Scene {0} does not contain a meta element. Skipping.".format(_scene_index+1)) return if new_scene.id in scenes: logger.error("Scene {0} has id {1} which already exists. Skipping.".format(_scene_index+1, new_scene.id)) return new_scene.blocks = parse_content_of_xml_element(_scene_el) logger.debug("Read scene {0}.".format(_scene_index+1)) scenes[new_scene.id] = new_scene tagged_scene_ids.add_item(new_scene.tags, new_scene.id)
def read_tags(_el, _el_name): tags = [] tags_string = _el.get("tags") if tags_string: tags = string_to_tags(tags_string) return tags