Skip to content

Commit e406d33

Browse files
committed
For #28441: refactored support checks to handle future additions
1 parent a64c55b commit e406d33

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

shotgun_api3/shotgun.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,35 @@ def __init__(self, host, meta):
137137
self._ensure_json_supported()
138138

139139

140-
def _ensure_json_supported(self):
141-
"""Checks the server version supports the JSON api, raises an
140+
def _ensure_support(self, feature):
141+
"""Checks the server version supports a given feature, raises an
142142
exception if it does not.
143143
144-
:raises ShotgunError: The current server version does not support json
144+
:param feature: dict supported version and human label { 'version': (int, int, int), 'label': str }
145+
146+
:raises ShotgunError: The current server version does not [feature]
145147
"""
146-
if not self.version or self.version < (2, 4, 0):
147-
raise ShotgunError("JSON API requires server version 2.4 or "\
148-
"higher, server is %s" % (self.version,))
148+
149+
if not self.version or self.version < feature['version']:
150+
raise ShotgunError(
151+
"%s requires server version %s or higher, "\
152+
"server is %s" % (feature['label'], _version_str(feature['version']), _version_str(self.version))
153+
)
154+
155+
156+
def _ensure_json_supported(self):
157+
"""Wrapper for ensure_support"""
158+
self._ensure_support({
159+
'version': (2, 4, 0),
160+
'label': 'JSON API'
161+
})
149162

150163
def ensure_include_archived_projects(self):
151-
"""Checks the server version support include_archived_projects parameter
152-
to find.
153-
"""
154-
if not self.version or self.version < (5, 3, 14):
155-
raise ShotgunError("The include_archived_projects flag requires server version 5.3.14 or "\
156-
"higher, server is %s" % (self.version,))
164+
"""Wrapper for ensure_support"""
165+
self._ensure_support({
166+
'version': (5, 3, 14),
167+
'label': 'include_archived_projects parameter'
168+
})
157169

158170

159171
def __str__(self):
@@ -2208,4 +2220,6 @@ def _translate_filters_simple(sg_filter):
22082220

22092221
return condition
22102222

2211-
2223+
def _version_str(version):
2224+
"""Converts a tuple of int's to a '.' separated str"""
2225+
return '.'.join(map(str, version))

0 commit comments

Comments
 (0)