def _extract_tag_text(elem: ElementTree, path: AnyStr) -> AnyStr: try: return elem.find(path, NS).text except AttributeError as e: logger.error('Error while extracting value of {path}', fparams={'path': path}) raise e
def _parse_rights(self, root: ElementTree) -> None: self._rights = {} rights = root.find("./Rights") if rights: name_list = rights.findall("./Name") access_list = rights.findall("./Access") for name, access in zip(name_list, access_list): self._rights[name.text] = int(access.text)
def synchronize_layer(self, el: ElementTree, parent: ElementTree = None) -> None: if el.find("Layer") is None: tree_item = self.get_layer_wms(el, parent) elif parent is None: tree_item = self.get_theme(el) else: tree_item = self.get_layer_group(el, parent) for child in el.findall("Layer"): self.synchronize_layer(child, tree_item)
def get_layer_group(self, el: ElementTree, parent: ElementTree) -> main.LayerGroup: name = el.find("Name").text group = cast( Optional[main.LayerGroup], ( self._request.dbsession.query(main.LayerGroup) .filter(main.LayerGroup.name == name) .one_or_none() ), ) if group is None: group = main.LayerGroup(name=el.find("Name").text) group.parents_relation.append(main.LayergroupTreeitem(group=parent)) # pylint: disable=no-member self._request.dbsession.add(group) self._logger.info("Layer %s added as new group in theme %s", name, parent.name) self._groups_added += 1 else: self._items_found += 1 return group
def get_theme(self, el: ElementTree) -> main.Theme: name = el.find("Name").text theme = cast( Optional[main.Theme], self._request.dbsession.query(main.Theme).filter(main.Theme.name == name).one_or_none(), ) if theme is None: theme = main.Theme() theme.name = name theme.public = False theme.interfaces = self._interfaces self._request.dbsession.add(theme) self._logger.info("Layer %s added as new theme", name) self._themes_added += 1 else: self._items_found += 1 return theme
def get_question(item: ElementTree, id: str) -> str: """Extract question from item in XML.""" title = item.find("title").text return title.replace(f"{id}.", "").strip()
def _parse_login_response(self, root: ElementTree) -> bool: self._sid = root.find("./SID").text self._block_time = int(root.find("./BlockTime").text) self._parse_rights(root) return self._sid != "0000000000000000"
def get_layer_wms(self, el: ElementTree, parent: ElementTree) -> main.LayerWMS: name = el.find("Name").text layer = cast( Optional[main.LayerWMS], self._request.dbsession.query(main.LayerWMS).filter(main.LayerWMS.name == name).one_or_none(), ) if layer is None: layer = main.LayerWMS() # TreeItem layer.name = el.find("Name").text layer.description = self._default_wms.description layer.metadatas = [main.Metadata(name=m.name, value=m.value) for m in self._default_wms.metadatas] # Layer layer.public = False layer.geo_table = None layer.exclude_properties = self._default_wms.exclude_properties layer.interfaces = list(self._default_wms.interfaces) or self._interfaces # DimensionLayer layer.dimensions = [ main.Dimension( name=d.name, value=d.value, field=d.field, description=d.description, ) for d in self._default_wms.dimensions ] # LayerWMS layer.ogc_server = self._ogc_server layer.layer = el.find("Name").text layer.style = ( self._default_wms.style if el.find("./Style/Name[.='{}']".format(self._default_wms.style)) is not None else None ) # layer.time_mode = # layer.time_widget = self._request.dbsession.add(layer) if parent is None or isinstance(parent, main.Theme): self._logger.info("Layer %s added as new layer with no parent", name) else: layer.parents_relation.append(main.LayergroupTreeitem(group=parent)) self._logger.info("Layer %s added as new layer in group %s", name, parent.name) self._layers_added += 1 else: self._items_found += 1 if layer.ogc_server is not self._ogc_server: self._logger.info( "Layer %s: another layer already exists with the same name in OGC server %s", name, self._ogc_server.name, ) return layer