2017-10-04 06:28:44 +00:00
|
|
|
# Copyright 2017 Mycroft AI Inc.
|
2016-12-06 23:10:34 +00:00
|
|
|
#
|
2017-10-04 06:28:44 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2016-12-06 23:10:34 +00:00
|
|
|
#
|
2017-10-04 06:28:44 +00:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2016-12-06 23:10:34 +00:00
|
|
|
#
|
2017-10-04 06:28:44 +00:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2016-12-06 23:10:34 +00:00
|
|
|
#
|
|
|
|
import json
|
2017-09-18 19:14:21 +00:00
|
|
|
|
2016-12-06 23:10:34 +00:00
|
|
|
from genericpath import exists, isfile
|
|
|
|
|
2017-09-18 18:55:58 +00:00
|
|
|
from mycroft.util.log import LOG
|
2016-12-06 23:10:34 +00:00
|
|
|
|
|
|
|
|
2017-01-24 23:34:44 +00:00
|
|
|
# The following lines are replaced during the release process.
|
|
|
|
# START_VERSION_BLOCK
|
2018-03-01 13:18:41 +00:00
|
|
|
CORE_VERSION_MAJOR = 18
|
|
|
|
CORE_VERSION_MINOR = 2
|
2018-05-18 00:40:28 +00:00
|
|
|
CORE_VERSION_BUILD = 6
|
2017-01-24 23:34:44 +00:00
|
|
|
# END_VERSION_BLOCK
|
|
|
|
|
2018-02-28 02:01:40 +00:00
|
|
|
CORE_VERSION_TUPLE = (CORE_VERSION_MAJOR,
|
|
|
|
CORE_VERSION_MINOR,
|
|
|
|
CORE_VERSION_BUILD)
|
|
|
|
CORE_VERSION_STR = '.'.join(map(str, CORE_VERSION_TUPLE))
|
2016-12-06 23:10:34 +00:00
|
|
|
|
|
|
|
|
2016-12-09 02:07:36 +00:00
|
|
|
class VersionManager(object):
|
|
|
|
__location = "/opt/mycroft/version.json"
|
2016-12-06 23:10:34 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2016-12-09 02:04:16 +00:00
|
|
|
def get():
|
2016-12-20 20:41:38 +00:00
|
|
|
if (exists(VersionManager.__location) and
|
|
|
|
isfile(VersionManager.__location)):
|
2016-12-06 23:10:34 +00:00
|
|
|
try:
|
2016-12-09 02:07:36 +00:00
|
|
|
with open(VersionManager.__location) as f:
|
2016-12-06 23:10:34 +00:00
|
|
|
return json.load(f)
|
2016-12-09 02:04:16 +00:00
|
|
|
except:
|
2016-12-20 20:41:38 +00:00
|
|
|
LOG.error("Failed to load version from '%s'"
|
|
|
|
% VersionManager.__location)
|
2016-12-09 02:04:16 +00:00
|
|
|
return {"coreVersion": None, "enclosureVersion": None}
|
2017-09-13 18:53:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_version(version_string):
|
|
|
|
"""
|
|
|
|
Check if current version is equal or higher than the
|
|
|
|
version string provided to the function
|
|
|
|
|
|
|
|
Args:
|
|
|
|
version_string (string): version string ('Major.Minor.Build')
|
|
|
|
"""
|
2018-02-28 02:01:40 +00:00
|
|
|
version_tuple = tuple(map(int, version_string.split('.')))
|
|
|
|
return CORE_VERSION_TUPLE >= version_tuple
|