Last active
January 8, 2019 14:54
-
-
Save grejppi/734700b8f8aee287352fc2d9e3f02c53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import defaultdict | |
import lilv | |
# FIXME: not sure if this is correct... | |
using_old_lilv = "lilv_nodes_begin" in dir(lilv) | |
show_details = '-d' in sys.argv or '--details' in sys.argv | |
required_total = defaultdict(set) | |
optional_total = defaultdict(set) | |
w = lilv.World() | |
w.load_all() | |
plugins = w.get_all_plugins() | |
for plugin in plugins: | |
required = plugin.get_required_features() | |
optional = plugin.get_optional_features() | |
uri = str(plugin.get_uri()) | |
if using_old_lilv: | |
it = lilv.lilv_nodes_begin(required.me) | |
while not lilv.lilv_nodes_is_end(required, it): | |
feat = lilv.lilv_node_as_uri(lilv.lilv_nodes_get(required, it)) | |
it = lilv.lilv_nodes_next(required, it) | |
required_total[feat].add(uri) | |
it = lilv.lilv_nodes_begin(optional.me) | |
while not lilv.lilv_nodes_is_end(optional, it): | |
feat = lilv.lilv_node_as_uri(lilv.lilv_nodes_get(optional, it)) | |
it = lilv.lilv_nodes_next(optional, it) | |
optional_total[feat].add(uri) | |
else: | |
for feature in required: | |
required_total[str(feature)].add(uri) | |
for feature in optional: | |
optional_total[str(feature)].add(uri) | |
def bar(width, total, required, optional): | |
r = required / total | |
o = optional / total | |
r_width = round(r * width) | |
o_width = round(o * width) | |
r_bar = '\u2588' * r_width | |
o_bar = '\u2592' * o_width | |
return (r_bar + o_bar).ljust(width) | |
def fmt(s): | |
return s.replace('-', '\u2500').replace('+', '\u253c').replace('|', '\u2502') | |
if using_old_lilv: | |
total = plugins.size() | |
else: | |
total = len(plugins) | |
print("```") | |
print(total, "plugins installed on the system.") | |
print() | |
if show_details: | |
feature_uri_length = max((len(uri) for uri in required_total)) + len("<> ") | |
print(fmt("feature".ljust(feature_uri_length) + "| required by")) | |
for feature in sorted(required_total): | |
print(fmt("-" * feature_uri_length + "+------------")) | |
for i, plugin in enumerate(sorted(required_total[feature])): | |
if i == 0: | |
a = "<{}>".format(feature).ljust(feature_uri_length) | |
else: | |
a = " " * feature_uri_length | |
print(fmt(a + "| <" + plugin + ">")) | |
print() | |
print() | |
all_features = set() | |
all_features = all_features.union(set(required_total.keys())) | |
all_features = all_features.union(set(optional_total.keys())) | |
features_sorted = [(uri, len(required_total[uri]), len(optional_total[uri])) for uri in all_features] | |
features_sorted.sort(key=lambda x: x[0]) | |
features_sorted.sort(key=lambda x: x[2]) | |
features_sorted.sort(key=lambda x: x[1]) | |
features_sorted.reverse() | |
print(fmt("0% 100%| required | optional | feature")) | |
print(fmt("----------+----------+----------+---------")) | |
for uri, required, optional in features_sorted: | |
print(fmt("{}| {} | {} | <{}>".format(bar(10, total, required, optional), str(required).rjust(8), str(optional).rjust(8), uri))) | |
print("```") |
SpotlightKid
commented
Jan 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment