diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2022-09-19 19:08:29 +0100 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2022-09-19 19:08:29 +0100 |
commit | 135f7ec31ccc691b626d465a70fcac97baa895f7 (patch) | |
tree | b6783700415dda7c8f551e75b9e4a169365a4db0 | |
parent | cfa6e98a33e89291b19376e9e1ab25510afdfb7d (diff) | |
download | git-scripts-135f7ec31ccc691b626d465a70fcac97baa895f7.tar.gz git-scripts-135f7ec31ccc691b626d465a70fcac97baa895f7.zip |
Added automatically restarting the web ui when a new repo is created
-rwxr-xr-x | del_repo | 2 | ||||
-rwxr-xr-x | gitscripts.conf.example | 1 | ||||
-rwxr-xr-x | klaus/app.py | 14 | ||||
-rwxr-xr-x | klaus/docker-compose.yml | 1 | ||||
-rwxr-xr-x | make_repo.py | 15 | ||||
-rwxr-xr-x | restart_ui | 4 |
6 files changed, 33 insertions, 4 deletions
@@ -6,3 +6,5 @@ read repo rm -fvr /srv/git/$repo.git rm -fvr ~/$repo* rm -fv /srv/www/repositories/$repo* + +bash /srv/www/git-scripts/restart_ui diff --git a/gitscripts.conf.example b/gitscripts.conf.example index 4acf70d..ee273b0 100755 --- a/gitscripts.conf.example +++ b/gitscripts.conf.example @@ -4,6 +4,7 @@ repo_meta_path = /srv/www/repositories domain = git.eda.gay gitignore_templates = /srv/www/gitignore license_templates = /srv/www/license-templates/templates +restart_ui_cmd = bash /srv/www/git-scripts/restart_ui [github] user = jwansek diff --git a/klaus/app.py b/klaus/app.py index 3ddd08b..6b2205e 100755 --- a/klaus/app.py +++ b/klaus/app.py @@ -3,10 +3,22 @@ import waitress import klaus import os -repositories = ["/srv/git/git-scripts.git", "/srv/git/anExampleRepo%21.git"] +def get_repo_paths(metadata_path): + repo_paths = [] + for filename in os.listdir(metadata_path): + if filename.endswith(".git.conf"): + meta = configparser.ConfigParser() + meta.read(os.path.join(metadata_path, filename)) + repo_name = filename[:-5] + if meta.getboolean(repo_name, "visible"): + repo_paths.append(meta.get(repo_name, "path")) + + return repo_paths if __name__ == "__main__": + repositories = get_repo_paths("/srv/repos") + print("Using repository paths: %s" % " ".join(repositories)) app = klaus.make_app(repositories, "Eden's git server - Repositories") waitress.serve(app, host = "0.0.0.0", port = 80, threads = int(os.environ["APP_THREADS"])) diff --git a/klaus/docker-compose.yml b/klaus/docker-compose.yml index e980485..e7ffba6 100755 --- a/klaus/docker-compose.yml +++ b/klaus/docker-compose.yml @@ -12,5 +12,6 @@ services: - APP_THREADS=4 volumes: - '/media/git:/srv/git:ro' + - '/media/gitwww/repositories:/srv/repos:ro' ports: - '81:80' diff --git a/make_repo.py b/make_repo.py index 6d8f3eb..0e2c9d1 100755 --- a/make_repo.py +++ b/make_repo.py @@ -27,7 +27,7 @@ if not os.path.exists(conf_path): CONFIG = configparser.ConfigParser() CONFIG.read(conf_path) -repo_name = urllib.parse.quote_plus(input("Input repository name: ")) +repo_name = input("Input repository name: ").replace(" ", "_") if not repo_name.endswith(".git"): repo_name += ".git" repo_dir = os.path.join(CONFIG.get("git", "repo_path"), repo_name) @@ -92,7 +92,7 @@ if input("Would you like the repository to remain bare? Useful for making mirror print("") selected_index = int(input("\nSelect .gitignore template: ")) - if selected_index != 0: + if selected_index != 1: shutil.copy(os.path.join(gitignore_templates_dir, templates[selected_index - 1]) + ".gitignore", ".gitignore", follow_symlinks = True) licenses_templates_dir = CONFIG.get("git", "license_templates") @@ -104,7 +104,7 @@ if input("Would you like the repository to remain bare? Useful for making mirror print("") selected_index = int(input("\nSelect license template: ")) - if selected_index != 0: + if selected_index != 1: with open(os.path.join(licenses_templates_dir, templates[selected_index - 1]) + ".txt", "r") as f: jinja_template = jinja2.Template(f.read()) @@ -119,6 +119,15 @@ if input("Would you like the repository to remain bare? Useful for making mirror subprocess.run(["git", "commit", "-m", "Initialized repository"]) subprocess.run(["git", "push", "origin", "master"]) +# could do this with the docker API instead maybe +proc = subprocess.Popen(CONFIG.get("git", "restart_ui_cmd").split(), stdout = subprocess.PIPE) +while True: + line = proc.stdout.readline() + if not line: + break + print(line.decode()) + + print(""" Repository created. You can now clone or add remote: git remote add other %s diff --git a/restart_ui b/restart_ui new file mode 100755 index 0000000..806358d --- /dev/null +++ b/restart_ui @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Restarting web UI docker container..." +ssh root@192.168.1.5 "cd /media/gitwww/git-scripts/klaus && docker-compose restart" |