[arch] fix -> AUR: not detecting some package updates

This commit is contained in:
Vinicius Moreira
2020-09-02 10:18:59 -03:00
parent b4b5dd3f6f
commit e4661e837a
2 changed files with 7 additions and 230 deletions

View File

@@ -1,25 +1,14 @@
import os
import re
from datetime import datetime
from pkg_resources import parse_version
from bauh.api.abstract.model import PackageStatus
from bauh.api.http import HttpClient
from bauh.gems.arch.model import ArchPackage
from bauh.view.util.translation import I18n
URL_PKG_DOWNLOAD = 'https://aur.archlinux.org/{}'
RE_LETTERS = re.compile(r'\.([a-zA-Z]+)-\d+$')
RE_VERSION_SPLIT = re.compile(r'[a-zA-Z]+|\d+|[\.\-_@#]+')
BAUH_PACKAGES = {'bauh', 'bauh-staging'}
RE_SFX = ('r', 're', 'release')
GA_SFX = ('ga', 'ge')
RC_SFX = ('rc',)
BETA_SFX = ('b', 'beta')
AL_SFX = ('alpha', 'alfa')
DEV_SFX = ('dev', 'devel', 'development')
V_SUFFIX_MAP = {s: {'c': sfxs[0], 'p': idx} for idx, sfxs in enumerate([RE_SFX, GA_SFX, RC_SFX, BETA_SFX, AL_SFX, DEV_SFX]) for s in sfxs}
class ArchDataMapper:
@@ -52,62 +41,13 @@ class ArchDataMapper:
pkg.url_download = URL_PKG_DOWNLOAD.format(package['URLPath']) if package.get('URLPath') else None
pkg.first_submitted = datetime.fromtimestamp(package['FirstSubmitted']) if package.get('FirstSubmitted') else None
pkg.last_modified = datetime.fromtimestamp(package['LastModified']) if package.get('LastModified') else None
pkg.update = self.check_update(pkg.version, pkg.latest_version, check_suffix=pkg.name in BAUH_PACKAGES)
pkg.update = self.check_update(pkg.version, pkg.latest_version)
@staticmethod
def check_update(version: str, latest_version: str, check_suffix: bool = False) -> bool:
def check_update(version: str, latest_version: str) -> bool:
if version and latest_version:
return parse_version(version) < parse_version(latest_version)
if check_suffix:
current_sfx = RE_LETTERS.findall(version)
latest_sf = RE_LETTERS.findall(latest_version)
if latest_sf and current_sfx:
current_sfx = current_sfx[0]
latest_sf = latest_sf[0]
current_sfx_data = V_SUFFIX_MAP.get(current_sfx.lower())
latest_sfx_data = V_SUFFIX_MAP.get(latest_sf.lower())
if current_sfx_data and latest_sfx_data:
nversion = version.split(current_sfx)[0]
nlatest = latest_version.split(latest_sf)[0]
if nversion == nlatest:
if current_sfx_data['c'] != latest_sfx_data['c']:
return latest_sfx_data['p'] < current_sfx_data['p']
else:
return ''.join(latest_version.split(latest_sf)) > ''.join(version.split(current_sfx))
return nlatest > nversion
latest_split = RE_VERSION_SPLIT.findall(latest_version)
current_split = RE_VERSION_SPLIT.findall(version)
for idx in range(len(latest_split)):
if idx < len(current_split):
latest_part = latest_split[idx]
current_part = current_split[idx]
if latest_part != current_part:
try:
dif = int(latest_part) - int(current_part)
if dif > 0:
return True
elif dif < 0:
return False
else:
continue
except ValueError:
if latest_part.isdigit():
return True
elif current_part.isdigit():
return False
else:
return latest_part > current_part
return False
def fill_package_build(self, pkg: ArchPackage):