19 |
""" |
""" |
20 |
Maintain WMS Capabilities |
Maintain WMS Capabilities |
21 |
|
|
22 |
|
Inherits methods from WMSCapabilitiesParser |
23 |
|
|
24 |
class WMSCapabilities: |
class WMSCapabilities: |
25 |
__init__ (resource xor filename xor nothing) |
__init__ (resource xor filename xor nothing) |
26 |
|
|
27 |
getErrorMsg() |
getErrorMsg() |
28 |
|
|
29 |
fetchCapabilities(*resource) |
fetchCapabilities(resource) |
30 |
saveCapabilities(filename) |
saveCapabilities(filename) |
31 |
loadCapabilities(filename) |
loadCapabilities(filename) |
32 |
printCapabilities() |
printCapabilities() |
33 |
|
|
34 |
|
getVersion() |
35 |
|
|
36 |
Requirements: |
Requirements: |
37 |
- PyOGCLib <http://www.sourceforge.net/projects/pyogclib> |
- PyOGCLib <http://www.sourceforge.net/projects/pyogclib> |
38 |
|
|
71 |
from Thuban import _ |
from Thuban import _ |
72 |
|
|
73 |
from ogclib.WMSClient import WMSClient |
from ogclib.WMSClient import WMSClient |
74 |
|
from parser import WMSCapabilitiesParser |
75 |
|
|
76 |
class WMSCapabilities(WMSClient): |
class WMSCapabilities(WMSClient, WMSCapabilitiesParser): |
77 |
""" |
""" |
78 |
Thuban class to maintain capabilities. This class provides |
Thuban class to maintain capabilities. This class provides |
79 |
methods to fetch, save and load capabilities as well as methods to |
methods to fetch, save and load capabilities as well as methods to |
94 |
""" |
""" |
95 |
Initialises Capabilities with one optional parameter |
Initialises Capabilities with one optional parameter |
96 |
|
|
97 |
|
param can be either a URL or a filename: |
98 |
|
|
99 |
filename -- load capabilities from file |
filename -- load capabilities from file |
100 |
url -- fetch capabilities from network |
url -- fetch capabilities from network |
101 |
""" |
""" |
108 |
self.fetchCapabilities(parm[0]) |
self.fetchCapabilities(parm[0]) |
109 |
else: |
else: |
110 |
self.errorMsg \ |
self.errorMsg \ |
111 |
= _("Resource '%s' is neither local file nor URL") |
= _("Resource '%s' is neither local file nor URL") \ |
112 |
% parm[0] |
% parm[0] |
113 |
|
|
114 |
|
|
115 |
def getErrorMsg(self): |
def getErrorMsg(self): |
124 |
if not self.capabilities: |
if not self.capabilities: |
125 |
self.wmsVersion = "1.0" |
self.wmsVersion = "1.0" |
126 |
self.capabilities = self.getCapabilities(resource, self.wmsVersion) |
self.capabilities = self.getCapabilities(resource, self.wmsVersion) |
127 |
|
if not self.capabilities: |
128 |
|
self.wmsVersion = None |
129 |
|
|
130 |
|
if self.capabilities: |
131 |
|
self.grok(self.capabilities) |
132 |
|
|
133 |
|
|
134 |
def saveCapabilities(self, fname): |
def saveCapabilities(self, fname): |
141 |
out = open(fname, "w") |
out = open(fname, "w") |
142 |
out.write(self.capabilities) |
out.write(self.capabilities) |
143 |
out.close() |
out.close() |
144 |
except: |
except IOError: |
145 |
self.errorMsg = _("Can't open file '%s' for writing") % fname |
self.errorMsg = _("Can't open file '%s' for writing") % fname |
146 |
|
|
147 |
|
|
152 |
input = open(fname, "r") |
input = open(fname, "r") |
153 |
self.capabilities = input.read() |
self.capabilities = input.read() |
154 |
input.close() |
input.close() |
155 |
except: |
self.grok(self.capabilities) |
156 |
|
except IOError: |
157 |
self.errorMsg = _("Can't open file '%s' for reading") % fname |
self.errorMsg = _("Can't open file '%s' for reading") % fname |
158 |
|
|
159 |
|
|
163 |
print self.capabilities |
print self.capabilities |
164 |
|
|
165 |
|
|
166 |
|
def getVersion(self): |
167 |
|
""" |
168 |
|
Returns the WMS protocol version |
169 |
|
|
170 |
|
If no capabilities could be fetched, None is returned. |
171 |
|
""" |
172 |
|
return self.wmsVersion |
173 |
|
|
174 |
|
|
175 |
if __name__ == "__main__": |
if __name__ == "__main__": |
176 |
capabilities \ |
capabilities \ |
177 |
= WMSCapabilities("http://frida.intevation.org/cgi-bin/frida_wms?") |
= WMSCapabilities("http://frida.intevation.org/cgi-bin/frida_wms?") |
178 |
if capa.getErrorMsg() is None: |
if capabilities.getErrorMsg() is None: |
179 |
capa.saveCapabilities("frida_capabilities.xml") |
capabilities.saveCapabilities("frida_capabilities.xml") |
180 |
else: |
else: |
181 |
print "Error: " + capa.getErrorMsg() |
print "Error: " + capabilities.getErrorMsg() |