From 5db082be890d60311e29b2f7d4a0ae188d19ebcb Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Sun, 14 Jul 2024 16:03:03 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Initial=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git-annex-duplicates | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 git-annex-duplicates diff --git a/git-annex-duplicates b/git-annex-duplicates new file mode 100755 index 0000000..66280b6 --- /dev/null +++ b/git-annex-duplicates @@ -0,0 +1,42 @@ +#!/usr/bin/python3 +import subprocess +import collections +import re +import click + + +@click.command() +@click.option("--exclude", multiple=True, default=[]) +@click.argument("arguments", nargs=-1) +def main(exclude, arguments): + # build command + find_cmd = ["git", "annex", "find", "--include", "*", "--format=${key}:${file}\n", *arguments] + for e in exclude: + find_cmd += ["--exclude", e] + + # run + result = subprocess.run(find_cmd, capture_output=True) + + files = collections.defaultdict(list) + for l in result.stdout.decode("utf-8").split("\n"): + if l == "": + continue + key, file = l.split(":", maxsplit=1) + + # XXX + if file.lower().endswith(".jpg"): + continue + if file.lower().endswith(".nfo"): + continue + + files[key].append(file) + + for k in files: + if len(files[k]) > 1: + for f in files[k]: + print(f) + print() + + +if __name__ == "__main__": + main()