From 99000f116579866bb98254450bae50a6c00f8465 Mon Sep 17 00:00:00 2001 From: binary Date: Wed, 18 Nov 2020 09:39:18 +0100 Subject: Repology filter per binname and distribution --- filter_plugins/__pycache__/filters.cpython-38.pyc | Bin 1027 -> 0 bytes filter_plugins/filters.py | 43 +++++++++++++++++++--- filter_plugins/filters.yml | 6 +-- 3 files changed, 40 insertions(+), 9 deletions(-) delete mode 100644 filter_plugins/__pycache__/filters.cpython-38.pyc (limited to 'filter_plugins') diff --git a/filter_plugins/__pycache__/filters.cpython-38.pyc b/filter_plugins/__pycache__/filters.cpython-38.pyc deleted file mode 100644 index e52f396..0000000 Binary files a/filter_plugins/__pycache__/filters.cpython-38.pyc and /dev/null differ diff --git a/filter_plugins/filters.py b/filter_plugins/filters.py index efe0c43..168a4f7 100644 --- a/filter_plugins/filters.py +++ b/filter_plugins/filters.py @@ -9,17 +9,48 @@ class FilterModule(object): "repology": self.repology_filter } - def repology_filter(self, package, repository): + def repology_filter(self, package, distribution): """ Use repology.org API for getting generic package names accrossed different Unix systems. This allows us to use standard package names, and execute install tasks with a system-agnostic way. """ api_endpoint = "https://repology.org/api/v1/project/" + possible_keys = ["name", "binname", "srcname"] + package_key = "" - response = requests.get(f"{api_endpoint}/{package}") + # Retrieve all packages + responses = requests.get(f"{api_endpoint}/{package}").json() + valid_packages = [] - for res in response.json(): - if res["repo"] == repository: - return res + # Sort packages corresponding for the given + # distribution and name + for response in responses: + print(response) - return response.json()[0] + for possible_key in possible_keys: + try: + response[possible_key] + except KeyError: + continue + package_key = possible_key + + if package_key == "": + continue + + is_not_documentation = "doc" not in package and "doc" not in response[package_key] + is_valid_package = package in response[package_key] + is_valid_repo = distribution in response["repo"] + + if is_not_documentation and is_valid_package and is_valid_repo: + valid_packages.append(response[package_key]) + + # Try to the guess best package + if len(valid_packages) > 1: + guessed_packages = [] + for valid in valid_packages: + # package name matches exactly + if valid == package: + return [package] + + + return valid_packages diff --git a/filter_plugins/filters.yml b/filter_plugins/filters.yml index 8ffd742..dd69c03 100644 --- a/filter_plugins/filters.yml +++ b/filter_plugins/filters.yml @@ -8,10 +8,10 @@ tasks: - debug: - msg: "{{ item | repology }}" + msg: "{{ item | repology('openbsd') }}" loop: - - "AAA" - "firefox" - "neovim" - - "brrrrrrrr" + - "sshfs" + - "wireguard" -- cgit v1.2.3