24 |
|
|
25 |
getErrorMsg() |
getErrorMsg() |
26 |
|
|
27 |
fetchCapabilities (*resource) |
fetchCapabilities(*resource) |
28 |
saveCapabilities (filename) |
saveCapabilities(filename) |
29 |
loadCapabilities (filename) |
loadCapabilities(filename) |
30 |
printCapabilities () |
printCapabilities() |
31 |
|
|
32 |
Requirements: |
Requirements: |
33 |
- PyOGCLib <http://www.sourceforge.net/projects/pyogclib> |
- PyOGCLib <http://www.sourceforge.net/projects/pyogclib> |
54 |
|
|
55 |
# Assume the PyOGCLib to be checked out next to the thuban main directory |
# Assume the PyOGCLib to be checked out next to the thuban main directory |
56 |
pyogclib = "../../../PyOGCLib" |
pyogclib = "../../../PyOGCLib" |
57 |
if os.path.isdir (pyogclib) and os.path.isdir (pyogclib + "/ogclib"): |
if os.path.isdir(pyogclib) and os.path.isdir(pyogclib + "/ogclib"): |
58 |
path.insert (0, pyogclib) |
path.insert(0, pyogclib) |
59 |
|
|
60 |
# We use gettext, so we need to import it and hence need to adjust the |
# We use gettext, so we need to import it and hence need to adjust the |
61 |
# path again |
# path again |
62 |
if __name__ == "__main__": |
if __name__ == "__main__": |
63 |
path.insert (0, "../../") |
path.insert(0, "../../") |
64 |
|
|
65 |
# ---------------------------------------------------------------------- |
# ---------------------------------------------------------------------- |
66 |
|
|
68 |
|
|
69 |
from ogclib.WMSClient import WMSClient |
from ogclib.WMSClient import WMSClient |
70 |
|
|
71 |
class Capabilities (WMSClient): |
class WMSCapabilities(WMSClient): |
72 |
""" |
""" |
73 |
Thuban class to maintain capabilities. This class provides |
Thuban class to maintain capabilities. This class provides |
74 |
methods to fetch, save and load capabilities as well as methods to |
methods to fetch, save and load capabilities as well as methods to |
85 |
errorMsg = None |
errorMsg = None |
86 |
wmsVersion = None |
wmsVersion = None |
87 |
|
|
88 |
def __init__ (self, *parm): |
def __init__(self, *parm): |
89 |
""" |
""" |
90 |
Initialises Capabilities with one optional parameter |
Initialises Capabilities with one optional parameter |
91 |
|
|
94 |
""" |
""" |
95 |
|
|
96 |
if parm and parm[0]: |
if parm and parm[0]: |
97 |
if os.path.isfile (parm[0]): |
if os.path.isfile(parm[0]): |
98 |
self.loadCapabilities (parm[0]) |
self.loadCapabilities(parm[0]) |
99 |
else: |
else: |
100 |
if parm[0].find ("http://",0) == 0: |
if parm[0].find("http://", 0) == 0: |
101 |
self.fetchCapabilities (parm[0]) |
self.fetchCapabilities(parm[0]) |
102 |
else: |
else: |
103 |
self.errorMsg = _("Resource '%s' is neither local file nor URL") % parm[0] |
self.errorMsg \ |
104 |
|
= _("Resource '%s' is neither local file nor URL") |
105 |
|
% parm[0] |
106 |
|
|
107 |
|
|
108 |
def getErrorMsg (self): |
def getErrorMsg(self): |
109 |
return self.errorMsg |
return self.errorMsg |
110 |
|
|
111 |
|
|
112 |
def fetchCapabilities (self, resource): |
def fetchCapabilities(self, resource): |
113 |
"""Fetches the WMS capabilities from an Internet resource""" |
"""Fetches the WMS capabilities from an Internet resource""" |
114 |
|
|
115 |
self.wmsVersion = "1.1" |
self.wmsVersion = "1.1" |
119 |
self.capabilities = self.getCapabilities(resource, self.wmsVersion) |
self.capabilities = self.getCapabilities(resource, self.wmsVersion) |
120 |
|
|
121 |
|
|
122 |
def saveCapabilities (self, fname): |
def saveCapabilities(self, fname): |
123 |
"""Save capabilities to local file""" |
"""Save capabilities to local file""" |
124 |
|
|
125 |
if self.capabilities is None: |
if self.capabilities is None: |
126 |
self.errorMsg = _("No capabilities available") |
self.errorMsg = _("No capabilities available") |
127 |
else: |
else: |
128 |
try: |
try: |
129 |
out = open (fname, "w") |
out = open(fname, "w") |
130 |
out.write (self.capabilities) |
out.write(self.capabilities) |
131 |
out.close() |
out.close() |
132 |
except: |
except: |
133 |
self.errorMsg = _("Can't open file '%s' for writing") % fname |
self.errorMsg = _("Can't open file '%s' for writing") % fname |
134 |
|
|
135 |
|
|
136 |
def loadCapabilities (self, fname): |
def loadCapabilities(self, fname): |
137 |
"""Load capabilities from a local file""" |
"""Load capabilities from a local file""" |
138 |
|
|
139 |
try: |
try: |
140 |
input = open (fname, "r") |
input = open(fname, "r") |
141 |
self.capabilities = input.read () |
self.capabilities = input.read() |
142 |
input.close() |
input.close() |
143 |
except: |
except: |
144 |
self.errorMsg = _("Can't open file '%s' for reading") % fname |
self.errorMsg = _("Can't open file '%s' for reading") % fname |
145 |
|
|
146 |
|
|
147 |
def printCapabilities (self): |
def printCapabilities(self): |
148 |
"""Prints capabilities to stdout""" |
"""Prints capabilities to stdout""" |
149 |
|
|
150 |
print self.capabilities |
print self.capabilities |
152 |
|
|
153 |
|
|
154 |
if __name__ == "__main__": |
if __name__ == "__main__": |
155 |
capa = Capabilities("http://frida.intevation.org/cgi-bin/frida_wms?") |
capabilities \ |
156 |
|
= WMSCapabilities("http://frida.intevation.org/cgi-bin/frida_wms?") |
157 |
if capa.getErrorMsg() is None: |
if capa.getErrorMsg() is None: |
158 |
capa.saveCapabilities("frida_capabilities.xml") |
capa.saveCapabilities("frida_capabilities.xml") |
159 |
else: |
else: |