MCPcopy
hub / github.com/deadc0de6/dotdrop / cmd_compare

Function cmd_compare

dotdrop/dotdrop.py:422–471  ·  view source on GitHub ↗

compare dotfiles and return True if all identical

(opts, tmp)

Source from the content-addressed store, hash-verified

420
421
422def cmd_compare(opts, tmp):
423 """compare dotfiles and return True if all identical"""
424 dotfiles = opts.dotfiles
425 if not dotfiles:
426 msg = f'no dotfile defined for this profile (\"{opts.profile}\")'
427 LOG.warn(msg)
428 return True
429
430 # compare only specific files
431 selected = dotfiles
432 if opts.compare_focus:
433 selected = _select(opts.compare_focus, dotfiles)
434
435 if len(selected) < 1:
436 LOG.log('\nno dotfile to compare')
437 return False
438
439 same = True
440 cnt = 0
441 if opts.workers > 1:
442 # in parallel
443 LOG.dbg(f'run with {opts.workers} workers')
444 ex = futures.ThreadPoolExecutor(max_workers=opts.workers)
445 wait_for = []
446 for dotfile in selected:
447 if not dotfile.src and not dotfile.dst:
448 # ignore fake dotfile
449 continue
450 j = ex.submit(_dotfile_compare, opts, dotfile, tmp)
451 wait_for.append(j)
452 # check result
453 for fut in futures.as_completed(wait_for):
454 if not fut.result():
455 same = False
456 cnt += 1
457 else:
458 # sequentially
459 for dotfile in selected:
460 if not dotfile.src and not dotfile.dst:
461 # ignore fake dotfile
462 continue
463 if not _dotfile_compare(opts, dotfile, tmp):
464 same = False
465 cnt += 1
466
467 if opts.compare_workdir and _workdir_enum(opts) > 0:
468 same = False
469
470 LOG.log(f'\n{cnt} dotfile(s) compared.')
471 return same
472
473
474def cmd_update(opts):

Callers 2

test_compareMethod · 0.90
_exec_commandFunction · 0.85

Calls 6

_selectFunction · 0.85
_dotfile_compareFunction · 0.85
_workdir_enumFunction · 0.85
warnMethod · 0.80
logMethod · 0.80
dbgMethod · 0.80

Tested by 1

test_compareMethod · 0.72