fix #46, #88, #103: Correct version parsing with build number and a trash

Esse commit está contido em:
Victor Nakoryakov
2013-09-24 13:15:43 +04:00
commit 2ed47f2d1a
3 arquivos alterados com 35 adições e 12 exclusões
+2
Ver Arquivo
@@ -106,6 +106,8 @@ Changelog
* Fix #93, #57, #8: Custom compile and link flags can be passed as `ino build` arguments
* Fix #60, #63: Custom `make` tool command can be passed as `ino build` argument
* Fix #23, #28: `make` is searched within Arduino IDE binaries as well
* Fix #88, #103: Correct version parsing for some distributions that mangle it
* Fix #46: Taking build number into account in version string
0.3.5
* Fix #62: Include `MIT-LICENSE.txt` in the tarball.
+22 -8
Ver Arquivo
@@ -23,9 +23,9 @@ from ino.utils import format_available_options
from ino.exc import Abort
class Version(namedtuple('Version', 'major minor')):
class Version(namedtuple('Version', 'major minor build')):
regex = re.compile(ur'^\d+(\.\d+)?')
regex = re.compile(ur'^([^:]+:)?(\d+(\.\d+(\.\d+)?)?)')
@classmethod
def parse(cls, s):
@@ -34,20 +34,34 @@ class Version(namedtuple('Version', 'major minor')):
# 0022ubuntu0.1
# 0022-macosx-20110822
# 1.0
# We have to extract a 2-int-tuple (major, minor)
# 1:1.0.5+dfsg2-1
# We have to extract a 3-int-tuple (major, minor, build)
match = cls.regex.match(s)
if not match:
raise Abort("Could not parse Arduino library version: %s" % s)
v = match.group(0)
# v is numbers possibly split by dots without a trash
v = match.group(2)
if v.startswith('0'):
return cls(0, int(v))
return cls(*map(int, v.split('.')))
# looks like old 0022 or something like that
return cls(0, int(v), 0)
parts = map(int, v.split('.'))
# append nulls if they were not explicit
while len(parts) < 3:
parts.append(0)
return cls(*parts)
def as_int(self):
return self.major * 100 + self.minor
if not self.major:
return self.minor
return self.major * 100 + self.minor * 10 + self.build
def __str__(self):
return '%s.%s' % self
return '%s.%s.%s' % self
class Environment(dict):
+11 -4
Ver Arquivo
@@ -7,7 +7,14 @@ from ino.environment import Version
class TestVersion(object):
def test_parsing(self):
assert_equal(Version.parse('0022'), (0, 22))
assert_equal(Version.parse('0022ubuntu0.1'), (0, 22))
assert_equal(Version.parse('0022-macosx-20110822'), (0, 22))
assert_equal(Version.parse('1.0'), (1, 0))
assert_equal(Version.parse('0022'), (0, 22, 0))
assert_equal(Version.parse('0022ubuntu0.1'), (0, 22, 0))
assert_equal(Version.parse('0022-macosx-20110822'), (0, 22, 0))
assert_equal(Version.parse('1.0'), (1, 0, 0))
assert_equal(Version.parse('1:1.0.5+dfsg2-1'), (1, 0, 5))
def test_int_conversion(self):
assert_equal(Version(0, 22, 0).as_int(), 22)
assert_equal(Version(1, 0, 0).as_int(), 100)
assert_equal(Version(1, 0, 5).as_int(), 105)
assert_equal(Version(1, 5, 1).as_int(), 151)