From: Michael Tremer Date: Fri, 6 Oct 2017 16:48:05 +0000 (+0100) Subject: Add new command to run functions from command line X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43025dca501e161ce69c6b8ff4ed36c56153601e;p=pbs.git Add new command to run functions from command line Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index cd87e463..4040e930 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,6 +63,7 @@ dist_doc_DATA = \ # ------------------------------------------------------------------------------ dist_bin_SCRIPTS = \ + src/scripts/pakfire-build-service \ src/scripts/pakfire-hub \ src/scripts/pakfire-manager \ src/scripts/pakfire-web diff --git a/src/scripts/pakfire-build-service b/src/scripts/pakfire-build-service new file mode 100644 index 00000000..fa7e4511 --- /dev/null +++ b/src/scripts/pakfire-build-service @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import sys + +# Use tornado's logging options +import tornado.options +tornado.options.parse_command_line() + +import pakfire.buildservice + +class Cli(object): + def __init__(self, *args, **kwargs): + # Initialise backend + self.backend = pakfire.buildservice.Backend(*args, **kwargs) + + self._commands = {} + + def __call__(self, *args): + if not len(args) >= 2: + print >>sys.stderr, "Insufficient number of arguments" + return 2 + + args = list(args) + basename = args.pop(0) + command = args.pop(0) + + # Get called command + try: + command = self._commands[command] + except KeyError: + print >>sys.stderr, "Command not found: %s" % command + return 2 + + # Execute command + r = command(*args) + + # Exit with error code + sys.exit(r or 0) + +# main + +cli = Cli() +cli(*sys.argv)