daca2: Improve package sorting using natsort (#2505)

* daca2: Improve package sorting using natsort

This switches the external dependency from semver to natsort, and
improves comparison of packages where one or more of the packages do not
use semantic versioning (major.minor.patch).

This also makes daca2-download and daca2-getpackages work with python 3.
In theory, they should work with python 2 as well, but I have not tested
it.

* Make daca2 scripts executable

* Update hashbangs to python3

* Update usage description

To avoid specifying python version in the usage description, just
show how to execute the scripts and leave the rest to the shebangs.

* No need to specify python version in start_donate_cpu_server_test_local.sh

Leave it to the hashbang instead.
This commit is contained in:
Rikard Falkeborn 2020-01-26 18:39:37 +01:00 committed by Daniel Marjamäki
parent 211d2e336d
commit ba33c7f6cd
4 changed files with 12 additions and 23 deletions

View File

@ -27,7 +27,6 @@ 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
@ -37,7 +36,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
- travis_retry python3 -m pip install --user natsort
matrix:
# do notify immediately about it when a job of a build fails.

13
tools/daca2-download.py Normal file → Executable file
View File

@ -1,9 +1,9 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Downloads all daca2 source code packages.
#
# Usage:
# $ mkdir ~/daca2-packages && python daca2-download.py
# $ ./daca2-download.py
import subprocess
@ -12,7 +12,7 @@ import shutil
import glob
import os
import time
import semver
import natsort
DEBIAN = ('ftp://ftp.se.debian.org/debian/',
'ftp://ftp.debian.org/debian/')
@ -33,11 +33,8 @@ def wget(filepath):
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]
s = natsort.natsorted(names, key=lambda x: x[x.index('_')+1:x.index('.orig.tar')])
return s[-1]
def getpackages():

17
tools/daca2-getpackages.py Normal file → Executable file
View File

@ -1,11 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Get list of debian packages
#
# Usage:
#
# cd cppcheck/tools
# python daca2-getpackages.py
# ./daca2-getpackages.py
#
@ -19,7 +19,7 @@ import os
import re
import datetime
import time
import semver
import natsort
DEBIAN = ('ftp://ftp.de.debian.org/debian/',
'ftp://ftp.debian.org/debian/')
@ -39,15 +39,8 @@ def wget(filepath):
def latestvername(names):
if len(names) == 1:
return names[0]
try:
names.sort(cmp=semver.compare, key=lambda x: x[x.index('_')+1:x.index('.orig.tar')])
except ValueError:
# semver.compare() throws an exception if the version is not formatted
# like it is required by semver. For example 0.8 is not valid.
pass
return names[-1]
s = natsort.natsorted(names, key=lambda x: x[x.index('_')+1:x.index('.orig.tar')])
return s[-1]
def getpackages():

View File

@ -22,7 +22,7 @@ fi
if [ ! -f "${dacaathome_path}/packages.txt" ]
then
python "${cppcheck_tools_path}/daca2-getpackages.py" > "${dacaathome_path}/packages.txt"
"${cppcheck_tools_path}/daca2-getpackages.py" > "${dacaathome_path}/packages.txt"
fi
while :