Skip to content

Commit c3b1bad

Browse files
committed
Merge pull request #23 from clarkperkins/feature/version-fixes
Removed unused version things
2 parents 960c926 + 2a38ac2 commit c3b1bad

File tree

3 files changed

+41
-77
lines changed

3 files changed

+41
-77
lines changed

stackdio/client/__init__.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,45 @@
3232
from .region import RegionMixin
3333
from .settings import SettingsMixin
3434
from .stack import StackMixin
35-
from .version import _parse_version_string
3635

3736
logger = logging.getLogger(__name__)
3837
logger.addHandler(logging.NullHandler())
3938

4039

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+
4174
class StackdioClient(BlueprintMixin, FormulaMixin, AccountMixin, ImageMixin,
4275
RegionMixin, StackMixin, SettingsMixin, HttpMixin):
4376

@@ -60,13 +93,17 @@ def __init__(self, url=None, username=None, password=None, verify=True, cfg_file
6093

6194
if self.usable():
6295
try:
63-
_, self.version = _parse_version_string(self.get_version(raise_for_status=False))
96+
raw_version = self.get_version(raise_for_status=False)
97+
self.version = _get_server_version_info(raw_version)
6498
except MissingUrlException:
99+
raw_version = None
65100
self.version = None
66101

67102
if self.version and (self.version[0] != 0 or self.version[1] != 7):
68-
raise IncompatibleVersionException('Server version {0}.{1}.{2} not '
69-
'supported.'.format(**self.version))
103+
raise IncompatibleVersionException(
104+
'Server version {0} not supported. Please upgrade '
105+
'stackdio-cli to {1}.{2}.0 or higher.'.format(raw_version, *self.version)
106+
)
70107

71108
@property
72109
def url(self):

stackdio/client/stack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from .exceptions import StackException
1919
from .http import HttpMixin, get, post, put, delete
20-
from .version import deprecated
2120

2221

2322
class StackMixin(HttpMixin):

stackdio/client/version.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -97,78 +97,6 @@ def get_git_changeset():
9797
__version__ = get_version(VERSION)
9898

9999

100-
def _unsupported_function(func, current_version, accepted_versions):
101-
raise IncompatibleVersionException("%s: %s is not one of %s" %
102-
(func.__name__,
103-
".".join([str(v) for v in current_version]),
104-
list(accepted_versions)))
105-
106-
107-
def _parse_version_string(version_string):
108-
original_version_string = version_string
109-
comparisons = {
110-
"=": operator.eq,
111-
"!=": operator.ne,
112-
"<": operator.lt,
113-
">": operator.gt,
114-
"<=": operator.le,
115-
">=": operator.ge
116-
}
117-
118-
# Determine the comparison function
119-
comp_string = "="
120-
if version_string[0] in ["<", ">", "=", "!"]:
121-
offset = 1
122-
if version_string[1] == "=":
123-
offset += 1
124-
125-
comp_string = version_string[:offset]
126-
version_string = version_string[offset:]
127-
128-
# Check if the version appears compatible
129-
try:
130-
int(version_string[0])
131-
except ValueError:
132-
raise InvalidVersionStringException(original_version_string)
133-
134-
# String trailing info
135-
version_string = re.split("[a-zA-Z]", version_string)[0]
136-
if version_string[-1] == '.':
137-
version_string = version_string[:-1]
138-
version = version_string.split(".")
139-
140-
# Pad length to 3
141-
version += [0] * (3 - len(version))
142-
143-
# Convert to ints
144-
version = [int(num) for num in version]
145-
146-
try:
147-
return comparisons[comp_string], tuple(version)
148-
except KeyError:
149-
raise InvalidVersionStringException(original_version_string)
150-
151-
152-
def accepted_versions(*versions):
153-
def decorator(func):
154-
if not versions:
155-
return func
156-
157-
parsed_versions = [_parse_version_string(version_string)
158-
for version_string in versions]
159-
160-
@wraps(func)
161-
def wrapper(obj, *args, **kwargs):
162-
for parsed_version in parsed_versions:
163-
comparison, version = parsed_version
164-
if comparison(obj.version, version):
165-
return func(obj, *args, **kwargs)
166-
167-
return _unsupported_function(func, obj.version, versions)
168-
return wrapper
169-
return decorator
170-
171-
172100
def deprecated(func):
173101
"""
174102
This is a decorator which can be used to mark functions

0 commit comments

Comments
 (0)