Last active
June 13, 2019 08:27
-
-
Save ekohl/e902cc5847e6453ed1007d951c05df80 to your computer and use it in GitHub Desktop.
A script to determine tiers
This file contains 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
#!/usr/bin/env python3 | |
# Requires Python 3.7 for dataclasses | |
import argparse | |
import json | |
from dataclasses import dataclass | |
@dataclass(eq=True, frozen=True, order=True) | |
class Module: | |
author: str | |
name: str | |
def __str__(self): | |
return f'{self.author}/{self.name}' | |
def get_module(module): | |
full_name = module.replace('-', '/', 1).lower() | |
author, name = full_name.split('/', 1) | |
return Module(author, name) | |
def handle_metadata(metadata, authors): | |
data = json.load(metadata) | |
module = get_module(data['name']) | |
dependencies = [get_module(dependency['name']) for dependency in data.get('dependencies', [])] | |
return module, {dependency for dependency in dependencies if dependency.author in authors} | |
def get_tiers(metadata, authors): | |
modules = dict(handle_metadata(data, authors) for data in metadata) | |
handled = set() | |
tiers = [] | |
while modules: | |
tier = {module for module, dependencies in modules.items() | |
if handled.issuperset(dependencies)} | |
for module in tier: | |
del modules[module] | |
tiers.append(tier) | |
handled.update(tier) | |
return tiers | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--author', action='append') | |
parser.add_argument('metadata', nargs='+', type=argparse.FileType('r')) | |
args = parser.parse_args() | |
for tier, modules in enumerate(get_tiers(args.metadata, args.author)): | |
print(f'Tier {tier}') | |
for module in sorted(modules): | |
print(f' {module}') | |
if __name__ == '__main__': | |
main() |
This file contains 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
$ ./bin/tiers --author katello --author theforeman modules/puppet-*/metadata.json | |
Tier 0 | |
katello/certs | |
katello/qpid | |
theforeman/dhcp | |
theforeman/dns | |
theforeman/foreman | |
theforeman/git | |
theforeman/puppet | |
theforeman/tftp | |
Tier 1 | |
katello/candlepin | |
katello/pulp | |
theforeman/foreman_proxy | |
Tier 2 | |
katello/foreman_proxy_content | |
katello/katello | |
Tier 3 | |
katello/katello_devel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment