From e6d692d9605850cf98153a4825e353898b9320a2 Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Sun, 24 Nov 2019 13:05:21 +0100 Subject: [PATCH] Fix daca2 using latest version of package (#2393) * Add semver import for sorting ls-lR list * Fix using latest release version of package * Import semver with pip in travis file --- .travis.yml | 2 ++ tools/daca2-download.py | 14 +++++++++++++- tools/daca2-getpackages.py | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 012bc160d..bf67d415e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ before_install: - travis_retry python2 -m pip install --user unittest2 - travis_retry python2 -m pip install --user pexpect # imported by tools/ci.py - travis_retry python2 -m pip install --user pygments + - travis_retry python2 -m pip install --user semver # Python 3 modules - travis_retry python3 -m pip install --user setuptools --upgrade - travis_retry python3 -m pip install --user pytest @@ -36,6 +37,7 @@ before_install: - travis_retry python3 -m pip install --user requests # imported by tools/pr.py - travis_retry python3 -m pip install --user pygments - travis_retry sudo python3 -m pip install demjson # installs jsonlint => sudo required + - travis_retry python3 -m pip install --user semver matrix: # do notify immediately about it when a job of a build fails. diff --git a/tools/daca2-download.py b/tools/daca2-download.py index 72fb9abd1..336e1555e 100644 --- a/tools/daca2-download.py +++ b/tools/daca2-download.py @@ -12,6 +12,7 @@ import shutil import glob import os import time +import semver DEBIAN = ('ftp://ftp.se.debian.org/debian/', 'ftp://ftp.debian.org/debian/') @@ -31,6 +32,14 @@ def wget(filepath): return False +def latestvername(names): + if len(names) == 1: + return names[0] + names.sort(cmp=semver.cmp, key=lambda x: x[x.index( + '_')+1:x.index('.orig.tar')-x.index('_')+1]) + return names[-1] + + def getpackages(): if not wget('ls-lR.gz'): return [] @@ -43,17 +52,20 @@ def getpackages(): path = None archives = [] filename = None + filenames = [] for line in lines: line = line.strip() if len(line) < 4: if filename: - archives.append(path + '/' + filename) + archives.append(path + '/' + latestvername(filenames)) path = None filename = None + filenames = [] elif line[:12] == './pool/main/': path = line[2:-1] elif path and '.orig.tar.' in line: filename = line[1 + line.rfind(' '):] + filenames.append(filename) for a in archives: print(a) diff --git a/tools/daca2-getpackages.py b/tools/daca2-getpackages.py index f4aa8bd97..6051a24e9 100644 --- a/tools/daca2-getpackages.py +++ b/tools/daca2-getpackages.py @@ -19,6 +19,7 @@ import os import re import datetime import time +import semver DEBIAN = ('ftp://ftp.de.debian.org/debian/', 'ftp://ftp.debian.org/debian/') @@ -37,6 +38,14 @@ def wget(filepath): return False +def latestvername(names): + if len(names) == 1: + return names[0] + names.sort(cmp=semver.cmp, key=lambda x: x[x.index( + '_')+1:x.index('.orig.tar')-x.index('_')+1]) + return names[-1] + + def getpackages(): if not wget('ls-lR.gz'): sys.exit(1) @@ -86,6 +95,7 @@ def getpackages(): previous_path = '' archives = [] filename = None + filenames = [] for line in lines: line = line.strip() if len(line) < 4: @@ -97,17 +107,19 @@ def getpackages(): if res2 is None: res2 = re.match(r'(.*)[-.][0-9.]+$', previous_path) if res1 is None or res2 is None or res1.group(1) != res2.group(1): - archives.append(path + '/' + filename) + archives.append(path + '/' + latestvername(filenames)) else: - archives[-1] = path + '/' + filename + archives[-1] = path + '/' + latestvername(filenames) if path: previous_path = path path = None filename = None + filenames = [] elif line.startswith('./pool/main/'): path = line[2:-1] elif path and line.endswith(('.orig.tar.gz', '.orig.tar.bz2')): filename = line[1 + line.rfind(' '):] + filenames.append(filename) return archives