Created
February 1, 2020 15:10
-
-
Save peterbe/5dbe77d63ddcb310125bb1b5abf803cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
from git import Git | |
def run(cwd): | |
g = Git(cwd) | |
loginfo = g.log("--pretty=format:metadata:%aD,%an,%ae", "--name-only") | |
last_modified = {} | |
files = [] | |
def add(these_files, this_metadata): | |
for file in these_files: | |
if file not in last_modified: | |
last_modified[file] = this_metadata["date"] | |
files.clear() | |
for line in loginfo.splitlines(): | |
if line.startswith("metadata:"): | |
if files: | |
add(files, metadata) | |
metadata = {"date": line.split(",")[1].strip()} | |
elif line: | |
files.append(line) | |
with open("lastmodified-python.json", "w") as f: | |
json.dump(last_modified, f, indent=2) | |
def main(*args): | |
cwd = args[0] | |
assert os.path.isdir(cwd) | |
run(cwd) | |
if __name__ == "__main__": | |
import sys | |
sys.exit(main(*sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment