diff options
author | Egor Tensin <egor@tensin.name> | 2024-06-23 19:28:48 +0200 |
---|---|---|
committer | Egor Tensin <egor@tensin.name> | 2024-06-23 19:51:49 +0200 |
commit | ed43ef1ff97b6fd6e2333ecc55d5f7d8449dd712 (patch) | |
tree | fea0167646232647ff8bd2dac966b498e5a03963 /cgit | |
parent | requirements.txt: bump dependencies (diff) | |
download | cgitize-ed43ef1ff97b6fd6e2333ecc55d5f7d8449dd712.tar.gz cgitize-ed43ef1ff97b6fd6e2333ecc55d5f7d8449dd712.zip |
include error.html in the frontend to signal errors
Diffstat (limited to '')
-rw-r--r-- | cgitize/config.py | 4 | ||||
-rw-r--r-- | cgitize/main.py | 35 |
2 files changed, 31 insertions, 8 deletions
diff --git a/cgitize/config.py b/cgitize/config.py index d4e660a..2df8651 100644 --- a/cgitize/config.py +++ b/cgitize/config.py @@ -44,6 +44,10 @@ class MainSection(Section): return self._get_config_path('output_dir', default=MainSection.DEFAULT_OUTPUT_DIR) @property + def error_header_path(self): + return os.path.join(self.output_dir, 'error.html') + + @property def clone_url(self): return self._get_config_value('clone_url', required=False) diff --git a/cgitize/main.py b/cgitize/main.py index 879e07d..7e52df0 100644 --- a/cgitize/main.py +++ b/cgitize/main.py @@ -32,23 +32,42 @@ def parse_args(argv=None): return parser.parse_args(argv) +def setup_error_header_file(error_header_path, success, error=None): + with open(error_header_path, 'w') as file: + contents = '' + if not success: + contents = '''<p style="text-align: center; color: red; font-weight: bold;">''' + contents += '''Some repositories couldn't be updated, please check application logs for details.''' + if error is not None: + contents += f'''<br>{type(error).__name__}: {error}''' + contents += '''</p>\n''' + file.write(contents) + + def main(argv=None): args = parse_args(argv) with setup_logging(args.verbose): config = Config.read(args.config) - cgit_server = CGitServer(config.main.clone_url) - output = CGitRepositories(config.main.output_dir, cgit_server, force=args.force) success = True - for repo in config.parse_repositories(): - if args.repos is None or repo.name in args.repos: - if not output.update(repo): - success = False + error = None + + try: + cgit_server = CGitServer(config.main.clone_url) + output = CGitRepositories(config.main.output_dir, cgit_server, force=args.force) + for repo in config.parse_repositories(): + if args.repos is None or repo.name in args.repos: + success = success and output.update(repo) + except Exception as e: + success = False + error = e + if success: logging.info('All repositories were updated successfully') - return 0 else: logging.warning("Some repositories couldn't be updated!") - return 1 + + setup_error_header_file(config.main.error_header_path, success, error) + return int(not success) if __name__ == '__main__': |