check news

This commit is contained in:
JerryXiao 2023-01-02 12:43:32 +08:00
parent cd64807a39
commit b685ec00a4
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
5 changed files with 27 additions and 5 deletions

View file

@ -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

View file

@ -26,5 +26,6 @@
"-l"
],
"systemd-check": true,
"news-check": true,
"clear_pkg_cache": false
}

View file

@ -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))

View file

@ -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)