From 3593f50aedce5544e7a03e85421ea4b9c1752462 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 14 Apr 2020 18:45:18 +0200 Subject: Remove debugging prints and simplify source package parsing --- .local/bin/zypper-wassup | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.local/bin/zypper-wassup b/.local/bin/zypper-wassup index 10e4826..6486367 100755 --- a/.local/bin/zypper-wassup +++ b/.local/bin/zypper-wassup @@ -19,6 +19,15 @@ ZYPPER_PATTERN = re.compile( re.MULTILINE ) +# Using http://ftp.rpm.org/max-rpm/ch-rpm-file-format.html to make a +# few assumptions, e.g. versions can't contain hyphens. +SOURCERPM_PATTERN = re.compile( + r'\.'.join(( + '-'.join(('(?P.+)', '(?P[^-]+)', '(?P[^-]+)')), + '(?:no)?src', + 'rpm' +))) + def execute(command): return run(command, check=True, text=True, capture_output=True).stdout @@ -34,25 +43,15 @@ def zypper_list_updates(): def source_package_name(package): - # Using http://ftp.rpm.org/max-rpm/ch-rpm-file-format.html to make - # a few assumptions, e.g. versions can't contain hyphens. - pattern = r'\.'.join(( - '-'.join(('(?P.+)', '(?P[^-]+)', '(?P[^-]+)')), - r'(?:no)?src', - r'rpm' - )) - match = re.fullmatch(pattern, package) - if match is None: - print(pattern) - print(package) + if (match := SOURCERPM_PATTERN.fullmatch(package)) is None: + raise Exception(f'{package} does not match "{SOURCERPM_PATTERN}".') + return match.group('name') def sort_by_source_package(packages): sorted_packages = defaultdict(list) - print() - for p in packages: source_pkgs = execute( ('rpm', '--query', '--queryformat', r'%{SOURCERPM}\n', p.package) -- cgit v1.2.3