From 19ac81a663e0d7adfb38f2139d4f73a1dfaae1ea Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Date: Nov 28 2018 16:36:52 +0000 Subject: summarize-module: add version and context to output Signed-off-by: Rafael dos Santos --- diff --git a/_fedmod/cli.py b/_fedmod/cli.py index 26c7ac4..a70e90a 100644 --- a/_fedmod/cli.py +++ b/_fedmod/cli.py @@ -198,6 +198,8 @@ def lint(modulemd, min_level): type=click.Path(exists=True), help="Additional modulemd files to check." " Can be given multiple times.") -def summarize(modules, add_file): +@click.option("--tree", "-t", is_flag=True, default=False, + help="Print output as a tree") +def summarize(modules, add_file, tree): """Prints a summary of available modules""" - summarize_modules(modules, add_file) + summarize_modules(modules, add_file, tree) diff --git a/_fedmod/modulemd_summarizer.py b/_fedmod/modulemd_summarizer.py index 31d66f5..ad4f8d9 100644 --- a/_fedmod/modulemd_summarizer.py +++ b/_fedmod/modulemd_summarizer.py @@ -29,11 +29,15 @@ import smartcols from . import _repodata -def _print_summary(profiles, sdefaults, pdefaults, restrict_to): +def _print_summary(profiles, sdefaults, pdefaults, restrict_to, as_tree): tb = smartcols.Table() cl = tb.new_column('Name') + cl.tree = as_tree cl_strm = tb.new_column('Stream') + cl_ver = tb.new_column('Version') + cl_ctxt = tb.new_column('Context') cl_prof = tb.new_column('Profiles') + parent_ln = {} for nsvc, plist in sorted(profiles.items()): modname, sname, version, context = nsvc.split(':') @@ -43,9 +47,19 @@ def _print_summary(profiles, sdefaults, pdefaults, restrict_to): def is_def_strm(s): return s == sdefaults.get(modname, '') - ln = tb.new_line() + if as_tree: + pl = parent_ln.get(modname, None) + if pl is None: + pl = parent_ln.setdefault(modname, tb.new_line()) + pl[cl] = modname + else: + pl = None + + ln = tb.new_line(pl) ln[cl] = modname ln[cl_strm] = sname + ' [d]' * is_def_strm(sname) + ln[cl_ver] = version + ln[cl_ctxt] = context def is_def_prof(p): return p in pdefaults.get(modname, {}).get(sname, []) @@ -83,7 +97,7 @@ def _add_module_metadata(yaml_files, profiles, dstreams, dprofiles): dprofiles[module_name][s] = pset.get() -def summarize_modules(restrict_list=None, yaml_files=None): +def summarize_modules(restrict_list=None, yaml_files=None, as_tree=False): """ Load Modulemd objects from each repository in repo_list and print a summary of the modules found with a summary of their streams and profiles. @@ -101,4 +115,4 @@ def summarize_modules(restrict_list=None, yaml_files=None): _add_module_metadata(yaml_files, profiles, dstreams, dprofiles) restrict_list = restrict_list or [] - _print_summary(profiles, dstreams, dprofiles, restrict_list) + _print_summary(profiles, dstreams, dprofiles, restrict_list, as_tree) diff --git a/tests/test_module_summary.py b/tests/test_module_summary.py index 9308d05..a05ca34 100644 --- a/tests/test_module_summary.py +++ b/tests/test_module_summary.py @@ -15,8 +15,9 @@ spec_v2_yaml_path = os.path.join(testfiles_dir, 'spec.v2.yaml') @pytest.mark.needs_metadata class TestModuleSummary(object): - def matches(self, mod, strm, prof, out): - return re.search(fr'^{mod}\s+{strm}\s+{prof}$', out, re.M) is not None + def matches(self, mod, strm, ver, ctxt, prof, out): + mstr = fr'^{mod}\s+{strm}\s+{ver}\s+{ctxt}\s+{prof}$' + return re.search(mstr, out, re.M) is not None # FIXME: we should mock the fetched metadata so that these tests do not # fail when the metadata changes @@ -24,33 +25,37 @@ class TestModuleSummary(object): summarize_modules() out, err = capfd.readouterr() - assert self.matches('reviewboard', '2.5', + assert self.matches('reviewboard', '2.5', '20180828143308', '083bce86', r'default \[d\], server', out) - assert self.matches('reviewboard', '3.0', + assert self.matches('reviewboard', '3.0', '20180828143238', '083bce86', r'default \[d\], server', out) - assert self.matches('testmodule', 'master', 'default', out) + assert self.matches('testmodule', 'master', '20180405123256', + 'c2c572ec', 'default', out) def test_summarize_modules_restricted(self, capfd): summarize_modules(['reviewboard', 'django']) out, err = capfd.readouterr() - assert self.matches('reviewboard', '2.5', + assert self.matches('reviewboard', '2.5', '20180828143308', '083bce86', r'default \[d\], server', out) - assert self.matches('reviewboard', '3.0', + assert self.matches('reviewboard', '3.0', '20180828143238', '083bce86', r'default \[d\], server', out) - assert self.matches('django', '1.6', + assert self.matches('django', '1.6', '20180828135711', '6c81f848', r'default \[d\], python2_development', out) - assert not self.matches('testmodule', 'master', 'default', out) + assert not self.matches('testmodule', 'master', '20180405123256', + 'c2c572ec', 'default', out) def test_summarize_modules_local_files(self, capfd): summarize_modules(yaml_files=[spec_v2_yaml_path]) out, err = capfd.readouterr() - assert self.matches('testmodule', 'master', 'default', out) - assert self.matches('foo', 'stream-name', 'buildroot, container, ' + - 'default, minimal, srpm-buildroot', out) + assert self.matches('testmodule', 'master', '20180405123256', + 'c2c572ec', 'default', out) + assert self.matches('foo', 'stream-name', '20160927144203', 'c0ffee43', + 'buildroot, container, default, minimal, ' + + 'srpm-buildroot', out)