From dd8015cccf9ad04e936f00a892f59f096723db9f Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Tue, 13 Feb 2024 10:05:03 -0500 Subject: [PATCH] Add some more scripts --- scripts/git-authors-recursive | 20 ++++++++++++++++++++ scripts/mc-log-cat | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 scripts/git-authors-recursive create mode 100755 scripts/mc-log-cat diff --git a/scripts/git-authors-recursive b/scripts/git-authors-recursive new file mode 100755 index 0000000..71494c8 --- /dev/null +++ b/scripts/git-authors-recursive @@ -0,0 +1,20 @@ +#! /bin/bash + +git submodule foreach git authors | grep -v "^Entering" | python3 -c ' + +import sys +lines = sys.stdin.read().splitlines() +stats = {} +for line in lines: + count, author = line.lstrip().split("\t") + if author not in stats: + stats[author] = 0 + stats[author] += int(count) + +stats = list(stats.items()) +stats.sort(key=lambda s: s[1], reverse=True) + +for author, count in stats: + print(f"{count}\t{author}") + +' diff --git a/scripts/mc-log-cat b/scripts/mc-log-cat new file mode 100755 index 0000000..288a2c9 --- /dev/null +++ b/scripts/mc-log-cat @@ -0,0 +1,34 @@ +#! /usr/bin/env python3 + +import sys +import argparse +import subprocess +from pathlib import Path + +def main() -> int: + ap = argparse.ArgumentParser(prog="mc-log-cat", description="Analyze a set of Minecraft logs") + ap.add_argument("logs_dir", help="Path to the logs directory", type=Path) + args = ap.parse_args() + + # Find all compressed (old) logs + compressed_logs = list(args.logs_dir.glob("*.log.gz")) + compressed_logs.sort() + + # Non-destructively read the contents of each archive + log_files = [] + for file in compressed_logs: + file_contents = subprocess.run(["gunzip", "-c", file.as_posix()], capture_output=True, text=True) + log_files.append(file_contents.stdout) + + # Read and append the most recent log + if args.logs_dir.joinpath("latest.log").exists(): + log_files.append(args.logs_dir.joinpath("latest.log").read_text()) + + # Print the logs + for log in log_files: + print(log) + + return 0 + +if __name__ == "__main__": + sys.exit(main())