From 4af04682173c546bff7781f26a493d1d36ff225c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 20 May 2026 07:25:17 +0200 Subject: main: move out the error header code --- cgitize/header.py | 18 ++++++++++++++++++ cgitize/main.py | 17 ++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 cgitize/header.py diff --git a/cgitize/header.py b/cgitize/header.py new file mode 100644 index 0000000..e513411 --- /dev/null +++ b/cgitize/header.py @@ -0,0 +1,18 @@ +# Copyright (c) 2026 Egor Tensin +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize. +# Distributed under the MIT License. + + +def update(path, success, error=None): + with open(path, 'w') as file: + contents = '' + if not success: + contents = ( + '''

''' + ) + contents += '''Some repositories couldn't be updated, please check application logs for details.''' + if error is not None: + contents += f'''
{type(error).__name__}: {error}''' + contents += '''

\n''' + file.write(contents) diff --git a/cgitize/main.py b/cgitize/main.py index 1d7245a..e99456e 100644 --- a/cgitize/main.py +++ b/cgitize/main.py @@ -9,6 +9,7 @@ import sys from cgitize.cgit import CGitRepositories, CGitServer from cgitize.config import Config +from cgitize.header import update as update_header from cgitize.utils import setup_logging from cgitize.version import __version__ @@ -39,20 +40,6 @@ 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 = ( - '''

''' - ) - contents += '''Some repositories couldn't be updated, please check application logs for details.''' - if error is not None: - contents += f'''
{type(error).__name__}: {error}''' - contents += '''

\n''' - file.write(contents) - - def main(argv=None): args = parse_args(argv) with setup_logging(args.verbose): @@ -79,7 +66,7 @@ def main(argv=None): if error is not None: logging.warning('Error: %s', error) - setup_error_header_file(config.main.error_header_path, success, error) + update_header(config.main.error_header_path, success, error) return int(not success) -- cgit v1.3