]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire-daemon: Move CLI into own script
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 14 Jun 2021 15:05:45 +0000 (15:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 14 Jun 2021 15:05:45 +0000 (15:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/pakfire/cli.py
src/pakfire/daemon.py
src/scripts/pakfire
src/scripts/pakfire-daemon [new file with mode: 0644]

index af39a071466bcbbd1c3813b672548b285c30fc08..b557f9733f8f29b8ed9c9bc492302b9a46db166a 100644 (file)
@@ -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
 
 # ------------------------------------------------------------------------------
index 06a2cfe2d303042fdf1fa7f43209a43331968e17..8cfd3fecd63864e9242e602ace0ebd3d82220653 100644 (file)
@@ -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(
index 9e6ee65768b870b52e49deaac97aaceae4598121..ce4e0d466c9b278c844fd586b44a0e92ead623d9 100644 (file)
@@ -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)
 
index dc1a51503e097c357e927d4552a44d5766b9e66f..9ba82cb68acfba1df82a775fbef9d8ca0a76cf6f 100755 (executable)
@@ -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 (file)
index 0000000..7a5904c
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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()