Repository navigation
Expand file tree
/
Copy pathwsdl.py
More file actions
350 lines (330 loc) · 15.7 KB
/
Copy pathwsdl.py
File metadata and controls
350 lines (330 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# onvif/utils/wsdl.py
import os
class ONVIFWSDL:
# Default base directory for WSDL files (Built-in)
# Included in the package
BASE_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "wsdl")
# Global custom WSDL directory - can be set once for all services
_custom_wsdl_dir = None
@classmethod
def set_custom_wsdl_dir(cls, custom_dir):
"""Set global custom WSDL directory for all services."""
cls._custom_wsdl_dir = custom_dir
@classmethod
def get_custom_wsdl_dir(cls):
"""Get current global custom WSDL directory."""
return cls._custom_wsdl_dir
@classmethod
def clear_custom_wsdl_dir(cls):
"""Clear custom WSDL directory, revert to built-in."""
cls._custom_wsdl_dir = None
@classmethod
def _get_base_dir(cls, custom_wsdl_dir=None):
"""Get the base WSDL directory, using custom directory if provided."""
# Priority: parameter > global setting > default
if custom_wsdl_dir:
return custom_wsdl_dir
elif cls._custom_wsdl_dir:
return cls._custom_wsdl_dir
else:
return cls.BASE_DIR
@classmethod
def _get_wsdl_map(cls, custom_wsdl_dir=None):
"""Get WSDL map with proper base directory."""
base_dir = cls._get_base_dir(custom_wsdl_dir)
# Default structure for WSDL files
# If custom_wsdl_dir is provided, use flat structure (direct filename)
# Otherwise, use the standard ONVIF directory structure
return {
"devicemgmt": {
"ver10": {
"path": os.path.join(base_dir, "devicemgmt.wsdl" if custom_wsdl_dir else "ver10/device/wsdl/devicemgmt.wsdl"),
"binding": "DeviceBinding",
"namespace": "http://www.onvif.org/ver10/device/wsdl",
}
},
"events": {
"ver10": {
"path": os.path.join(base_dir, "event-vs.wsdl" if custom_wsdl_dir else "ver10/events/wsdl/event-vs.wsdl"),
"binding": "EventBinding",
"namespace": "http://www.onvif.org/ver10/events/wsdl",
}
},
"pullpoint": {
"ver10": {
"path": os.path.join(base_dir, "event-vs.wsdl" if custom_wsdl_dir else "ver10/events/wsdl/event-vs.wsdl"),
"binding": "PullPointSubscriptionBinding",
"namespace": "http://www.onvif.org/ver10/events/wsdl",
}
},
"notification": {
"ver10": {
"path": os.path.join(base_dir, "event-vs.wsdl" if custom_wsdl_dir else "ver10/events/wsdl/event-vs.wsdl"),
"binding": "NotificationProducerBinding",
"namespace": "http://www.onvif.org/ver10/events/wsdl",
}
},
"subscription": {
"ver10": {
"path": os.path.join(base_dir, "event-vs.wsdl" if custom_wsdl_dir else "ver10/events/wsdl/event-vs.wsdl"),
"binding": "SubscriptionManagerBinding",
"namespace": "http://www.onvif.org/ver10/events/wsdl",
}
},
"accesscontrol": {
"ver10": {
"path": os.path.join(base_dir, "accesscontrol.wsdl" if custom_wsdl_dir else "ver10/pacs/accesscontrol.wsdl"),
"binding": "PACSBinding",
"namespace": "http://www.onvif.org/ver10/accesscontrol/wsdl",
}
},
"accessrules": {
"ver10": {
"path": os.path.join(base_dir, "accessrules.wsdl" if custom_wsdl_dir else "ver10/accessrules/wsdl/accessrules.wsdl"),
"binding": "AccessRulesBinding",
"namespace": "http://www.onvif.org/ver10/accessrules/wsdl",
}
},
"actionengine": {
"ver10": {
"path": os.path.join(base_dir, "actionengine.wsdl" if custom_wsdl_dir else "ver10/actionengine.wsdl"),
"binding": "ActionEngineBinding",
"namespace": "http://www.onvif.org/ver10/actionengine/wsdl",
}
},
"advancedsecurity": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "AdvancedSecurityServiceBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"jwt": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "JWTBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"keystore": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "KeystoreBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"tlsserver": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "TLSServerBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"dot1x": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "Dot1XBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"authorizationserver": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "AuthorizationServerBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"mediasigning": {
"ver10": {
"path": os.path.join(base_dir, "advancedsecurity.wsdl" if custom_wsdl_dir else "ver10/advancedsecurity/wsdl/advancedsecurity.wsdl"),
"binding": "MediaSigningBinding",
"namespace": "http://www.onvif.org/ver10/advancedsecurity/wsdl",
}
},
"analytics": {
"ver20": {
"path": os.path.join(base_dir, "analytics.wsdl" if custom_wsdl_dir else "ver20/analytics/wsdl/analytics.wsdl"),
"binding": "AnalyticsEngineBinding",
"namespace": "http://www.onvif.org/ver20/analytics/wsdl",
}
},
"ruleengine": {
"ver20": {
"path": os.path.join(base_dir, "ruleengine.wsdl" if custom_wsdl_dir else "ver20/analytics/wsdl/analytics.wsdl"),
"binding": "RuleEngineBinding",
"namespace": "http://www.onvif.org/ver20/analytics/wsdl",
}
},
"analyticsdevice": {
"ver10": {
"path": os.path.join(base_dir, "analyticsdevice.wsdl" if custom_wsdl_dir else "ver10/analyticsdevice.wsdl"),
"binding": "AnalyticsDeviceBinding",
"namespace": "http://www.onvif.org/ver10/analyticsdevice/wsdl",
}
},
"appmgmt": {
"ver10": {
"path": os.path.join(base_dir, "appmgmt.wsdl" if custom_wsdl_dir else "ver10/appmgmt/wsdl/appmgmt.wsdl"),
"binding": "AppManagementBinding",
"namespace": "http://www.onvif.org/ver10/appmgmt/wsdl",
}
},
"authenticationbehavior": {
"ver10": {
"path": os.path.join(base_dir, "authenticationbehavior.wsdl" if custom_wsdl_dir else "ver10/authenticationbehavior/wsdl/authenticationbehavior.wsdl"),
"binding": "AuthenticationBehaviorBinding",
"namespace": "http://www.onvif.org/ver10/authenticationbehavior/wsdl",
}
},
"credential": {
"ver10": {
"path": os.path.join(base_dir, "credential.wsdl" if custom_wsdl_dir else "ver10/credential/wsdl/credential.wsdl"),
"binding": "CredentialBinding",
"namespace": "http://www.onvif.org/ver10/credential/wsdl",
}
},
"deviceio": {
"ver10": {
"path": os.path.join(base_dir, "deviceio.wsdl" if custom_wsdl_dir else "ver10/deviceio.wsdl"),
"binding": "DeviceIOBinding",
"namespace": "http://www.onvif.org/ver10/deviceIO/wsdl",
}
},
"display": {
"ver10": {
"path": os.path.join(base_dir, "display.wsdl" if custom_wsdl_dir else "ver10/display.wsdl"),
"binding": "DisplayBinding",
"namespace": "http://www.onvif.org/ver10/display/wsdl",
}
},
"doorcontrol": {
"ver10": {
"path": os.path.join(base_dir, "doorcontrol.wsdl" if custom_wsdl_dir else "ver10/pacs/doorcontrol.wsdl"),
"binding": "DoorControlBinding",
"namespace": "http://www.onvif.org/ver10/doorcontrol/wsdl",
}
},
"imaging": {
"ver20": {
"path": os.path.join(base_dir, "imaging.wsdl" if custom_wsdl_dir else "ver20/imaging/wsdl/imaging.wsdl"),
"binding": "ImagingBinding",
"namespace": "http://www.onvif.org/ver20/imaging/wsdl",
}
},
"media": {
"ver10": {
"path": os.path.join(base_dir, "media.wsdl" if custom_wsdl_dir else "ver10/media/wsdl/media.wsdl"),
"binding": "MediaBinding",
"namespace": "http://www.onvif.org/ver10/media/wsdl",
},
},
"media2": {
"ver20": {
"path": os.path.join(base_dir, "media2.wsdl" if custom_wsdl_dir else "ver20/media/wsdl/media.wsdl"),
"binding": "Media2Binding",
"namespace": "http://www.onvif.org/ver20/media/wsdl",
},
},
"provisioning": {
"ver10": {
"path": os.path.join(base_dir, "provisioning.wsdl" if custom_wsdl_dir else "ver10/provisioning/wsdl/provisioning.wsdl"),
"binding": "ProvisioningBinding",
"namespace": "http://www.onvif.org/ver10/provisioning/wsdl",
},
},
"ptz": {
"ver20": {
"path": os.path.join(base_dir, "ptz.wsdl" if custom_wsdl_dir else "ver20/ptz/wsdl/ptz.wsdl"),
"binding": "PTZBinding",
"namespace": "http://www.onvif.org/ver20/ptz/wsdl",
},
},
"receiver": {
"ver10": {
"path": os.path.join(base_dir, "receiver.wsdl" if custom_wsdl_dir else "ver10/receiver.wsdl"),
"binding": "ReceiverBinding",
"namespace": "http://www.onvif.org/ver10/receiver/wsdl",
},
},
"recording": {
"ver10": {
"path": os.path.join(base_dir, "recording.wsdl" if custom_wsdl_dir else "ver10/recording.wsdl"),
"binding": "RecordingBinding",
"namespace": "http://www.onvif.org/ver10/recording/wsdl",
},
},
"replay": {
"ver10": {
"path": os.path.join(base_dir, "replay.wsdl" if custom_wsdl_dir else "ver10/replay.wsdl"),
"binding": "ReplayBinding",
"namespace": "http://www.onvif.org/ver10/replay/wsdl",
},
},
"schedule": {
"ver10": {
"path": os.path.join(base_dir, "schedule.wsdl" if custom_wsdl_dir else "ver10/schedule/wsdl/schedule.wsdl"),
"binding": "ScheduleBinding",
"namespace": "http://www.onvif.org/ver10/schedule/wsdl",
},
},
"search": {
"ver10": {
"path": os.path.join(base_dir, "search.wsdl" if custom_wsdl_dir else "ver10/search.wsdl"),
"binding": "SearchBinding",
"namespace": "http://www.onvif.org/ver10/search/wsdl",
},
},
"thermal": {
"ver10": {
"path": os.path.join(base_dir, "thermal.wsdl" if custom_wsdl_dir else "ver10/thermal/wsdl/thermal.wsdl"),
"binding": "ThermalBinding",
"namespace": "http://www.onvif.org/ver10/thermal/wsdl",
},
},
"uplink": {
"ver10": {
"path": os.path.join(base_dir, "uplink.wsdl" if custom_wsdl_dir else "ver10/uplink/wsdl/uplink.wsdl"),
"binding": "UplinkBinding",
"namespace": "http://www.onvif.org/ver10/uplink/wsdl",
},
},
}
WSDL_MAP = None # Will be initialized when first accessed
@classmethod
def _ensure_wsdl_map_initialized(cls):
"""Ensure WSDL_MAP is initialized with default values."""
if cls.WSDL_MAP is None:
cls.WSDL_MAP = cls._get_wsdl_map()
@classmethod
def get_definition(cls, service: str, version: str = "ver10", custom_wsdl_dir=None) -> dict:
"""
Return WSDL definition including path, binding and namespace.
Args:
service (str): The service name.
version (str): The service version. Defaults to "ver10".
custom_wsdl_dir (str, optional): Custom WSDL directory path. If provided,
returns definition using custom directory instead of default.
Returns:
dict: The service definition containing path, binding, and namespace.
Raises:
ValueError: If the service or version is not found.
FileNotFoundError: If the WSDL file does not exist.
"""
# Use custom WSDL map if custom directory is provided
if custom_wsdl_dir:
wsdl_map = cls._get_wsdl_map(custom_wsdl_dir)
else:
# Ensure default WSDL_MAP is initialized
cls._ensure_wsdl_map_initialized()
wsdl_map = cls.WSDL_MAP
# Safety check for None wsdl_map
if wsdl_map is None:
raise RuntimeError("Failed to initialize WSDL map")
if service not in wsdl_map:
raise ValueError(f"Unknown service: {service}")
if version not in wsdl_map[service]:
raise ValueError(f"Version {version} not available for {service}")
definition = wsdl_map[service][version]
if not os.path.exists(definition["path"]):
raise FileNotFoundError(f"WSDL file not found: {definition['path']}")
return definition