aboutsummaryrefslogtreecommitdiffstats
path: root/update-time
blob: 0c1f6c764f00efc11d1200a21e3c783cbeb328dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3

import os
import subprocess
from pathlib import Path

GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/")

def update_time(repo: Path) -> str:
   cmd = ["git", "for-each-ref", "--sort=-authordate", "--count=1", "--format='%(authordate:iso8601)'" ]
   proc = subprocess.run(cmd, cwd=repo, stdout=subprocess.PIPE)
   time = proc.stdout.decode().strip()
   with open(repo / "info" / "web" / "last-modified", "w") as f:
      f.write(time)
   return time

def run_on_all_repos(root: Path):
   for element in os.listdir(root):
      full_path = root / element
      if element.startswith("."):
         pass # ignore hidden files
      elif element.endswith(".git"):
         time = update_time(full_path)
         print(f"last update for '{element.replace('.git','')}': {time}")
      elif os.path.isdir(root / element):
         run_on_all_repos(root / element)

if __name__ == "__main__":
   run_on_all_repos(GIT_ROOT)