From: Michael Tremer Date: Mon, 14 Jun 2021 15:05:45 +0000 (+0000) Subject: pakfire-daemon: Move CLI into own script X-Git-Tag: 0.9.28~1252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa62aed6dc7b77cd64c322eaddcf7bfc9090716d;p=pakfire.git pakfire-daemon: Move CLI into own script Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index af39a0714..b557f9733 100644 --- a/Makefile.am +++ b/Makefile.am @@ -103,14 +103,14 @@ dist_doc_DATA = \ # ------------------------------------------------------------------------------ dist_bin_SCRIPTS = \ - src/scripts/pakfire + src/scripts/pakfire \ + src/scripts/pakfire-daemon install-exec-local: $(MKDIR_P) $(DESTDIR)/$(bindir) cd $(DESTDIR)/$(bindir) && \ $(LN_S) -vf pakfire pakfire-builder && \ $(LN_S) -vf pakfire pakfire-client && \ - $(LN_S) -vf pakfire pakfire-daemon && \ $(LN_S) -vf pakfire pakfire-key # ------------------------------------------------------------------------------ diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index 06a2cfe2d..8cfd3fecd 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -659,32 +659,6 @@ class CliClient(Cli): o.refresh() -class CliDaemon(Cli): - def parse_cli(self): - parser = argparse.ArgumentParser( - description = _("Pakfire daemon command line interface"), - ) - self._add_common_arguments(parser, offline_switch=False) - - # There is only one default action - parser.set_defaults(func=self.handle_run) - - return parser.parse_args() - - def handle_run(self, ns): - """ - Runs the pakfire daemon - """ - d = daemon.PakfireDaemon() - - try: - d.run() - - # We cannot just kill the daemon, it needs a smooth shutdown - except (SystemExit, KeyboardInterrupt): - d.shutdown() - - class CliKey(Cli): def parse_cli(self): parser = argparse.ArgumentParser( diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index 9e6ee6576..ce4e0d466 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -40,7 +40,7 @@ class BuildJob(dict): raise AttributeError(key) -class PakfireDaemon(object): +class Daemon(object): def __init__(self, config_file="daemon.conf"): self.config = config.Config(config_file) diff --git a/src/scripts/pakfire b/src/scripts/pakfire index dc1a51503..9ba82cb68 100755 --- a/src/scripts/pakfire +++ b/src/scripts/pakfire @@ -49,7 +49,6 @@ basename2cls = { "pakfire" : pakfire.cli.Cli, "pakfire-builder" : pakfire.cli.CliBuilder, "pakfire-client" : pakfire.cli.CliClient, - "pakfire-daemon" : pakfire.cli.CliDaemon, "pakfire-key" : pakfire.cli.CliKey, } diff --git a/src/scripts/pakfire-daemon b/src/scripts/pakfire-daemon new file mode 100644 index 000000000..7a5904c07 --- /dev/null +++ b/src/scripts/pakfire-daemon @@ -0,0 +1,62 @@ +#!/usr/bin/python3 +############################################################################## +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2021 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +# # +############################################################################### + +import argparse +import sys + +import pakfire.daemon +from pakfire.i18n import _ + +class Cli(object): + def parse_cli(self): + parser = argparse.ArgumentParser( + description = _("Pakfire daemon command line interface"), + ) + + parser.add_argument("--config", "-c", nargs="?", + default="@sysconfdir@/daemon.conf", help=_("Configuration file to load")) + + return parser.parse_args() + + def __call__(self): + """ + Runs the daemon + """ + args = self.parse_cli() + + # Initialize the daemon + d = pakfire.daemon.Daemon( + args.config, + ) + + # Run it + try: + r = d.run() + + except (SytemExit, KeyboardInterrupt): + d.shutdown() + + # Return the exit code + sys.exit(r or 0) + +if __name__ == "__main__": + c = Cli() + c()