Repository navigation
Expand file tree
/
Copy pathgitall.py
More file actions
65 lines (46 loc) · 1.36 KB
/
Copy pathgitall.py
File metadata and controls
65 lines (46 loc) · 1.36 KB
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
63
64
65
#!/usr/bin/env python3
import subprocess
import re
import sys
from pathlib import Path
def git(*args):
return subprocess.check_output(
["git", *args],
text=True
).strip()
def main():
# Get all changed and untracked files
output = git("status", "--porcelain")
if not output:
print("Nothing to commit.")
return
# Extract problem IDs from filenames
problem_ids = set()
for line in output.splitlines():
filename = line[3:].strip()
match = re.search(r"/?(\d+)\.[^.]+$", filename)
if match:
problem_ids.add(match.group(1))
if not problem_ids:
print("No problem IDs found.")
return
# Find and execute all readme_generator.py scripts
root = Path.cwd()
scripts = sorted(root.rglob("readme_generator.py"))
for script in scripts:
print(f"Running: {script}")
subprocess.run(
[sys.executable, script.name],
cwd=script.parent,
check=True
)
# Generate commit message
ids = sorted(problem_ids, key=int)
message = f"Add URI problems: {', '.join(ids)}"
print(f"Commit message: {message}")
# Add all changes
subprocess.run(["git", "add", "-A"], check=True)
# Commit
subprocess.run(["git", "commit", "-m", message], check=True)
if __name__ == "__main__":
main()