-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow.py
executable file
·62 lines (56 loc) · 1.79 KB
/
show.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import subprocess
from pathlib import Path
from datetime import timedelta, datetime
import argparse
def main():
parser = argparse.ArgumentParser(description="show latest packages updates")
parser.add_argument(
"limit", type=str, help="time limit like 3d for 3 days and 1w for one weeks"
)
args = parser.parse_args()
limit = None
if args.limit[-1] == "d":
limit = timedelta(days=int(args.limit[:-1]))
elif args.limit[-1] == "w":
limit = timedelta(weeks=int(args.limit[:-1]))
else:
print("bad time limit")
exit(1)
now = datetime.now()
since = now - limit
root = Path(__file__).parent
repos = root / "straight" / "repos"
lastest_and_repos = []
for repo in repos.iterdir():
ts = subprocess.check_output(
"git show -s --format=%ct", cwd=repo, shell=True
).rstrip()
ts = datetime.fromtimestamp(int(ts))
if ts > since:
lastest_and_repos.append((ts, repo))
lastest_and_repos.sort(reverse=True)
for ts, repo in lastest_and_repos:
url = (
subprocess.check_output("git remote get-url origin", cwd=repo, shell=True)
.rstrip()
.decode("utf-8")
)
if url.endswith(".git"):
url = url[:-4]
print(f"\033[35m{repo.name} \033[33m{url}\033[0m")
output = subprocess.check_output(
[
"git",
"-c",
"color.ui=always",
"log",
"--pretty=format:%Cred%h%Creset %s %Cgreen(%cr)",
"--abbrev-commit",
f"--since={int(since.timestamp())}",
],
cwd=repo,
).decode("utf-8")
print(output)
if __name__ == "__main__":
main()