Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compare brief by default, add --all option #218

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 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
Expand Down
7 changes: 6 additions & 1 deletion mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +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(
'--all',
action = 'store_true',
help = 'Show all repos, not only differing repos')

def __whereis(self):
whereis = self.subparsers.add_parser(
Expand Down
32 changes: 28 additions & 4 deletions mepo.d/command/compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
if curr_ver not in orig_ver:
return True

return False

def calculate_header_lengths(allcomps):
names = []
Expand All @@ -37,13 +56,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, all_repos):
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 unless --all is passed in
if not all_repos:
return
FMT_VAL = (name_width, name_width, orig_width)

FMT0 = '{:<%s.%ss} | {:<%ss} | {:<s}' % FMT_VAL
Expand All @@ -57,3 +80,4 @@ def print_cmp(name, orig, curr, name_width, orig_width):
print(FMT2.format(name_blank, '...', curr))
else:
print(FMT0.format(name, orig, curr))