Skip to content

Commit 2a38ac2

Browse files
author
Clark Perkins
committed
Be smarter about version parsing
1 parent f46f928 commit 2a38ac2

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

stackdio/client/__init__.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,40 @@
3737
logger.addHandler(logging.NullHandler())
3838

3939

40+
def _get_server_version_info(version_str):
41+
basic_info = version_str.split('.')
42+
43+
major = int(basic_info[0])
44+
minor = int(basic_info[1])
45+
46+
version_type = 'final'
47+
extra_id = 0
48+
49+
try:
50+
patch_v = int(basic_info[2])
51+
except ValueError:
52+
for vtype in ('a', 'b', 'rc'):
53+
if vtype in basic_info[2]:
54+
version_type = vtype
55+
idx = basic_info[2].find(vtype)
56+
patch_v = int(basic_info[:idx])
57+
extra_id = int(basic_info[2][idx + len(vtype):])
58+
59+
if version_type == 'final':
60+
raise ValueError('Invalid version: {}'.format(version_str))
61+
62+
if len(basic_info) > 3:
63+
for vtype in ('dev', 'post'):
64+
if basic_info[3].startswith(vtype):
65+
version_type = vtype
66+
extra_id = int(basic_info[3][len(vtype):])
67+
68+
if version_type == 'final':
69+
raise ValueError('Invalid version: {}'.format(version_str))
70+
71+
return major, minor, patch_v, version_type, extra_id
72+
73+
4074
class StackdioClient(BlueprintMixin, FormulaMixin, AccountMixin, ImageMixin,
4175
RegionMixin, StackMixin, SettingsMixin, HttpMixin):
4276

@@ -60,11 +94,12 @@ def __init__(self, url=None, username=None, password=None, verify=True, cfg_file
6094
if self.usable():
6195
try:
6296
raw_version = self.get_version(raise_for_status=False)
63-
self.version = raw_version.split('.')
97+
self.version = _get_server_version_info(raw_version)
6498
except MissingUrlException:
6599
raw_version = None
100+
self.version = None
66101

67-
if raw_version and (self.version[0] != 0 or self.version[1] != 7):
102+
if self.version and (self.version[0] != 0 or self.version[1] != 7):
68103
raise IncompatibleVersionException(
69104
'Server version {0} not supported. Please upgrade '
70105
'stackdio-cli to {1}.{2}.0 or higher.'.format(raw_version, *self.version)

0 commit comments

Comments
 (0)