From 2e09859cd974e1f2e0ba0146820c87ee8081f569 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Sun, 4 Dec 2022 19:21:14 -0500 Subject: [PATCH] guess working --- vimtabdiff.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/vimtabdiff.py b/vimtabdiff.py index 08b0c63..64b81d6 100755 --- a/vimtabdiff.py +++ b/vimtabdiff.py @@ -4,6 +4,7 @@ import os,sys import argparse import pathlib from pathlib import Path +import itertools def parse_args(): parser = argparse.ArgumentParser(description="Show diff in vim tab pages") @@ -22,10 +23,33 @@ def get_dir_info(dirname: Path): files.append(p) return dirs, files +def get_chunks(aItems, bItems): + aItems = [(item, 'A') for item in aItems] + bItems = [(item, 'B') for item in bItems] + items = sorted(aItems + bItems) + for name, items in itertools.groupby(items, lambda item: item[0].name): + items = list(items) + if len(items) == 2: + aItem, bItem = items + aItem, _ = aItem + bItem, _ = bItem + yield aItem, bItem + else: + assert(len(items) == 1) + item, = items + item, tag = item + if tag == 'A': + yield item, None + else: + yield None, item + def get_file_pairs(a, b): - aDirs, aFiles = get_dir_info(a) - bDirs, bFiles = get_dir_info(b) - pass + aDirs, aFiles = get_dir_info(Path(a)) + bDirs, bFiles = get_dir_info(Path(b)) + print(f"{a=}, {aDirs=}, {aFiles=}, {b=}, {bDirs=}, {bFiles=}") + yield from get_chunks(aFiles, bFiles) + for aDir, bDir in get_chunks(aDirs, bDirs): + yield from get_file_pairs(aDir, bDir) def main(): dirs, files = get_dir_info(Path('.')) @@ -33,6 +57,8 @@ def main(): args = parse_args() print("Helloworld") print(f"{args.pathA=} {args.pathB=}") + for a, b in get_file_pairs(args.pathA, args.pathB): + print(f"{a=}, {b=}") if __name__ == '__main__': main()