aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filter_plugins/__pycache__/filters.cpython-38.pycbin1027 -> 0 bytes
-rw-r--r--filter_plugins/filters.py43
-rw-r--r--filter_plugins/filters.yml6
3 files changed, 40 insertions, 9 deletions
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
--- a/filter_plugins/__pycache__/filters.cpython-38.pyc
+++ /dev/null
Binary files 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"
remember that computers suck.