def gather_capabilities(Nset, nameSet, cur, set_layers, list_WMSservers, server_URL): # Generated file name name_file = nameSet + ".xml" # Product of an object class Document - dom dom = xml.dom.minidom.Document() # DTD schema takes one of the servers Nwms_dtd = list_WMSservers[0] # create service tag with need information (see Service.py).Return subtree dom tag_service = Service.get_tag(dom, server_URL, nameSet, Nwms_dtd) # create tag Capability. capability = dom.createElement("Capability") tag_service.appendChild(capability) # create tag in Capability: Request request_dom = dom.createElement("Request") capability.appendChild(request_dom) # Formated a tag Request with the intersection of all formats by all used servers request_dom = Service.get_tagRequest(dom, "GetCapabilities", request_dom,\ server_URL, cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "GetMap", request_dom, server_URL,\ cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "GetFeatureInfo", request_dom, \ server_URL, cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "DescribeLayer", request_dom, \ server_URL, cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "GetLegendGraphic", request_dom, \ server_URL, cur, list_WMSservers, nameSet, 0) Nwms_used = -1 count_servers = 0 oldlist_formats = [] for server_id in list_WMSservers: # Enumerates all used servers # Check their recurrence if Nwms_used == server_id: continue Nwms_used = server_id # Requested format of the tag with the name "Exception" of the server server_id # SELECT xpath_nodeset(Capabilites, '"//Capability/Exception/Format"') # FROM WMSresources # WHERE Nwms = server_id; res = BD.interset_request(cur, "WMSresources", "Capabilites",\ "//Capability/Exception/Format", "Nwms", server_id) # Stores intersection list formats result = [] if res: # If there is a format for tagFormat in res: strformat = tagFormat.replace("</Format>", "</Format>\n") if count_servers: # This is not the first list of formats oldlist_formats = list_formats # The string format is divided into a list list_formats = strformat.split("\n") # Created by the intersection of the lists of formats belonging to two servers for m in oldlist_formats: for j in list_formats: if m == j: result.append(m) break # The result of suppresion of record in the list of formats list_formats = result else: # This is the first list of formats # The string format is divided into a list list_formats = strformat.split("\n") count_servers += 1 # Formed a string from the list of formats strformat = " " for k in list_formats: strformat = strformat + "%s\n\t"%k # Create tag "Exception" exception = dom.createElement("Exception") capability.appendChild(exception) except_format = dom.createTextNode("%s" % strformat) exception.appendChild(except_format) count_servers = 0 Nwms_used = -1 oldlist_formats = " " for server_id in list_WMSservers: # Enumerates all used servers result = " " # Check their recurrence if Nwms_used == server_id: continue Nwms_used = server_id # Requested format of the tag with the name "Exception" of the server server_id # SELECT xpath_nodeset(Capabilites, '"//Capability/UserDefinedSymbolization"') # FROM WMSresources # WHERE Nwms = server_id; res = BD.interset_request(cur, "WMSresources", "Capabilites",\ "//Capability/UserDefinedSymbolization",\ "Nwms", server_id) if res: # If there is a UserDefinedSymbolization for tagSymbolization in res: if count_servers: # This is not the first string UserDefinedSymbolization oldlist_formats = list_formats list_formats = tagSymbolization if oldlist_formats == list_formats: result = list_formats else: list_formats = tagSymbolization count_servers += 1 list_formats = result # Create tag UserDefinedSymbolization symb = dom.createTextNode("%s" % list_formats) capability.appendChild(symb) # External layer - layer containing all the layers set external_Layer = dom.createElement("Layer") capability.appendChild(external_Layer) Name_exLayer = dom.createElement("Name") Name_exLayer.appendChild(dom.createTextNode("%s"%nameSet)) external_Layer.appendChild(Name_exLayer) Title_exLayer = dom.createElement("Title") Title_exLayer.appendChild(dom.createTextNode("WMS Resource Manager of SB RAS")) external_Layer.appendChild(Title_exLayer) # Requested a list of layers which don't display in "Capabilities" tables = [] keywords = {} tables.append("AuthorsSets.layer_noset") keywords["AuthorsSets.Nset"] = Nset res = BD.ifsome_tables(cur, tables, keywords, "AuthorsSets") if res: list_layernoset = res[0][0] else: list_layernoset = "" # For all layers of the set for Nlayer, Nwms in set_layers.items(): # Checking whether to display the layer in "Capabilities" place_instr = list_layernoset.find("%d"%Nlayer + ";") if (place_instr != -1): if ((place_instr != 0 and (list_layernoset[place_instr-1:place_instr])!='_') or (place_instr == 0)): # If the layer is not necessary to display, then its inner layers too continue; # Requested by the parent layer, a list of internal layers and Capabilities. tables = [] keywords = {} tables.append("KnownLayers.Nl_group") tables.append("KnownLayers.LayerCapabilites") tables.append("SetLayer.sub_group") keywords["KnownLayers.Nwms"] = Nwms keywords["SetLayer.Nlayer"] = Nlayer keywords["KnownLayers.Nlayer"] = "SetLayer.Nlayer" keywords["SetLayer.Nset"] = Nset res = BD.ifsome_tables(cur, tables, keywords, "KnownLayers", "SetLayer") for parent_id, capabilities, subgroup_layers in res: if not subgroup_layers: # If there is no internal layers capabilities = form_layer(capabilities, Nlayer, server_URL) if parent_id != -1: # If the layer has a parent capabilities = form_layerInfo(cur, parent_id, capabilities) else: # Another group is formed from layer capabilities = form_layerGroup(cur, Nlayer) # Is the formation of sublayers capabilities = form_sublayers(cur, Nwms, subgroup_layers, capabilities,\ server_URL, list_layernoset, Nlayer) capabilities = capabilities + "</Layer>\t" # Create new node "Layer" text = dom.createTextNode("%s" % capabilities) external_Layer.appendChild(text) # transform tree in string texts = tag_service.toprettyxml(indent=' ', newl='\n') # transform psevdo codes in symbols texts = texts.replace("<", "<") texts = texts.replace(">", ">") texts = texts.replace(""", "\"") texts = texts.replace("&amp;", "&") print texts