Skip to content

Instantly share code, notes, and snippets.

@ekohl ekohl/tiers.py
Last active Jun 13, 2019

Embed
What would you like to do?
A script to determine tiers
#!/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()
$ ./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
You can’t perform that action at this time.