- commit
- 974fc29f55cfd28355316ada921ed2ce22056721
- parent
- fbf4f98f3a62573c07f71691f1e5c485fb53281b
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-03-30 07:17
access: update-everything command
Diffstat
M | gitolite/stagit.py | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
1 files changed, 65 insertions, 5 deletions
diff --git a/gitolite/stagit.py b/gitolite/stagit.py
@@ -3,6 +3,7 @@ import sys 3 3 import shutil 4 4 import subprocess 5 5 import configparser -1 6 from xml.sax.saxutils import escape 6 7 7 8 USER = 'git' 8 9 @@ -28,6 +29,9 @@ class Config: 28 29 self.config = configparser.ConfigParser() 29 30 self.config.read(CONF_PATH) 30 31 -1 32 def get(self, section, key): -1 33 return self.config.get(section, key, fallback='') -1 34 31 35 def _iter_sets(self, repo, prefix): 32 36 try: 33 37 for key, value in self.config[repo].items(): @@ -63,14 +67,20 @@ class Config: 63 67 config = Config() 64 68 65 6966 -1 def update_daemon_export_ok(repo):67 -1 export_ok = os.path.join(get_repo_dir(repo), 'git-daemon-export-ok')-1 70 def update_metadata(repo): -1 71 repodir = get_repo_dir(repo) -1 72 export_ok = os.path.join(repodir, 'git-daemon-export-ok') 68 73 if config.is_public(repo): 69 74 with open(export_ok, 'a'): 70 75 os.utime(export_ok, None) 71 76 elif os.path.exists(export_ok): 72 77 os.unlink(export_ok) 73 78 -1 79 with open(os.path.join(repodir, 'description'), 'w') as fh: -1 80 fh.write(config.get(repo, 'desc')) -1 81 with open(os.path.join(repodir, 'url'), 'w') as fh: -1 82 fh.write(config.get(repo, 'url')) -1 83 74 84 75 85 def update_repo(repo): 76 86 path = get_repo_dir(repo) @@ -79,10 +89,60 @@ def update_repo(repo): 79 89 subprocess.check_call(['git', 'init', '--bare'], cwd=path) 80 90 shutil.copy(UPDATE_HOOK, os.path.join(path, 'hooks', 'update')) 81 91 shutil.copy(POST_UPDATE_HOOK, os.path.join(path, 'hooks', 'post-update'))82 -183 -184 -1 def render_html(repo):-1 92 update_metadata(repo) -1 93 -1 94 -1 95 def render_index(): -1 96 fh = open(os.path.join(WWW_DIR, 'index.html'), 'w') -1 97 fh.write('<!DOCTYPE html>\n') -1 98 fh.write('<html>\n<head>\n') -1 99 fh.write('<meta charset="UTF-8">') -1 100 fh.write('<title>Repositories</title>\n') -1 101 fh.write('<link rel="stylesheet" type="text/css" href="style.css" />\n') -1 102 fh.write('</head>\n<body>\n') -1 103 fh.write('<h1>Repositories</h1>') -1 104 fh.write('<hr/>\n') -1 105 fh.write('<main id="content">\n') -1 106 fh.write('<table>\n<thead>\n') -1 107 fh.write('<tr><th>Name</th><th>Description</th></tr>\n') -1 108 fh.write('</thead>\n<tbody>\n') -1 109 for repo in config.iter_user_repos('@public'): -1 110 fh.write('<tr><td><a href="%s/">%s</a></td><td>%s</td></tr>\n' % ( -1 111 escape(repo), escape(repo), escape(config.get(repo, 'desc')) -1 112 )) -1 113 fh.write('</tbody>\n</table>\n') -1 114 fh.write('</main>\n</body>\n</html>\n') -1 115 fh.close() -1 116 -1 117 -1 118 def render_repo(repo): 85 119 if config.is_public(repo): 86 120 target_dir = os.path.join(WWW_DIR, repo) 87 121 os.makedirs(target_dir, exist_ok=True) 88 122 subprocess.check_call(['stagit', get_repo_dir(repo)], cwd=target_dir) -1 123 -1 124 -1 125 def render_all(): -1 126 for repo in os.listdir(WWW_DIR): -1 127 path = os.path.join(WWW_DIR, repo) -1 128 if os.path.isdir(path): -1 129 shutil.rmtree(path) -1 130 for repo in config.iter_user_repos('@public'): -1 131 render_repo(repo) -1 132 render_index() -1 133 -1 134 -1 135 if __name__ == '__main__': -1 136 all_repos = set(config.iter_repos()) -1 137 phy_repos = set(fn[:-4] for fn in os.listdir(REPO_DIR) if fn.endswith('.git')) -1 138 stale_repos = phy_repos - all_repos -1 139 -1 140 print('Updating repos …') -1 141 for repo in all_repos: -1 142 update_repo(repo) -1 143 -1 144 if stale_repos: -1 145 print('Warning: stale files for deleted repos:', ', '.join(stale_repos)) -1 146 -1 147 print('Generating HTML …') -1 148 render_all()