Add semver import for sorting ls-lR list (#1735)

This commit is contained in:
Bo Rydberg 2019-03-12 06:14:32 +01:00 committed by Daniel Marjamäki
parent 4ababeb704
commit e61343f213
2 changed files with 29 additions and 2 deletions

View File

@ -13,6 +13,8 @@ import glob
import os
import time
import semver
DEBIAN = ('ftp://ftp.se.debian.org/debian/',
'ftp://ftp.debian.org/debian/')
@ -31,6 +33,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 +53,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)

View File

@ -16,6 +16,8 @@ import os
import datetime
import time
import semver
DEBIAN = ('ftp://ftp.se.debian.org/debian/',
'ftp://ftp.debian.org/debian/')
@ -33,6 +35,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 []
@ -79,17 +89,21 @@ def getpackages():
path = None
archives = []
filename = None
filenames = []
for line in lines:
line = line.strip()
if len(line) < 4:
if filename:
archives.append(DEBIAN[0] + path + '/' + filename)
archives.append(DEBIAN[0] + path + '/' +
latestvername(filenames))
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