- commit
- acf71cc52765723a4ea49218b4a75ed094d90079
- parent
- 5ab47af37cc353f1052eef97ba3ff54962688543
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-05 10:07
python: use context manager to open file
Diffstat
M | gitolite/stagit.py | 43 | +++++++++++++++++++++---------------------- |
1 files changed, 21 insertions, 22 deletions
diff --git a/gitolite/stagit.py b/gitolite/stagit.py
@@ -86,28 +86,27 @@ def update_repo(repo): 86 86 87 87 88 88 def render_index():89 -1 fh = open(WWW_DIR / 'index.html', 'w')90 -1 fh.write('<!DOCTYPE html>\n')91 -1 fh.write('<html>\n<head>\n')92 -1 fh.write('<meta charset="UTF-8">')93 -1 fh.write('<meta name="viewport" content="width=device-width">\n')94 -1 fh.write('<title>Repositories</title>\n')95 -1 fh.write('<link rel="stylesheet" type="text/css" href="style.css" />\n')96 -1 fh.write('</head>\n<body>\n')97 -1 fh.write('<h1>Repositories</h1>')98 -1 fh.write('<hr/>\n')99 -1 fh.write('<main id="content">\n')100 -1 fh.write('<table>\n<thead>\n')101 -1 fh.write('<tr><th>Name</th><th>Description</th></tr>\n')102 -1 fh.write('</thead>\n<tbody>\n')103 -1 for repo in config.iter_repos():104 -1 if config.getboolean(repo, 'http'):105 -1 fh.write('<tr><td><a href="{}/">{}</a></td><td>{}</td></tr>\n'.format(106 -1 escape(repo), escape(repo), escape(config.get(repo, 'desc'))107 -1 ))108 -1 fh.write('</tbody>\n</table>\n')109 -1 fh.write('</main>\n</body>\n</html>\n')110 -1 fh.close()-1 89 with open(WWW_DIR / 'index.html', 'w') as fh: -1 90 fh.write('<!DOCTYPE html>\n') -1 91 fh.write('<html>\n<head>\n') -1 92 fh.write('<meta charset="UTF-8">') -1 93 fh.write('<meta name="viewport" content="width=device-width">\n') -1 94 fh.write('<title>Repositories</title>\n') -1 95 fh.write('<link rel="stylesheet" type="text/css" href="style.css" />\n') -1 96 fh.write('</head>\n<body>\n') -1 97 fh.write('<h1>Repositories</h1>') -1 98 fh.write('<hr/>\n') -1 99 fh.write('<main id="content">\n') -1 100 fh.write('<table>\n<thead>\n') -1 101 fh.write('<tr><th>Name</th><th>Description</th></tr>\n') -1 102 fh.write('</thead>\n<tbody>\n') -1 103 for repo in config.iter_repos(): -1 104 if config.getboolean(repo, 'http'): -1 105 fh.write('<tr><td><a href="{}/">{}</a></td><td>{}</td></tr>\n'.format( -1 106 escape(repo), escape(repo), escape(config.get(repo, 'desc')) -1 107 )) -1 108 fh.write('</tbody>\n</table>\n') -1 109 fh.write('</main>\n</body>\n</html>\n') 111 110 112 111 113 112 def render_repo(repo):