aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgit/repos/main.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-27 03:01:31 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-27 03:01:31 +0300
commitd4966a22743bc49153bf3fef16637f9862f88d75 (patch)
tree427a436eb75b10f90ca0763d2c4fca0dc7980169 /cgit/repos/main.py
parentfix a typo (diff)
downloadcgitize-d4966a22743bc49153bf3fef16637f9862f88d75.tar.gz
cgitize-d4966a22743bc49153bf3fef16637f9862f88d75.zip
minor refactoring
Diffstat (limited to '')
-rw-r--r--cgit/repos/main.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/cgit/repos/main.py b/cgit/repos/main.py
index 8132208..a1b5bae 100644
--- a/cgit/repos/main.py
+++ b/cgit/repos/main.py
@@ -5,6 +5,7 @@
from argparse import ArgumentParser
import configparser
+from contextlib import contextmanager
import importlib
import logging
import os.path
@@ -19,11 +20,17 @@ DEFAULT_CONFIG_PATH = '/etc/cgit-repos/cgit-repos.conf'
DEFAULT_MY_REPOS_PATH = '/etc/cgit-repos/my_repos.py'
-def set_up_logging():
+@contextmanager
+def setup_logging():
logging.basicConfig(
level=logging.DEBUG,
datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)s | %(levelname)s | %(message)s')
+ try:
+ yield
+ except Exception as e:
+ logging.exception(e)
+ raise
def parse_args(argv=None):
@@ -86,8 +93,7 @@ class Config:
def main(args=None):
- set_up_logging()
- try:
+ with setup_logging():
args = parse_args(args)
config = Config.read(args.config)
config.set_defaults()
@@ -105,9 +111,6 @@ def main(args=None):
else:
logging.warning("Some repositories couldn't be updated!")
return 1
- except Exception as e:
- logging.exception(e)
- raise
if __name__ == '__main__':