--- /dev/null
+#!/usr/bin/env python3
+
+import os
+import sys
+from pathlib import Path
+from subprocess import CalledProcessError, check_output, run
+
+GITWEB_CONFIGS = {
+ "admin": {
+ "owner": "mar77i <mar77i@protonmail.ch>",
+ "description": "admin scripts",
+ },
+ "mar77i.info": {
+ "owner": "mar77i <mar77i@protonmail.ch>",
+ "description": "mar77i.info website",
+ },
+}
+
+
+def main():
+ base_dir = Path.home() / "git"
+ mismatched = set(GITWEB_CONFIGS) ^ {p.name for p in base_dir.iterdir() if p.is_dir()}
+ if mismatched:
+ print(
+ f"Warning: gitweb_configs mismatch: {', '.join(mismatched)}",
+ file=sys.stderr,
+ )
+ for repository, configs in GITWEB_CONFIGS.items():
+ p = base_dir / repository
+ if not p.exists():
+ continue
+ os.chdir(p)
+ description = p / "description"
+ if description.exists():
+ description.unlink()
+ assert set(configs) == {"owner", "description"}
+ for key, value in configs.items():
+ try:
+ output = check_output(
+ ["git", "config", "--get", f"gitweb.{key}"], universal_newlines=True
+ )
+ except CalledProcessError:
+ output = None
+ if output != f"{value}\n":
+ run(["git", "config", f"gitweb.{key}", value])
+
+
+if __name__ == "__main__":
+ main()
update_gitweb_theme() {
local theme_css_dest="${HOME}/gitweb/gitweb-theme.css"
- print_and_run bash -c "git show master:gitweb-theme.css > ${theme_css_dest}"
+ print_and_run bash -c "git show master:gitweb-theme.css > \"${theme_css_dest}\""
}
-tasks=(update_gitweb_theme)
+update_gitweb_configs() {
+ print_and_run bash -c 'python <(git show master:gitweb_configs.py)'
+}
+
+tasks=(update_gitweb_theme update_gitweb_configs)
for task in "${tasks[@]}"; do
"${task}"
from itertools import chain
from pathlib import Path
from socketserver import BaseRequestHandler, TCPServer
-from subprocess import DEVNULL, PIPE, Popen, run
+from subprocess import DEVNULL, PIPE, Popen, check_output, run
PORT = "7777"
REMOTE_HOST = "localhost"
)
+class ReusableTCPServer(TCPServer):
+ allow_reuse_address = True
+
+
def check_ssh_auth_sock(**kwargs):
completed = run(
["ssh-add", "-l"],
):
return q_str
print("starting new ssh-agent")
- return run(
+ return check_output(
["bash", "-c", '. <(ssh-agent); echo "${SSH_AUTH_SOCK}"'],
- stdout=PIPE,
universal_newlines=True,
- ).stdout
+ )
def create_tcp_server(server_address, data):
def handle(self):
self.request.sendall(data)
- class ReusableTCPServer(TCPServer):
- allow_reuse_address = True
-
return ReusableTCPServer(server_address, RequestHandler)