]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
Add new command to run functions from command line
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2017 16:48:05 +0000 (17:48 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2017 16:48:05 +0000 (17:48 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/scripts/pakfire-build-service [new file with mode: 0644]

index cd87e46388e6dcc973c7db56969931d5a2a7498f..4040e9301dc50639bc98f29ad58f6fd30b8e70aa 100644 (file)
@@ -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 (file)
index 0000000..fa7e451
--- /dev/null
@@ -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)