From 1826f6d32dd7fd51f05d64838a89adf9966e118e Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 24 Mar 2022 11:10:46 -0400 Subject: [PATCH 1/2] Add brief option to compare --- CHANGELOG.md | 2 ++ mepo.d/cmdline/parser.py | 4 ++++ mepo.d/command/compare/compare.py | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdff540..3c5dd8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Add `--brief` option to `compare` to only show differing repos + ### Changed ### Removed diff --git a/mepo.d/cmdline/parser.py b/mepo.d/cmdline/parser.py index 12865d7..c597a1b 100644 --- a/mepo.d/cmdline/parser.py +++ b/mepo.d/cmdline/parser.py @@ -298,6 +298,10 @@ def __compare(self): 'compare', description = 'Compare current and original states of all components', aliases=mepoconfig.get_command_alias('compare')) + compare.add_argument( + '--brief', + action = 'store_true', + help = 'Only show differing repos') def __whereis(self): whereis = self.subparsers.add_parser( diff --git a/mepo.d/command/compare/compare.py b/mepo.d/command/compare/compare.py index 19db70b..4407c00 100644 --- a/mepo.d/command/compare/compare.py +++ b/mepo.d/command/compare/compare.py @@ -18,7 +18,7 @@ def run(args): # This command is to try and work with git tag oddities curr_ver = sanitize_version_string(orig_ver,curr_ver,git) - print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen) + print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen, args.brief) def calculate_header_lengths(allcomps): names = [] @@ -37,13 +37,17 @@ def print_header(max_namelen, max_origlen): print(FMTHEAD.format("Repo","Original","Current")) print(FMTHEAD.format("-"*80,"-"*max_origlen,"-"*7)) -def print_cmp(name, orig, curr, name_width, orig_width): +def print_cmp(name, orig, curr, name_width, orig_width, brief): name_blank = '' #if orig not in curr: if curr not in orig: name = colors.RED + name + colors.RESET name_blank = colors.RED + name_blank + colors.RESET name_width += len(colors.RED) + len(colors.RESET) + else: + # This only prints differing repos if --brief is passed in + if brief: + return FMT_VAL = (name_width, name_width, orig_width) FMT0 = '{:<%s.%ss} | {:<%ss} | {: Date: Thu, 24 Mar 2022 15:41:01 -0400 Subject: [PATCH 2/2] Have compare only show differing repos by default --- CHANGELOG.md | 4 ++-- mepo.d/cmdline/parser.py | 7 ++++--- mepo.d/command/compare/compare.py | 32 +++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c5dd8b..f8ca511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Add `--brief` option to `compare` to only show differing repos - ### Changed +- Changed the default behavior of `compare` to only show differing repos. Use `--all` to see all repos + ### Removed ## [1.40.0] - 2022-01-12 diff --git a/mepo.d/cmdline/parser.py b/mepo.d/cmdline/parser.py index c597a1b..0cbf1c7 100644 --- a/mepo.d/cmdline/parser.py +++ b/mepo.d/cmdline/parser.py @@ -296,12 +296,13 @@ def __pull_all(self): def __compare(self): compare = self.subparsers.add_parser( 'compare', - description = 'Compare current and original states of all components', + description = 'Compare current and original states of all components. ' + 'Will only show differing repos unless --all is passed in', aliases=mepoconfig.get_command_alias('compare')) compare.add_argument( - '--brief', + '--all', action = 'store_true', - help = 'Only show differing repos') + help = 'Show all repos, not only differing repos') def __whereis(self): whereis = self.subparsers.add_parser( diff --git a/mepo.d/command/compare/compare.py b/mepo.d/command/compare/compare.py index 4407c00..3d532b1 100644 --- a/mepo.d/command/compare/compare.py +++ b/mepo.d/command/compare/compare.py @@ -8,8 +8,24 @@ def run(args): allcomps = MepoState.read_state() - max_namelen, max_origlen = calculate_header_lengths(allcomps) - print_header(max_namelen, max_origlen) + + if not any_differing_repos(allcomps): + print(f'No repositories have changed') + else: + max_namelen, max_origlen = calculate_header_lengths(allcomps) + print_header(max_namelen, max_origlen) + for comp in allcomps: + git = GitRepository(comp.remote, comp.local) + curr_ver = version_to_string(git.get_version(),git) + orig_ver = version_to_string(comp.version,git) + + # This command is to try and work with git tag oddities + curr_ver = sanitize_version_string(orig_ver,curr_ver,git) + + print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen, args.all) + +def any_differing_repos(allcomps): + for comp in allcomps: git = GitRepository(comp.remote, comp.local) curr_ver = version_to_string(git.get_version(),git) @@ -18,7 +34,10 @@ def run(args): # This command is to try and work with git tag oddities curr_ver = sanitize_version_string(orig_ver,curr_ver,git) - print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen, args.brief) + if curr_ver not in orig_ver: + return True + + return False def calculate_header_lengths(allcomps): names = [] @@ -37,7 +56,7 @@ def print_header(max_namelen, max_origlen): print(FMTHEAD.format("Repo","Original","Current")) print(FMTHEAD.format("-"*80,"-"*max_origlen,"-"*7)) -def print_cmp(name, orig, curr, name_width, orig_width, brief): +def print_cmp(name, orig, curr, name_width, orig_width, all_repos): name_blank = '' #if orig not in curr: if curr not in orig: @@ -45,8 +64,8 @@ def print_cmp(name, orig, curr, name_width, orig_width, brief): name_blank = colors.RED + name_blank + colors.RESET name_width += len(colors.RED) + len(colors.RESET) else: - # This only prints differing repos if --brief is passed in - if brief: + # This only prints differing repos unless --all is passed in + if not all_repos: return FMT_VAL = (name_width, name_width, orig_width) @@ -61,3 +80,4 @@ def print_cmp(name, orig, curr, name_width, orig_width, brief): print(FMT2.format(name_blank, '...', curr)) else: print(FMT0.format(name, orig, curr)) +