2016-12-06 23:10:34 +00:00
|
|
|
# Copyright 2016 Mycroft AI, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Mycroft Core.
|
|
|
|
#
|
|
|
|
# Mycroft Core is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Mycroft Core is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
__author__ = 'augustnmonteiro'
|
|
|
|
|
2017-01-24 23:34:44 +00:00
|
|
|
# The following lines are replaced during the release process.
|
|
|
|
# START_VERSION_BLOCK
|
|
|
|
CORE_VERSION_MAJOR = 0
|
|
|
|
CORE_VERSION_MINOR = 8
|
2017-09-19 02:15:20 +00:00
|
|
|
CORE_VERSION_BUILD = 22
|
2017-01-24 23:34:44 +00:00
|
|
|
# END_VERSION_BLOCK
|
|
|
|
|
|
|
|
CORE_VERSION_STR = (str(CORE_VERSION_MAJOR) + "." +
|
|
|
|
str(CORE_VERSION_MINOR) + "." +
|
|
|
|
str(CORE_VERSION_BUILD))
|
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')
|
|
|
|
"""
|
|
|
|
major, minor, build = version_string.split('.')
|
|
|
|
major = int(major)
|
|
|
|
minor = int(minor)
|
|
|
|
build = int(build)
|
|
|
|
|
|
|
|
if CORE_VERSION_MAJOR > major:
|
|
|
|
return True
|
|
|
|
elif CORE_VERSION_MAJOR == major and CORE_VERSION_MINOR > minor:
|
|
|
|
return True
|
|
|
|
elif major == CORE_VERSION_MAJOR and minor == CORE_VERSION_MINOR and \
|
|
|
|
CORE_VERSION_BUILD >= build:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|