Skip to content

Commit 18358b5

Browse files
committed
For #28441: refactored support checks to handle future additions
1 parent 7c5625b commit 18358b5

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

shotgun_api3/shotgun.py

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

134134

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

145158
def ensure_include_archived_projects(self):
146-
"""Checks the server version support include_archived_projects parameter
147-
to find.
148-
"""
149-
if not self.version or self.version < (5, 3, 14):
150-
raise ShotgunError("The include_archived_projects flag requires server version 5.3.14 or "\
151-
"higher, server is %s" % (self.version,))
159+
"""Wrapper for ensure_support"""
160+
self._ensure_support({
161+
'version': (5, 3, 14),
162+
'label': 'include_archived_projects parameter'
163+
})
152164

153165

154166
def __str__(self):
@@ -2132,4 +2144,6 @@ def _translate_filters_simple(sg_filter):
21322144

21332145
return condition
21342146

2135-
2147+
def _version_str(version):
2148+
"""Converts a tuple of int's to a '.' separated str"""
2149+
return '.'.join(map(str, version))

0 commit comments

Comments
 (0)