diff options
Diffstat (limited to 'prometheus_pacman_exporter')
| -rw-r--r-- | prometheus_pacman_exporter/__init__.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/prometheus_pacman_exporter/__init__.py b/prometheus_pacman_exporter/__init__.py index e957662..c6bed96 100644 --- a/prometheus_pacman_exporter/__init__.py +++ b/prometheus_pacman_exporter/__init__.py @@ -75,6 +75,20 @@ BASE_QUERIES: tuple[PackageQuery, ...] = ( ), ) +PACMAN_UPDATEABLE_QUERY = PackageQuery( + (*PACMAN_BASE_COMMAND, "--upgrades"), + "updateable packages", + metrics.UPDATEABLE_PACKAGES, + empty_exit_codes=PACMAN_EMPTY_EXIT_CODES, +) + +CHECKUPDATES_QUERY = PackageQuery( + ("checkupdates",), + "updateable packages", + metrics.UPDATEABLE_PACKAGES, + accepted_exit_codes=(0, 2), +) + def print_version( ctx: click.Context, param: click.Parameter | None, value: bool @@ -150,8 +164,8 @@ def run_command( """ command_string = shlex.join(command) debug("Running command:", command_string, err=True) - result = subprocess.run(command, capture_output=True, encoding="utf-8", check=False) + result = subprocess.run(command, capture_output=True, encoding="utf-8", check=False) if result.returncode in accepted_exit_codes: return result @@ -266,26 +280,10 @@ def prometheus_pacman_exporter( debug(" verbose:", str(verbose_flag), err=True) debug(" quiet:", str(quiet_flag), err=True) - queries: list[PackageQuery] = [*BASE_QUERIES] - - if use_checkupdates_flag: - queries.append( - PackageQuery( - ("checkupdates",), - "updateable packages", - metrics.UPDATEABLE_PACKAGES, - (0, 2), - ) - ) - else: - queries.append( - PackageQuery( - (*PACMAN_BASE_COMMAND, "--upgrades"), - "updateable packages", - metrics.UPDATEABLE_PACKAGES, - empty_exit_codes=PACMAN_EMPTY_EXIT_CODES, - ) - ) + queries: list[PackageQuery] = [ + *BASE_QUERIES, + CHECKUPDATES_QUERY if use_checkupdates_flag else PACMAN_UPDATEABLE_QUERY, + ] if aur_flag: queries.append( |
