diff --git a/README.md b/README.md index 66119d2..a946ee9 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ A list of pacnew files that are silently ignored during parsing, any other pacne Custom pacman hooks and packages output matching is configurable via `/etc/pacroller/known_output_override.py`. ### check systemd status The "systemd-check" option allows pacroller to check fo degraded systemd services before an upgrade. +### check news from archinux.org +Automatically checks news before upgrade, unless "news-check" is set to false. ### clear package cache Pacroller wipes /var/cache/pacman/pkg after a successful upgrade if the option "clear_pkg_cache" is set. ### save pacman output @@ -52,4 +54,3 @@ Configure `/etc/pacroller/smtp.json` to receive an email notification when an up - Your favourite package may not be supported, however it's easy to add another set of rules. - Restarting the whole system after a kernel upgrade is not implemented. - Human interaction is required occasionally. -- Does not check news from archlinux.org diff --git a/src/pacroller/config.json b/src/pacroller/config.json index beb1db9..0ac1178 100644 --- a/src/pacroller/config.json +++ b/src/pacroller/config.json @@ -26,5 +26,6 @@ "-l" ], "systemd-check": true, + "news-check": true, "clear_pkg_cache": false } diff --git a/src/pacroller/config.py b/src/pacroller/config.py index 1f3290c..637856f 100644 --- a/src/pacroller/config.py +++ b/src/pacroller/config.py @@ -11,6 +11,7 @@ CONFIG_FILE_SMTP = 'smtp.json' F_KNOWN_OUTPUT_OVERRIDE = 'known_output_override.py' LIB_DIR = Path('/var/lib/pacroller') DB_FILE = 'db' +NEWS_FILE = 'news' LOG_DIR = Path('/var/log/pacroller') PACMAN_CONFIG = '/etc/pacman.conf' PACMAN_LOG = '/var/log/pacman.log' @@ -75,6 +76,7 @@ for i in NEEDRESTART_CMD: assert isinstance(i, str) SYSTEMD = bool(_config.get('systemd-check', True)) +NEWS = bool(_config.get('news-check', True)) PACMAN_SCC = bool(_config.get('clear_pkg_cache', False)) SMTP_ENABLED = bool(_smtp_config.get('enabled', False)) diff --git a/src/pacroller/main.py b/src/pacroller/main.py index 4e51daf..41af782 100644 --- a/src/pacroller/main.py +++ b/src/pacroller/main.py @@ -12,11 +12,12 @@ from datetime import datetime from typing import List, Iterator from pacroller.utils import execute_with_io, UnknownQuestionError, back_readline, ask_interactive_question from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net, checkReport -from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, PACMAN_LOG, PACMAN_CONFIG, - TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, SYNC_SH, - EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD, - PACMAN_PKG_DIR, PACMAN_SCC, PACMAN_DB_LCK, SAVE_STDOUT, LOG_DIR) +from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, NEWS_FILE, PACMAN_LOG, + PACMAN_CONFIG, TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, + SYNC_SH, EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD, + NEWS, PACMAN_PKG_DIR, PACMAN_SCC, PACMAN_DB_LCK, SAVE_STDOUT, LOG_DIR) from pacroller.mailer import MailSender +from pacroller.news import get_news logger = logging.getLogger() @@ -32,6 +33,8 @@ class CheckFailed(Exception): pass class NeedrestartFailed(Exception): pass +class NewsUnread(Exception): + pass def sync() -> None: logger.info('sync start') @@ -318,6 +321,21 @@ def main() -> None: logger.error(_err) send_mail(_err) exit(11) + if NEWS: + _newsf = LIB_DIR / NEWS_FILE + try: + _old_news = _newsf.read_text() if _newsf.exists() else '' + if (_news := get_news(_old_news)): + _newsf.write_text(_news[0]) + _err = NewsUnread(_news) + write_db(None, _err) + for _n in _news: + logger.warn(f"news: {_n}") + send_mail(_err) + exit(11) + except Exception: + send_mail(f"Checking news:\n{traceback.format_exc()}") + raise if Path(PACMAN_DB_LCK).exists(): _err = f'Database is locked at {PACMAN_DB_LCK}' logger.error(_err) diff --git a/src/pacroller/arch-news-feed.py b/src/pacroller/news.py similarity index 100% rename from src/pacroller/arch-news-feed.py rename to src/pacroller/news.py