Make versions list sorted for Vanilla and HDP
Right now the list is not sorted. Probably the versions order in the list is OS dependent. In my case 2.3.0 came before 1.2.1 in UI, which is not pretty. The natural ordering is applied to handle cases like 2.2 < 2.13 (lexicographical order will return that 2.2 > 2.13) Change-Id: I3a98549ff8a369ea202095e8070f65483e0bd099
This commit is contained in:
parent
4d150db7d5
commit
9d58c11db8
@ -15,6 +15,8 @@
|
||||
|
||||
import os
|
||||
|
||||
from sahara.utils import general
|
||||
|
||||
|
||||
class VersionHandlerFactory():
|
||||
versions = None
|
||||
@ -25,10 +27,12 @@ class VersionHandlerFactory():
|
||||
def get_instance():
|
||||
if not VersionHandlerFactory.initialized:
|
||||
src_dir = os.path.join(os.path.dirname(__file__), '')
|
||||
VersionHandlerFactory.versions = [name[8:].replace('_', '.')
|
||||
for name in os.listdir(src_dir)
|
||||
if os.path.isdir(
|
||||
os.path.join(src_dir, name))]
|
||||
versions = [name[8:].replace('_', '.')
|
||||
for name in os.listdir(src_dir)
|
||||
if os.path.isdir(os.path.join(src_dir, name))]
|
||||
versions.sort(key=general.natural_sort_key)
|
||||
VersionHandlerFactory.versions = versions
|
||||
|
||||
VersionHandlerFactory.modules = {}
|
||||
for version in VersionHandlerFactory.versions:
|
||||
module_name = ('sahara.plugins.hdp.versions.version_{0}.'
|
||||
|
@ -16,6 +16,8 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
from sahara.utils import general
|
||||
|
||||
|
||||
class VersionFactory():
|
||||
versions = None
|
||||
@ -26,11 +28,14 @@ class VersionFactory():
|
||||
def get_instance():
|
||||
if not VersionFactory.initialized:
|
||||
src_dir = os.path.join(os.path.dirname(__file__), '')
|
||||
VersionFactory.versions = (
|
||||
versions = (
|
||||
[name[1:].replace('_', '.')
|
||||
for name in os.listdir(src_dir)
|
||||
if (os.path.isdir(os.path.join(src_dir, name))
|
||||
and re.match(r'^v\d+_\d+_\d+$', name))])
|
||||
versions.sort(key=general.natural_sort_key)
|
||||
VersionFactory.versions = versions
|
||||
|
||||
VersionFactory.modules = {}
|
||||
for version in VersionFactory.versions:
|
||||
module_name = 'sahara.plugins.vanilla.v%s.versionhandler' % (
|
||||
|
@ -13,6 +13,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import re
|
||||
|
||||
import six
|
||||
|
||||
from sahara import conductor as c
|
||||
@ -24,6 +26,8 @@ from sahara.utils.notification import sender
|
||||
conductor = c.API
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
NATURAL_SORT_RE = re.compile('([0-9]+)')
|
||||
|
||||
|
||||
def find_dict(iterable, **rules):
|
||||
"""Search for dict in iterable of dicts using specified key-value rules."""
|
||||
@ -61,6 +65,13 @@ def get_by_id(lst, id):
|
||||
return None
|
||||
|
||||
|
||||
# Taken from http://stackoverflow.com/questions/4836710/does-
|
||||
# python-have-a-built-in-function-for-string-natural-sort
|
||||
def natural_sort_key(s):
|
||||
return [int(text) if text.isdigit() else text.lower()
|
||||
for text in re.split(NATURAL_SORT_RE, s)]
|
||||
|
||||
|
||||
def change_cluster_status(cluster, status, status_description=None):
|
||||
if cluster is None:
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user