Skip to content

Commit e7168a3

Browse files
author
Clark Perkins
committed
Fixed version parsing
1 parent ee264ea commit e7168a3

File tree

1 file changed

+6
-37
lines changed

1 file changed

+6
-37
lines changed

stackdio/client/__init__.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
# limitations under the License.
1616
#
1717

18+
from __future__ import unicode_literals
19+
1820
import logging
1921

22+
from pkg_resources import parse_version
2023
from .account import AccountMixin
2124
from .blueprint import BlueprintMixin
2225
from .config import StackdioConfig
@@ -37,44 +40,10 @@
3740
logger.addHandler(logging.NullHandler())
3841

3942

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-
7443
class StackdioClient(BlueprintMixin, FormulaMixin, AccountMixin, ImageMixin,
7544
RegionMixin, StackMixin, SettingsMixin, HttpMixin):
7645

77-
def __init__(self, url=None, username=None, password=None, verify=True, cfg_file=None):
46+
def __init__(self, url=None, username=None, password=None, verify=None, cfg_file=None):
7847
self.config = StackdioConfig(cfg_file)
7948

8049
self._password = self.config.get_password()
@@ -94,12 +63,12 @@ def __init__(self, url=None, username=None, password=None, verify=True, cfg_file
9463
if self.usable():
9564
try:
9665
raw_version = self.get_version(raise_for_status=False)
97-
self.version = _get_server_version_info(raw_version)
66+
self.version = parse_version(raw_version)
9867
except MissingUrlException:
9968
raw_version = None
10069
self.version = None
10170

102-
if self.version and (self.version[0] != 0 or self.version[1] != 8):
71+
if self.version and not self.version.base_version.startswith('0.8'):
10372
raise IncompatibleVersionException(
10473
'Server version {0} not supported. Please upgrade '
10574
'stackdio-cli to {1}.{2}.0 or higher.'.format(raw_version, *self.version)

0 commit comments

Comments
 (0)