From 2a58e7a1869290678bdb1e4707dfac9519ed45fe Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Thu, 23 Jul 2026 13:11:58 +0200 Subject: [PATCH] Modernize Python director entry point --- contrib/testing/python-runtime-check.sh | 8 ++- src/agents/director/bongodirector.py | 85 +++++++++++++++++++------ 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/contrib/testing/python-runtime-check.sh b/contrib/testing/python-runtime-check.sh index 9c9fd15..292785b 100755 --- a/contrib/testing/python-runtime-check.sh +++ b/contrib/testing/python-runtime-check.sh @@ -35,10 +35,15 @@ import io from bongo import table from bongo.Console import wrap +from bongo.configuration.cli import main_admin, main_setup +from bongo.configuration.spamassassin_update import main as sa_update_main from bongo.external.simpletal import simpleTAL, simpleTALES from bongo.external.simpletal.simpleElementTree import parseFile from bongo.storetool import BackupCommands, CalendarCommands, MailCommands +assert callable(main_admin) +assert callable(main_setup) +assert callable(sa_update_main) assert isinstance(wrap("Grüße 世界", width=8), str) assert "Müller" in table.format_table(["Name"], [["Müller"]]) @@ -58,6 +63,7 @@ bongo-admin --help >"${temporary}/bongo-admin.help" bongo-storetool --help >"${temporary}/bongo-storetool.help" bongo-queuetool --help >"${temporary}/bongo-queuetool.help" bongo-web --help >"${temporary}/bongo-web.help" +bongodirector --help >"${temporary}/bongodirector.help" /usr/libexec/bongo/bongo-sa-update --help \ >"${temporary}/bongo-sa-update.help" @@ -71,4 +77,4 @@ set -e test "${status}" -eq 1 grep -q '"ok":false' "${temporary}/bongo-acme.json" -echo "PYTHON-3 PASS compileall=installed imports=storetool,template,xml cli=6" +echo "PYTHON-3 PASS compileall=installed imports=config,storetool,template,xml cli=7" diff --git a/src/agents/director/bongodirector.py b/src/agents/director/bongodirector.py index e87a4b3..415db54 100755 --- a/src/agents/director/bongodirector.py +++ b/src/agents/director/bongodirector.py @@ -1,31 +1,74 @@ #!/usr/bin/env python3 -import logging, os, pwd, sys +# /**************************************************************************** +# * +# * Copyright (c) 2001 Novell, Inc. All Rights Reserved. +# * +# * This program is free software; you can redistribute it and/or +# * modify it under the terms of version 2 of the GNU General Public License +# * as published by the Free Software Foundation. +# * +# * This program is distributed in the hope that it will be useful, +# * but WITHOUT ANY WARRANTY; without even the implied warranty of +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# * GNU General Public License for more details. +# * +# * You should have received a copy of the GNU General Public License +# * along with this program; if not, contact Novell, Inc. +# * +# * To contact Novell about this file by physical or electronic mail, you +# * may find current contact information at www.novell.com. +# * +# ****************************************************************************/ + +"""Bongo's event director agent entry point.""" + +from __future__ import annotations + +import argparse +import logging +import sys sys.path.insert(0, "${PYTHON_SITEPACKAGES_PATH}") sys.path.insert(0, "${PYTHON_SITELIB_PATH}") -from bongo.Agent import Agent - -class DirectorAgent(Agent): - log = logging.getLogger("Bongo.Director") - - def __init__(self, name="bongo-director"): - Agent.__init__(self, name) - pass - - def callback(self, response): - # something needs to be directed... - pass +LOGGER = logging.getLogger("Bongo.Director") -director = DirectorAgent() -director.daemonize() +def _director_class(): + """Load the native Bongo bindings only when the daemon is started.""" + from bongo.Agent import Agent -try: - director.connect("admin", "_system") -except: - exit(-1) + class DirectorAgent(Agent): + log = LOGGER -director.waitForEvents() -exit(0) + def __init__(self, name="bongo-director"): + Agent.__init__(self, name) + + def callback(self, response): + # something needs to be directed... + pass + + return DirectorAgent + + +def main(arguments: list[str] | None = None) -> int: + parser = argparse.ArgumentParser( + description="Start the Bongo event director agent") + parser.parse_args(arguments) + + DirectorAgent = _director_class() + director = DirectorAgent() + director.daemonize() + try: + director.connect("admin", "_system") + except Exception: + LOGGER.exception( + "could not connect the director to the system event queue") + return 1 + director.waitForEvents() + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())