fix bug on pkgver compare

This commit is contained in:
bgme 2023-08-15 01:30:42 +08:00
parent c0031235a6
commit 9187984b6b

View file

@ -2,24 +2,18 @@ import os
from collections import namedtuple from collections import namedtuple
import subprocess import subprocess
import re import re
from typing import Tuple, List, Dict from typing import List, Dict
from pkg_resources import parse_version as _parse_version
from packaging.version import Version # type: ignore from packaging.version import Version # type: ignore
def parse_arch_version(v: str) -> Tuple[int, Version]:
if ':' in v:
epoch = int(v.split(':', 1)[0])
else:
epoch = 0
return epoch, _parse_version(v)
class PkgNameInfo(namedtuple('PkgNameInfo', 'name, version, release, arch')): class PkgNameInfo(namedtuple('PkgNameInfo', 'name, version, release, arch')):
def __lt__(self, other) -> bool: def __lt__(self, other) -> bool:
if self.name != other.name or self.arch != other.arch: if self.name != other.name or self.arch != other.arch:
return NotImplemented return NotImplemented
if self.version != other.version: if self.version != other.version:
return parse_arch_version(self.version) < parse_arch_version(other.version) p = subprocess.Popen(["vercmp", self.version, other.version], stdout=subprocess.PIPE)
output = p.stdout.read()
return int(output) < 0
return float(self.release) < float(other.release) return float(self.release) < float(other.release)
def __gt__(self, other) -> bool: def __gt__(self, other) -> bool: