[elbe-devel] [PATCH] pkgutils: care about version numbers of packages
Torben Hohn
torben.hohn at linutronix.de
Tue May 15 15:36:42 CEST 2018
The current python-apt workaround code always downloads the last package
mentioned in the Packages file for a given package name. This is not
always the latest package.
This implements a minimalisic version comparision that is able to
download the latest elbe-bootstrap package and therefore fixes the
issue mentioned on github with the id #145.
However this will not work for all version strings that are allowed
in Debian.
This should be backported to elbe-2.x because as mentioned in #145
the issue is hard to decode.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/pkgutils.py | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
index 02c6d995..84675a9c 100644
--- a/elbepack/pkgutils.py
+++ b/elbepack/pkgutils.py
@@ -21,6 +21,8 @@ import hashlib
from tempfile import mkdtemp
from elbepack.shellhelper import CommandError, system
+from itertools import izip_longest
+from pkg_resources import parse_version as V
try:
from apt_pkg import TagFile
@@ -89,6 +91,19 @@ def get_initrd_pkg(prj, defs):
return initrdname
+def version_ge(ver_a, ver_b):
+ for a,b in izip_longest( ver_a.split('+'), ver_b.split('+') ):
+ if a is None:
+ return False
+ if b is None:
+ return True
+ if V(a) < V(b):
+ return False
+
+ # when we come here
+ # the 2 versions are probably equal
+ return True
+
def get_url(arch, suite, target_pkg, mirror, comp='main'):
try:
pack_url = "%s/dists/%s/%s/binary-%s/Packages" % (
@@ -99,9 +114,19 @@ def get_url(arch, suite, target_pkg, mirror, comp='main'):
packages = [x for x in packages if x.startswith("Filename")]
packages = [x for x in packages if x.find(target_pkg) != -1]
- tmp = packages.pop()
- urla = tmp.split()
+ # detect package with latest version number
+ latest_version_str = '0+deb0u0+jessie0'
+ latest_version_pos = 0
+ cnt = 0
+ for x in packages:
+ # extract version from path/name_version_arch
+ version = x.split('_')[1]
+ if version_ge(version, latest_version_str):
+ latest_version_str = version
+ latest_version_pos = cnt
+ urla = packages[latest_version_pos].split()
url = "%s/%s" % (mirror.replace("LOCALMACHINE", "localhost"), urla[1])
+
except IOError:
url = ""
except IndexError:
--
2.11.0
More information about the elbe-devel
mailing list