forked from platformio/platformio-core
Improve semiversion detection
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import struct
|
||||||
from os import remove
|
from os import remove
|
||||||
from os.path import isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
@ -42,26 +43,32 @@ class Upgrader(object):
|
|||||||
self.from_version = self.version_to_int(from_version)
|
self.from_version = self.version_to_int(from_version)
|
||||||
self.to_version = self.version_to_int(to_version)
|
self.to_version = self.version_to_int(to_version)
|
||||||
|
|
||||||
|
self._upgraders = (
|
||||||
|
(self.version_to_int("0.9.0"), self._upgrade_to_0_9_0),
|
||||||
|
(self.version_to_int("1.0.0"), self._upgrade_to_1_0_0)
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def version_to_int(version):
|
def version_to_int(version):
|
||||||
intver = int(re.sub(r"[^\d]+", "", version))
|
match = re.match(r"(\d+)\.(\d+)\.(\d+)(\D+)?", version)
|
||||||
if "dev" in version:
|
assert match is not None and len(match.groups()) is 4
|
||||||
intver -= 1
|
verchrs = [chr(int(match.group(i))) for i in range(1, 4)]
|
||||||
return intver
|
verchrs.append(chr(255 if match.group(4) is None else 0))
|
||||||
|
return struct.unpack(">I", "".join(verchrs))
|
||||||
|
|
||||||
def run(self, ctx):
|
def run(self, ctx):
|
||||||
if self.from_version > self.to_version:
|
if self.from_version > self.to_version:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
result = [True]
|
result = [True]
|
||||||
for v in (90, 110):
|
for item in self._upgraders:
|
||||||
if self.from_version >= v:
|
if self.from_version >= item[0]:
|
||||||
continue
|
continue
|
||||||
result.append(getattr(self, "_upgrade_to_%d" % v)(ctx))
|
result.append(item[1](ctx))
|
||||||
|
|
||||||
return all(result)
|
return all(result)
|
||||||
|
|
||||||
def _upgrade_to_90(self, ctx): # pylint: disable=R0201
|
def _upgrade_to_0_9_0(self, ctx): # pylint: disable=R0201
|
||||||
prev_platforms = []
|
prev_platforms = []
|
||||||
|
|
||||||
# remove platform's folder (obsoleted package structure)
|
# remove platform's folder (obsoleted package structure)
|
||||||
@ -82,7 +89,7 @@ class Upgrader(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _upgrade_to_110(self, ctx): # pylint: disable=R0201
|
def _upgrade_to_1_0_0(self, ctx): # pylint: disable=R0201
|
||||||
# install "ldscripts" package
|
# install "ldscripts" package
|
||||||
if "titiva" in PlatformFactory.get_platforms(installed=True).keys():
|
if "titiva" in PlatformFactory.get_platforms(installed=True).keys():
|
||||||
ctx.invoke(cmd_install, platforms=["titiva"])
|
ctx.invoke(cmd_install, platforms=["titiva"])
|
||||||
|
Reference in New Issue
Block a user