]> git.mar77i.info Git - admin/blob - gitweb_configs.py
add rcfiles, bigintmandel
[admin] / gitweb_configs.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 from pathlib import Path
6 from shutil import rmtree
7 from subprocess import CalledProcessError, check_output, run
8
9 GITWEB_CONFIGS = {
10 "admin": {
11 "owner": "mar77i <mar77i@protonmail.ch>",
12 "description": "admin scripts",
13 },
14 "mar77i.info": {
15 "owner": "mar77i <mar77i@protonmail.ch>",
16 "description": "mar77i.info website",
17 },
18 "hublib": {
19 "owner": "mar77i <mar77i@protonmail.ch>",
20 "description": "base for websocket toys",
21 },
22 "laptop-config": {
23 "owner": "mar77i <mar77i@protonmail.ch>",
24 "description": "laptop screen configuration",
25 },
26 "rcfiles": {
27 "owner": "mar77i <mar77i@protonmail.ch>",
28 "description": "user configuration files",
29 },
30 "bigintmandel": {
31 "owner": "mar77i <mar77i@protonmail.ch>",
32 "description": "Qt mandelbrot toy, with big integers only",
33 },
34 }
35
36
37 def main():
38 base_dir = Path.home() / "git"
39 for p in base_dir.iterdir():
40 if p.is_dir() and p.name not in GITWEB_CONFIGS:
41 rmtree(p)
42 print(f"removed {p.name}")
43 for repository, configs in GITWEB_CONFIGS.items():
44 p = base_dir / repository
45 if not p.exists():
46 p.mkdir(0o755)
47 os.chdir(p)
48 run(["git", "init", "--bare"])
49 print(f"created {p.name}")
50 else:
51 os.chdir(p)
52 description = p / "description"
53 if description.exists():
54 description.unlink()
55 assert set(configs) == {"owner", "description"}
56 for key, value in configs.items():
57 try:
58 output = check_output(
59 ["git", "config", "--get", f"gitweb.{key}"], universal_newlines=True
60 )
61 except CalledProcessError:
62 output = None
63 if output != f"{value}\n":
64 run(["git", "config", f"gitweb.{key}", value])
65
66
67 if __name__ == "__main__":
68 main()